forked from alpine-docker/terragrunt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·47 lines (35 loc) · 1.17 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
#!/usr/bin/env bash
# Prerequisite
# Make sure you set secret enviroment variables in Travis CI
# DOCKER_USERNAME
# DOCKER_PASSWORD
# API_TOKEN
set -ex
image="alpine/terragrunt"
repo="hashicorp/terraform"
if [[ ${CI} == 'true' ]]; then
CURL="curl -sL -H \"Authorization: token ${API_TOKEN}\""
else
CURL="curl -sL"
fi
latest=$(${CURL} https://api.github.com/repos/${repo}/releases/latest |jq -r .tag_name|sed 's/v//')
terragrunt=$(${CURL} https://api.github.com/repos/gruntwork-io/terragrunt/releases/latest |jq -r .tag_name)
sum=0
echo "Lastest release is: ${latest}"
tags=`curl -s https://hub.docker.com/v2/repositories/${image}/tags/ |jq -r .results[].name`
for tag in ${tags}
do
if [ ${tag} == ${latest} ];then
sum=$((sum+1))
fi
done
if [[ ( $sum -ne 1 ) || ( ${REBUILD} == "true" ) ]];then
sed "s/VERSION/${latest}/" Dockerfile.template > Dockerfile
docker build --build-arg TERRAGRUNT=${terragrunt} --no-cache -t ${image}:${latest} .
docker tag ${image}:${latest} ${image}:latest
if [[ "$TRAVIS_BRANCH" == "master" ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker push ${image}:${latest}
docker push ${image}:latest
fi
fi