[NOD-555] Remove build scripts. (#581)

This commit is contained in:
stasatdaglabs 2020-01-13 13:37:21 +02:00 committed by Svarog
parent 3a15aa4bae
commit a177ea4f15
4 changed files with 0 additions and 242 deletions

10
Jenkinsfile vendored
View File

@ -1,10 +0,0 @@
node {
stage 'Checkout'
checkout scm
stage 'Version'
sh './deploy.sh version'
stage 'Build'
sh "./deploy.sh build"
}

168
deploy.sh
View File

@ -1,168 +0,0 @@
#!/bin/sh
export ENVIRONMENT_NAME=${ENVIRONMENT_NAME:-"dev"}
export CF_STACK_NAME=${CF_STACK_NAME:-"${ENVIRONMENT_NAME}-ECS-KASPAD"}
export SERVICE_NAME=${SERVICE_NAME:-"kaspad"}
export IMAGE_TAG=${IMAGE_TAG:-"latest"}
# GIT_COMMIT is set by Jenkins
export COMMIT=${COMMIT:-$GIT_COMMIT}
export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-eu-central-1}
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output=text)
export ECR_SERVER=${ECR_SERVER:-"$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"}
CF_PARAM=TaskImage
IMAGE_NAME=${ECR_SERVER}/${SERVICE_NAME}
# Start atd
service atd start
# Sends a Discord notification with some details about the failure
# All variables in this function are set by Jenkins
notify_discord() {
if [ -z "${DISCORD_CLIENT_ID}" ] || [ -z "${DISCORD_API_TOKEN}" ]; then
return
fi
echo "./discord.sh \
'${DISCORD_CLIENT_ID}' \
'${DISCORD_API_TOKEN}' \
'${BUILD_URL}' \
'${ghprbActualCommitAuthor}' \
'${ghprbPullTitle}' \
'${ghprbPullLink}'" | at -m now + 1 minute
}
trap "exit 1" INT
fatal() {
echo "ERROR: $*" >&2
notify_discord
exit 1
}
measure_runtime() {
START=$(date +%s)
echo "--> $*" >&2
"$@"
rc=$?
echo "--> took $(($(date +%s) - START))s" >&2
return $rc
}
test_git_cli() {
git --version >/dev/null || fatal 'The "git" CLI tool is not available.'
}
test_aws_cli() {
aws --version >/dev/null || fatal 'The "aws" CLI tool is not available.'
aws sts get-caller-identity >/dev/null || fatal 'The "aws" CLI tool is not configured.'
}
test_docker_cli() {
docker --version >/dev/null || fatal 'The "docker" CLI tool is not available.'
}
test_docker_server() {
docker version -f 'Docker server version {{.Server.Version}}, build {{.Server.GitCommit}}' >/dev/null \
|| fatal 'The "docker" server is not available'
}
# fix $COMMIT if executed without Jenkins
if [ -z "$COMMIT" ]; then
test_git_cli
COMMIT=$(git rev-parse --short=7 HEAD)
export COMMIT
fi
version() {
test_git_cli
# place environment variables set by Jenkins into a metadata file
cat <<-EOF > version.txt
GIT_BRANCH=$BRANCH_NAME
GIT_COMMIT=$(git rev-parse --short=12 HEAD)
GIT_AUTHOR_EMAIL=$(git log -1 --pretty='format:%ae')
GIT_AUTHOR_NAME=$(git log -1 --pretty='format:%an')
GIT_AUTHOR_DATE=$(git log -1 --pretty='format:%aI')
EOF
}
login() {
test_aws_cli
eval "$(aws ecr get-login --no-include-email)"
}
build() {
login
test_docker_cli
version
measure_runtime docker build -t "${SERVICE_NAME}:${COMMIT}" . \
-f docker/Dockerfile \
|| fatal 'Failed to build the docker image'
}
create_ecr() {
echo "==> Checking for existance of ECR repository..."
measure_runtime aws ecr describe-repositories --query 'repositories[].repositoryName' \
| grep -E "\"$SERVICE_NAME\"" >/dev/null \
|| {
echo "==> ECR for $SERVICE_NAME does not exist. Creating ..."
measure_runtime aws ecr create-repository --repository-name "$SERVICE_NAME" \
|| fatal 'Failed to create ECR repository'
}
}
push() {
test_aws_cli
test_docker_cli
test_docker_server
build
measure_runtime docker tag "${SERVICE_NAME}:${COMMIT}" "${IMAGE_NAME}:${COMMIT}" || fatal 'Failed to tag docker image'
measure_runtime docker tag "${SERVICE_NAME}:${COMMIT}" "${IMAGE_NAME}:latest" || fatal 'Failed to tag docker image to :last'
create_ecr
login
measure_runtime docker push "${IMAGE_NAME}:${COMMIT}" || fatal 'Failed to push docker image to ECR'
measure_runtime docker push "${IMAGE_NAME}:latest" || fatal 'Failed to push docker image :latest to ECR'
}
deploy() {
measure_runtime aws cloudformation \
update-stack \
--stack-name "$CF_STACK_NAME" \
--capabilities CAPABILITY_NAMED_IAM \
--use-previous-template \
--parameters "ParameterKey=EnvironmentName,UsePreviousValue=true \
ParameterKey=$CF_PARAM,ParameterValue=${IMAGE_NAME}:$COMMIT" \
|| fatal "Failed to update CloudFormation stack $STACK_NAME."
}
usage() {
echo "Usage: $0 <build|login|push|deploy>"
echo " version - create a version.txt file with some meta data"
echo " build - create docker image named $SERVICE_NAME with tag \$COMMIT"
echo " login - configure docker push credentials to use AWS ECR"
echo " push - tag image as :latest and push both :\$COMMIT and :latest to ECR"
echo " push_all - push for all AWS regions"
echo " deploy - update CloudFormation stack '$CF_STACK_NAME' with ECR image '${SERVICE_NAME}:${COMMIT}'"
}
push_all() {
for AWS_DEFAULT_REGION in 'us-east-1' 'us-east-2'; do
export AWS_DEFAULT_REGION
ECR_SERVER="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"
export ECR_SERVER
IMAGE_NAME=${ECR_SERVER}/${SERVICE_NAME}
export IMAGE_NAME
push
done
}
case $1 in
version) version ;;
build) build ;;
login) login ;;
push) push ;;
push_all) push_all ;;
deploy) deploy ;;
*) usage ;;
esac

View File

@ -1,26 +0,0 @@
#!/bin/sh
# This file is part of Continuous Integration. When ran by
# the CI agent, it sends a some details about the build failure
# to a Discord channel.
CLIENT_ID="$1"
API_TOKEN="$2"
BUILD_URL="$3"
PR_AUTHOR="$4"
PR_TITLE="$5"
PR_LINK="$6"
# Build the failure message
MESSAGE="*${PR_AUTHOR}*:
Build *FAILED* for pull request '${PR_TITLE}'
[Github](${PR_LINK}) [Jenkins](${BUILD_URL}console)"
# Retrieve the build log
LOG=$(curl ${BUILD_URL}consoleText)
# Send the build log
printf "$LOG" | curl \
"https://discordapp.com/api/webhooks/${CLIENT_ID}/${API_TOKEN}" \
-F content="${MESSAGE}" \
-F document="@-;filename=build.log"

View File

@ -1,38 +0,0 @@
#!/bin/bash
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. golint (https://github.com/golang/lint)
# 3. go vet (http://golang.org/cmd/vet)
# 4. gosimple (https://github.com/dominikh/go-simple)
# 5. unconvert (https://github.com/mdempsky/unconvert)
#
# gometalinter (github.com/alecthomas/gometalinter) is used to run each static
# checker.
set -ex
# Make sure glide is installed and $GOPATH/bin is in your path.
# $ go get -u github.com/Masterminds/glide
# $ glide install
if [ ! -x "$(type -p glide)" ]; then
exit 1
fi
# Make sure gometalinter is installed and $GOPATH/bin is in your path.
# $ go get -v github.com/alecthomas/gometalinter"
# $ gometalinter --install"
if [ ! -x "$(type -p gometalinter.v2)" ]; then
exit 1
fi
linter_targets=$(glide novendor)
# Automatic checks
test -z "$(gometalinter.v2 -j 4 --disable-all \
--enable=gofmt \
--enable=golint \
--enable=vet \
--enable=gosimple \
--enable=unconvert \
--deadline=10m $linter_targets 2>&1 | grep -v 'ALL_CAPS\|OP_' 2>&1 | tee /dev/stderr)"
go test -tags rpctest $linter_targets