forked from docker-archive/tutum-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·80 lines (73 loc) · 2.41 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·80 lines (73 loc) · 2.41 KB
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
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
set -e
if [ -S /var/run/docker.sock ]; then
echo "=> Detected unix socket at /var/run/docker.sock"
docker version > /dev/null 2>&1 || (echo " Failed to connect to docker daemon at /var/run/docker.sock" && exit 1)
else
echo "=> Starting docker"
wrapdocker > /dev/null 2>&1 &
sleep 2
echo "=> Checking docker daemon"
docker version > /dev/null 2>&1 || (echo " Failed to start docker (did you use --privileged when running this container?)" && exit 1)
fi
echo "=> Loading docker auth configuration"
if [ -f /.dockercfg ]; then
echo " Using existing configuration in /.dockercfg"
elif [ ! -z "$DOCKERCFG" ]; then
echo " Detected configuration in \$DOCKERCFG"
echo $DOCKERCFG > /.dockercfg
elif [ ! -z "$USERNAME" ] && [ ! -z "$PASSWORD" ]; then
REGISTRY=$(echo $IMAGE_NAME | tr "/" "\n" | head -n1 | grep "\." || true)
echo " Logging into registry using $USERNAME"
docker login -u $USERNAME -p $PASSWORD -e ${EMAIL-no-email@test.com} $REGISTRY
else
echo " WARNING: no \$USERNAME/\$PASSWORD or \$DOCKERCFG found - unable to load any credentials for pusing/pulling"
fi
echo "=> Detecting application"
if [ ! -d /app ]; then
if [ ! -z "$GIT_REPO" ]; then
echo " Cloning repo from $GIT_REPO in /app"
git clone $GIT_REPO /app
cd /app
git checkout $GIT_TAG
elif [ ! -z "$TGZ_URL" ]; then
echo " Downloading $TGZ_URL to /app"
mkdir -p /app
curl -sL $TGZ_URL | tar zx -C /app
cd /app
else
echo " ERROR: No application found in /app, and no \$GIT_REPO defined"
exit 1
fi
else
echo " Using existing app in /app"
cd /app
fi
cd .${DOCKERFILE_PATH-/}
if [ ! -f Dockerfile ]; then
echo " WARNING: no Dockerfile detected! Created one using tutum/buildstep"
echo "FROM tutum/buildstep" >> Dockerfile
fi
echo "=> Testing repo"
FIGTEST_FILENAME=${FIGTEST_FILENAME-fig-test.yml}
if [ -f "./${FIGTEST_FILENAME}" ]; then
fig -f ${FIGTEST_FILENAME} -p app up sut
RET=$(docker wait app_sut_1)
if [ "$RET" != "0" ]; then
echo " Tests FAILED: $RET"
exit 1
else
echo " Tests PASSED"
fi
else
echo " No tests found - skipping (have you created a ${FIGTEST_FILENAME} file?)"
fi
echo "=> Building and pushing image"
if [ ! -z "$IMAGE_NAME" ]; then
docker build --rm --force-rm -t $IMAGE_NAME .
echo " Pushing image $IMAGE_NAME"
docker push $IMAGE_NAME
docker rmi -f $(docker images -q --no-trunc -a) > /dev/null 2>&1
else
echo " WARNING: no \$IMAGE_NAME found - skipping build and push"
fi