-
Notifications
You must be signed in to change notification settings - Fork 69
/
deploy-docker-image.sh
executable file
·69 lines (56 loc) · 1.59 KB
/
deploy-docker-image.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
#!/bin/bash -e
TAG=$1
RELEASE=$2
retry() {
"${@}" || "${@}" || exit 2
}
login() {
echo "Logging into Docker Hub"
retry docker login \
"--username=${DOCKER_USERNAME}" \
"--password=${DOCKER_PASSWORD}"
}
buildPush() {
IMAGE="${1}"
DOCKERFILE="${2:-Dockerfile}"
echo "Building docker image"
retry docker pull "${IMAGE}"
retry docker build -t "${IMAGE}" -t "${IMAGE}:${TAG}" -f "${DOCKERFILE}" --build-arg FROM_TAG="${TAG}" --cache-from "${IMAGE}" .
echo "Pushing image to ${IMAGE}:${TAG}"
retry docker push "${IMAGE}:${TAG}"
retry docker push "${IMAGE}"
}
logout() {
echo "Logging out""${@}"
retry docker logout
}
deploy() {
environment=${1}
image=${2}
username='inspire-bot'
token="${INSPIRE_BOT_TOKEN}"
curl \
-u "${username}:${token}" \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-d '{"event_type":"deploy", "client_payload":{ "project": "inspire", "application": "next", "namespace":"'${environment}'", "image":"'${image}'", "new_tag":"'${TAG}'"}}' \
https://api.github.com/repos/cern-sis/kubernetes/dispatches
echo "${TAG}"
}
main() {
login
buildPush "inspirehep/next"
buildPush "inspirehep/next-assets" Dockerfile
buildPush "inspirehep/next-scrapyd" Dockerfile.scrapyd
logout
if [ -z "${RELEASE}" ]; then
deploy "inspire-qa" "inspirehep/next"
deploy "inspire-qa" "inspirehep/next-assets"
deploy "inspire-qa" "inspirehep/next-scrapyd"
else
deploy "inspire-prod" "inspirehep/next"
deploy "inspire-prod" "inspirehep/next-assets"
deploy "inspire-prod" "inspirehep/next-scrapyd"
fi
}
main