-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
72 lines (61 loc) · 1.93 KB
/
entrypoint.sh
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
#!/bin/sh
set -e
function main() {
sanitize "${INPUT_ACCESS_KEY_ID}" "access_key_id"
sanitize "${INPUT_SECRET_ACCESS_KEY}" "secret_access_key"
sanitize "${INPUT_REGION}" "region"
sanitize "${INPUT_ACCOUNT_ID}" "account_id"
sanitize "${INPUT_REPO}" "repo"
ACCOUNT_URL="$INPUT_ACCOUNT_ID.dkr.ecr.$INPUT_REGION.amazonaws.com"
aws_configure
login
docker_build $INPUT_TAGS $ACCOUNT_URL
create_ecr_repo $INPUT_CREATE_REPO
docker_push_to_ecr $INPUT_TAGS $ACCOUNT_URL
}
function sanitize() {
if [ -z "${1}" ]; then
>&2 echo "Unable to find the ${2}. Did you set with.${2}?"
exit 1
fi
}
function aws_configure() {
export AWS_ACCESS_KEY_ID=$INPUT_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$INPUT_SECRET_ACCESS_KEY
export AWS_DEFAULT_REGION=$INPUT_REGION
}
function login() {
echo "== START LOGIN"
LOGIN_PASSWORD=$(aws ecr get-login-password --region $AWS_DEFAULT_REGION)
echo "$LOGIN_PASSWORD" | docker login --username AWS --password-stdin $ACCOUNT_URL
echo "== FINISHED LOGIN"
}
function create_ecr_repo() {
if [ "${1}" = true ]; then
echo "== START CREATE REPO"
aws ecr describe-repositories --region $AWS_DEFAULT_REGION --repository-names $INPUT_REPO > /dev/null 2>&1 || \
aws ecr create-repository --region $AWS_DEFAULT_REGION --repository-name $INPUT_REPO
echo "== FINISHED CREATE REPO"
fi
}
function docker_build() {
echo "== START DOCKERIZE"
local TAG=$1
local docker_tag_args=""
local DOCKER_TAGS=$(echo "$TAG" | tr "," "\n")
for tag in $DOCKER_TAGS; do
docker_tag_args="$docker_tag_args -t $2/$INPUT_REPO:$tag"
done
docker build $INPUT_EXTRA_BUILD_ARGS -f $INPUT_DOCKERFILE $docker_tag_args $INPUT_PATH
echo "== FINISHED DOCKERIZE"
}
function docker_push_to_ecr() {
echo "== START PUSH TO ECR"
local TAG=$1
local DOCKER_TAGS=$(echo "$TAG" | tr "," "\n")
for tag in $DOCKER_TAGS; do
docker push $2/$INPUT_REPO:$tag
done
echo "== FINISHED PUSH TO ECR"
}
main