-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks
executable file
·84 lines (76 loc) · 2.66 KB
/
tasks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
set -Eeo pipefail
AWS_DEFAULT_REGION=eu-west-2
RELEASER_VERSION="2.1.3"
DOCKER_OPS_VERSION="2.0.1"
RELEASER_FILE="ops/releaser-${RELEASER_VERSION}"
DOCKER_OPS_FILE="ops/docker-ops-${DOCKER_OPS_VERSION}"
mkdir -p ops
if [[ ! -f $RELEASER_FILE ]];then
wget --quiet -O $RELEASER_FILE https://github.com/kudulab/releaser/releases/download/${RELEASER_VERSION}/releaser
fi
source $RELEASER_FILE
if [[ ! -f $DOCKER_OPS_FILE ]];then
wget --quiet -O $DOCKER_OPS_FILE https://github.com/kudulab/docker-ops/releases/download/${DOCKER_OPS_VERSION}/docker-ops
fi
source $DOCKER_OPS_FILE
image_name="gocd-agent"
image_registry="327778747031.dkr.ecr.eu-west-2.amazonaws.com"
image_dir="./image"
imagerc_filename="imagerc"
function docker_login {
eval $(dojo "aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION")
}
function get_aws_value {
secret_id=$1
json=$(aws ssm get-parameter --with-decryption --region $AWS_DEFAULT_REGION --name $secret_id)
if [ $? != 0 ]; then
>&2 echo "Failed to obtain SSM value: $secret_id"
exit 5
fi
echo $json | jq -r ".Parameter.Value"
}
command="$1"
set +u
case "${command}" in
set_version)
releaser::bump_changelog_version "$2" "$3"
;;
verify)
releaser::verify_release_ready
;;
build_local)
image_tag=$(git rev-parse HEAD)
docker_ops::docker_build "${image_dir}" "${imagerc_filename}" "${image_name}" "${image_tag}" "${image_registry}"
;;
build)
docker_login
./tasks build_local
docker_ops::push "${image_dir}" "${imagerc_filename}"
;;
release)
# GITHUB_CREDENTIALS should be in format of account-name:api-key
export GITHUB_CREDENTIALS=$(get_aws_value "/repo/prod/user-input/external/gocd-github-api-key")
OLD_URL=$(git remote get-url origin)
NEW_URL=$(echo $OLD_URL | sed "s|https://|https://$GITHUB_CREDENTIALS@|g")
git remote set-url origin $NEW_URL
./tasks verify
releaser::git_tag_from_changelog
exit $?
;;
_publish)
docker_ops::source_imagerc "${image_dir}" "${imagerc_filename}"
MANIFEST=$(aws ecr batch-get-image --region eu-west-2 --repository-name ${KUDU_DOCKER_IMAGE_SHORT_NAME} --image-ids imageTag=${KUDU_DOCKER_IMAGE_TAG} --query 'images[].imageManifest' --output text)
aws ecr put-image --region eu-west-2 --repository-name ${KUDU_DOCKER_IMAGE_SHORT_NAME} --image-tag "v${changelog_version}" --image-manifest "$MANIFEST"
;;
publish)
docker_login
export changelog_version=$(releaser::get_last_version_from_whole_changelog "${changelog_file}")
dojo "./tasks _publish"
;;
*)
echo "Invalid command: '${command}'"
exit 1
;;
esac
set +e