-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·63 lines (47 loc) · 1.21 KB
/
build.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
#!/bin/bash
set -e
ROOT_DIR="${PWD}"
BASE_IMAGE=aws-base
LOGIN=$(aws ecr get-login)
ECR=$(echo ${LOGIN} | sed 's|.*https://||')
REPO_BASE=${ECR}/${STACK_NAME}
${LOGIN}
calc_hash() {
find "$1" -type f -exec md5sum {} \; |
sort -k 2 |
md5sum |
cut -d ' ' -f1
}
tag_and_push() {
local name="$1"
local tag="$2"
local repo=${REPO_BASE}/${name}
docker tag ${name} ${repo}:${tag}
docker push ${repo}:${tag}
}
build_image() {
local name=$1
local build=$2
local repo_name=${STACK_NAME}/${name}
cd "${ROOT_DIR}/images/${name}"
local hash=$(calc_hash .)
aws ecr create-repository --repository-name ${repo_name} || true
aws ecr describe-images --repository-name ${repo_name} --image-ids imageTag="${hash}" || build=true
if [ -z "${build}" ]; then
false
else
docker build -t ${name} .
local version=$(docker inspect -f '{{ .Config.Labels.Version }}' ${name})
tag_and_push ${name} ${version}
tag_and_push ${name} ${hash}
fi
}
REBUILD=true
build_image ${BASE_IMAGE} || {
docker pull ${REPO_BASE}/${BASE_IMAGE}
docker tag ${REPO_BASE}/${BASE_IMAGE} ${BASE_IMAGE}
REBUILD=
}
for app in $(ls "${ROOT_DIR}/images/apps"); do
build_image apps/${app} ${REBUILD} || true
done