Skip to content

Commit 116a10c

Browse files
authored
Publish Docker onbuild image and multiple version tags (#343)
* publish multiple docker tags and an onbuild image * pull from local image for onbuild
1 parent b385ccd commit 116a10c

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ Thumbs.db
7171
###########################
7272
*scratch.*
7373
*Scratch.*
74+
Dockerfile.onbuild.temp

Dockerfile.onbuild

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM cinchapi/concourse
2+
3+
# The directory that is included should have a directory called "plugins" which
4+
# contains all the plugins that will be installed when the image is built.
5+
ONBUILD ARG INCLUDE=.
6+
7+
# Copy the INCLUDE directory to the image
8+
ONBUILD COPY ${INCLUDE} /usr/src/include
9+
10+
# Ensure that the expected directories exist, even if empty
11+
ONBUILD RUN mkdir -p /usr/src/include/plugins
12+
ONBUILD RUN mkdir -p /usr/src/include/data
13+
14+
# Install plugins from the INCLUDE directory
15+
ONBUILD RUN concourse start && \
16+
concourse plugin install /usr/src/include/plugins --password admin \
17+
concourse stop

concourse-server/dockerize.sh

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,46 @@ HOME="`pwd -P`"
2121
HOME=`cd ${HOME}; pwd`
2222
cd ..
2323

24-
tag=$1
24+
version=$1
2525

26-
if [ -z "$tag" ]; then
27-
echo "Please provide a tag"
26+
if [ -z "$version" ] || ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
27+
echo "Please provide a valid version number"
2828
exit 1
2929
else
30-
# Build the docker image
31-
docker build -t cinchapi/concourse:$tag -f Dockerfile .
30+
# Determine all the docker tags to publish
31+
major=$(echo ${version} | cut -d . -f 1)
32+
minor=$(echo ${version} | cut -d . -f 2)
33+
patch=$(echo ${version} | cut -d . -f 3 | cut -d '-' -f 1)
34+
suffix=$(echo ${version} | cut -d '-' -f 2-)
35+
if [[ "$suffix" == "$version" ]]; then
36+
suffix=""
37+
tags="latest " # No suffix indicates we should push a latest tag
38+
else
39+
suffix="-"$suffix
40+
tags=""
41+
fi
3242

33-
# Push the docker image to docker hub
34-
docker login -e [email protected] -u $DOCKER_USER -p $DOCKER_PASS
35-
docker push cinchapi/concourse:$tag
43+
tags="$tags$major$suffix $major.$minor$suffix $major.$minor.$patch$suffix"
44+
45+
# Build the main docker image
46+
image=$(date +%Y%m%d%H%M%S)
47+
docker build -t $image -f Dockerfile .
3648

37-
# TODO: check if tag indicates a master build and push the latest tag
49+
# Build the -onbuild image using the image from the previous step as a base
50+
temp=Dockerfile.onbuild.temp
51+
sed "1s/.*/FROM $image/" Dockerfile.onbuild > $temp
52+
docker build -t $image-onbuild -f $temp --pull=false .
53+
rm $temp
54+
55+
# Push the image to docker hub with each of the tags
56+
docker login -e [email protected] -u $DOCKER_USER -p $DOCKER_PASS
57+
for tag in $tags; do
58+
for type in " " "-onbuild"; do
59+
name=cinchapi/concourse:$tag$type
60+
docker tag $image$type $name
61+
docker push $name
62+
echo "Pushed $name"
63+
done
64+
done
3865
exit 0
3966
fi

0 commit comments

Comments
 (0)