-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_docker.sh
executable file
·56 lines (50 loc) · 1.54 KB
/
deploy_docker.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
#!/bin/bash
# Deploys the application to Docker by building the docker image, and pushing it
# to Docker. Tags the image with the first 6 characters of the commit, "latest",
# and the Travis build number. Deploys with the suffix "-simulated" appended at
# the end of each tag name.
# Expects the following environment variables to be provided by travis:
# * TRAVIS_COMMIT
# * DOCKER_USERNAME
# * DOCKER_PASSWORD
# * TRAVIS_BUILD_NUMBER
echo "Deploying Docker image."
DOCKER_REPO="willjschmitt/joulia-controller"
COMMIT=${TRAVIS_COMMIT::6}
SUFFIX="-simulated"
DOCCKER_FILE="Dockerfile_Simulated"
echo "Deploying to ${DOCKER_REPO} at commit ${COMMIT} with suffix ${SUFFIX}"
echo "Logging into Docker."
docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}"
if [ $? -ne 0 ]
then
>&2 echo "Failed to log into Docker."
exit -1
fi
echo "Building Docker image."
docker build -f "${DOCCKER_FILE}" -t "${DOCKER_REPO}:${COMMIT}${SUFFIX}" .
if [ $? -ne 0 ]
then
>&2 echo "Failed to build Docker image."
exit -1
fi
echo "Tagging Docker image."
docker tag "${DOCKER_REPO}:${COMMIT}${SUFFIX}" "${DOCKER_REPO}:latest${SUFFIX}"
if [ #? -ne 0 ]
then
>&2 echo "Failed to tag Docker image with latest tag."
exit -1
fi
docker tag "${DOCKER_REPO}:${COMMIT}${SUFFIX}" "${DOCKER_REPO}:travis-${TRAVIS_BUILD_NUMBER}${SUFFIX}"
if [ #? -ne 0 ]
then
>&2 echo "Failed to tag Docker image with travis build number."
exit -1
fi
echo "Pushing Docker image."
docker push "${DOCKER_REPO}"
if [ #? -ne 0 ]
then
>&2 echo "Failed to push Docker image to Docker."
exit -1
fi