forked from City-of-Helsinki/respa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
containerize.sh
executable file
·47 lines (36 loc) · 1.18 KB
/
containerize.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
#!/bin/bash
# Travis does not set secret variables, if the pull request comes
# from outside our own repository
if [ -z "$DOCKER_PASSWORD" ]; then
echo "Need Docker login credentials to proceed"
exit 0
fi
if [ "$TRAVIS_PYTHON_VERSION" != "3.6" ]; then
echo "Only deploy on production Python build"
exit 0
fi
export ORGANIZATION="helsinki"
export IMAGE="respa"
export REPO="$ORGANIZATION/$IMAGE"
export COMMIT=${TRAVIS_COMMIT::7}
export BRANCH=${TRAVIS_BRANCH//\//_}
echo "Building image"
docker build -t $IMAGE .
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
if [ "$TRAVIS_PULL_REQUEST" != false ]; then
echo "Tagging pull request" "$TRAVIS_PULL_REQUEST"
export BASE="$REPO:pr-$TRAVIS_PULL_REQUEST"
docker tag "$IMAGE" "$BASE"
docker tag "$BASE" "$REPO-$TRAVIS_BUILD_NUMBER"
docker push "$BASE"
docker push "$REPO:travis-$TRAVIS_BUILD_NUMBER"
exit 0
fi
echo "Tagging branch " "$TRAVIS_BRANCH"
docker tag "$IMAGE" "$REPO:$COMMIT"
docker tag "$REPO:$COMMIT" "$REPO:$BRANCH"
docker tag "$REPO:$COMMIT" "$REPO:travis-$TRAVIS_BUILD_NUMBER"
docker push "$REPO:$COMMIT"
docker push "$REPO:travis-$TRAVIS_BUILD_NUMBER"
docker push "$REPO:$BRANCH"
exit 0