mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-19 21:36:43 +00:00

* [DEV-134] Implement Continuous Integration Squashed commit: [5e41d830] Dev 223 fix txindex (#100) * [DEV-201] In handleGetBlockDAGInfo calculate difficulty by the tip with the lowest bits * [DEV-202] Move VirtualBlock.GetUTXOEntry to BlockDAG * [DEV-203] Move VirtualBlock.SelectedTip() to BlockDAG * [DEV-203] Move VirtualBlock.SelectedTip() to BlockDAG * [DEV-204] Unexport VirtualBlock() and add CalcMedianTime method for DAG * [DEV-204] add explanation about difficulty in CurrentBits() comment * [DEV-204] unexport VirtualBlock type * [DEV-223] make applyUTXOChanges return pastUTXOResults * [DEV-223] add bluestxdata for current block as well * [DEV-223] re-design tx index * [DEV-223] edit txindex comments * [DEV-223] rename BluesTxData -> AcceptedTxData, and return from applyUTXOChanges only transactions that got accepted * [DEV-223] add unit test for txindex * [DEV-223] fix comments and unite blueTransaction and AcceptedTxData to one type * [DEV-223] use bucket cursor for dbFetchFirstTxRegion * [DEV-223] use the same cursor instance for dbFetchFirstTxRegion * [DEV-223] write in dbFetchFirstTxRegion's comment that it returns the first block region * [DEV-223] rename type BlueBlockTransaction to TxWithBlockHash * [DEV-223] add named returned value for applyUTXOChanges [4c95e293] [DEV-134] Made golint ignore the vendor directory. [21736dbc] [DEV-134] Renamed ExampleBlockChain_ProcessBlock to ExampleBlockDAG_ProcessBlock to satisfy go vet. [beea6486] [DEV-134] Removed pushing the built docker to a remove repository. That's unnecessary at this stage. [bee911ed] [DEV-134] Made all precompilation checks run on everything instead of only the root dir. [585f92ae] [DEV-134] Added "github.com/pkg/errors" to dep. [5f02f570] [DEV-134] -vendor-only is written with only one hyphen. [3eee7f95] [DEV-134] go vet instead of go tool vet. [0c2d4343] [DEV-134] Split all the pre-compile checks to separate lines to be able to tell which of them is failing. [780519c8] [DEV-134] Ran gofmt on everything. [8247146b] Dev 223 fix txindex (#100) * [DEV-201] In handleGetBlockDAGInfo calculate difficulty by the tip with the lowest bits * [DEV-202] Move VirtualBlock.GetUTXOEntry to BlockDAG * [DEV-203] Move VirtualBlock.SelectedTip() to BlockDAG * [DEV-203] Move VirtualBlock.SelectedTip() to BlockDAG * [DEV-204] Unexport VirtualBlock() and add CalcMedianTime method for DAG * [DEV-204] add explanation about difficulty in CurrentBits() comment * [DEV-204] unexport VirtualBlock type * [DEV-223] make applyUTXOChanges return pastUTXOResults * [DEV-223] add bluestxdata for current block as well * [DEV-223] re-design tx index * [DEV-223] edit txindex comments * [DEV-223] rename BluesTxData -> AcceptedTxData, and return from applyUTXOChanges only transactions that got accepted * [DEV-223] add unit test for txindex * [DEV-223] fix comments and unite blueTransaction and AcceptedTxData to one type * [DEV-223] use bucket cursor for dbFetchFirstTxRegion * [DEV-223] use the same cursor instance for dbFetchFirstTxRegion * [DEV-223] write in dbFetchFirstTxRegion's comment that it returns the first block region * [DEV-223] rename type BlueBlockTransaction to TxWithBlockHash * [DEV-223] add named returned value for applyUTXOChanges [bff68aa3] [DEV-134] Gave executable permission to deploy.sh [638a99d9] [DEV-134] Added jenkinsfile and deploy script. * [DEV-134] Added a robust testing script. * [DEV-134] Fixed a bash-ism. * [DEV-134] Disabled testing with coverage for now. * [DEV-134] Disabled golint and removed removing debug symbols. * [DEV-134] Disabled aligncheck. * [DEV-134] Disabled structcheck and varcheck. * [DEV-134] Added "don't inline functions" to compiler flags for testing. * [DEV-134] Made build fail if gofmt prints out anything. * [DEV-134] Fixed misleading comment. * [DEV-134] Added comments to test.sh. * [DEV-134] Renamed tm to measure_runtime and removed do_ prefixes from functions. * [DEV-134] Fixed gofmt line in build script. * [DEV-134] Fixed gofmt some more. * [DEV-134] Fixed gofmt not actually failing due to logical or.
147 lines
4.4 KiB
Bash
Executable File
147 lines
4.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
export ENVIRONMENT_NAME=${ENVIRONMENT_NAME:-"dev"}
|
|
export CF_STACK_NAME=${CF_STACK_NAME:-"${ENVIRONMENT_NAME}-ECS-BTCD"}
|
|
export SERVICE_NAME=${SERVICE_NAME:-"btcd"}
|
|
export IMAGE_TAG=${IMAGE_TAG:-"latest"}
|
|
# GIT_COMMIT is set by Jenkins
|
|
export COMMIT=${COMMIT:-$GIT_COMMIT}
|
|
|
|
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-eu-central-1}
|
|
export AWS_DEFAULT_REGION
|
|
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output=text)
|
|
export AWS_ACCOUNT_ID
|
|
ECR_SERVER=${ECR_SERVER:-"$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"}
|
|
export ECR_SERVER
|
|
|
|
CF_PARAM=TaskImage
|
|
IMAGE_NAME=${ECR_SERVER}/${SERVICE_NAME}
|
|
|
|
trap "exit 1" INT
|
|
fatal() { echo "ERROR: $*" >&2; 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
|