-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks
executable file
·61 lines (54 loc) · 1.71 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
#!/bin/bash
set -Eeuo pipefail
DOCKER_OPS_VERSION="2.0.0"
DOCKER_OPS_FILE="ops/docker-ops-${DOCKER_OPS_VERSION}"
AWS_REGION="eu-west-2"
mkdir -p ops
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="nhsdev/mhs-python-dojo"
image_registry="dockerhub"
image_dir="./image"
imagerc_filename="imagerc"
function docker_login {
if [ -z "$DOCKERHUB_USERNAME" ]; then
echo "DOCKERHUB_USERNAME must be your dockerhub username or an API token"
exit 5;
fi
if [ -z "$DOCKERHUB_PASSWORD" ]; then
echo "DOCKERHUB_PASSWORD must be your dockerhub password or an API token"
exit 5;
fi
echo "$DOCKERHUB_PASSWORD" | docker login --username $DOCKERHUB_USERNAME --password-stdin
}
function get_aws_ssm_secret {
secret_id=$1
json=$(dojo "aws ssm get-parameter --with-decryption --region $AWS_REGION --name $secret_id")
if [ $? != 0 ]; then
>&2 echo "Failed to obtain AWS secret from SSM: $secret_id"
exit 5
fi
echo $json | jq -r ".Parameter.Value"
}
command="$1"
set +u
case "${command}" in
build_local)
image_tag=$(git rev-parse HEAD)
docker_ops::docker_build "${image_dir}" "${imagerc_filename}" "${image_name}" "${image_tag}" "${image_registry}"
;;
build)
DOCKERHUB_USERNAME=$(get_aws_ssm_secret "/repo/prod/user-input/prm-team-dockerhub-username")
DOCKERHUB_PASSWORD=$(get_aws_ssm_secret "/repo/prod/user-input/prm-team-dockerhub-password")
docker_login
./tasks build_local
docker_ops::push "${image_dir}" "${imagerc_filename}"
;;
*)
echo "Invalid command: '${command}'"
exit 1
;;
esac
set +e