Skip to content

Use build args for versions #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
procps \
e2fsprogs \
xz-utils \
git \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

ENV VERSION 1.9.0-rc1
ARG VERSION
COPY get_docker.sh /get_docker.sh
RUN bash /get_docker.sh

Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ $ docker run --rm --privileged -it dockerswarm/dind:1.0.0 docker version
Client version: 1.0.0
```

## Tools
## Build

### update.sh

For every tag in `docker/docker` that is not present in this repository, create a corresponding tag with an updated
`Dockerfile`.

## build_and_push.sh

Build and push the given Docker images. If not arguments are given, it will build and push **all** images.
```
./build.sh VERSION
```
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

if [[ -z "$1" ]]; then
>&2 echo "Usage: $(basename $0) <version>"
exit 1
fi

VERSION=$1
docker build --build-arg=VERSION=$VERSION -t dockerswarm/dind:$VERSION .
35 changes: 0 additions & 35 deletions build_and_push.sh

This file was deleted.

44 changes: 44 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
#
# Check for new docker versions. Build and push an image for any
# version that doesn't already exist.
#

set -e

DOCKER_REPOSITORY=https://github.com/docker/docker-ce.git

MIN_DOCKER_VERSION_TAG=${MIN_DOCKER_VERSION_TAG-"v1.12.0"}

DOCKER_IMAGE=${DOCKER_IMAGE:-dockerswarm/dind}

# Sort versions correctly with rc releases. This will break if there
# are more than 9 bug fix releases in a minor version
function tags_after() {
local min_version=$1
sort -t"." -k "1,3.1Vr" -k "3.2,3.2" | \
sed "/^${min_version}\$/q" | \
sort -t"." -k "1,3.1V" -k "3.2,3.2r"
}

# Docker version tags starting from MIN_VERSION
tags=$(
git ls-remote --tags $DOCKER_REPOSITORY v\* |
awk -F'/' '{ print $3 }' |
grep -v "\^{}" |
tags_after $MIN_DOCKER_VERSION_TAG |
sed "s/^v//"
)

tags=$(python tags_compare.py "$tags")

for version in $tags
do
echo "Building version $version"
image="${DOCKER_IMAGE}:${version}"
./build.sh $version
./test.sh $image
docker push $image
done


32 changes: 26 additions & 6 deletions get_docker.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
#!/bin/bash
set -e

if [[ -z "$VERSION" ]]; then
>&2 echo "A VERSION is required."
exit 1
fi

function is_stable() {
local month=$(echo $1 | cut -d. -f2)
test $(expr $month % 3) -eq 0
}

function arch_suffix() {
# 17.06.0-ce-rc2 and rc3 need the arch suffix in the archive name
if [[ $1 == '17.06.0-ce-rc2' || $1 == '17.06.0-ce-rc3' ]]; then
echo "-x86_64"
fi
}

if [[ "$VERSION" == *"rc"* ]]; then
HOST=test.docker.com
STAGE=test
elif is_stable $VERSION; then
STAGE=stable
else
HOST=get.docker.com
STAGE=edge
fi

curl -L -f -o /usr/local/bin/docker \
https://$HOST/builds/Linux/x86_64/docker-${VERSION}

chmod +x /usr/local/bin/docker
curl -L -f \
https://download.docker.com/linux/static/${STAGE}/x86_64/docker-${VERSION}$(arch_suffix $VERSION).tgz \
| tar -xz
mv docker/* /usr/bin
rmdir docker
23 changes: 23 additions & 0 deletions tags_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
import sys
import urllib2

REPO_NAME = 'dockerswarm/dind'
URL = (
'https://hub.docker.com/v2/repositories'
'/{0}/tags/?page=1&page_size=250'.format(
REPO_NAME
)
)


def main(github_tags):
github_tags = github_tags.split()
res = urllib2.urlopen(URL)
hub_tags = json.loads(res.read())
hub_tags = [t['name'] for t in hub_tags['results']]
for gh_t in github_tags:
if gh_t not in hub_tags:
print(gh_t)

main(sys.argv[1])
38 changes: 38 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#
# Test the image starts correctly
#

set -e

if [[ -z "$1" ]]; then
>&2 echo "Usage: $(basename $0) <image>"
exit 1
fi

DOCKER_IMAGE=$1
BUILD_ID=dindtest-${BUILD_NUMBER-$USER}
TEST_HOST=tcp://0.0.0.0:2375


docker run -d --privileged \
--name $BUILD_ID \
$DOCKER_IMAGE \
dockerd -H $TEST_HOST $DOCKER_DAEMON_ARGS


function on_exit() {
unset DOCKER_HOST
if [[ "$?" != "0" ]]; then
docker logs "$BUILD_ID" 2>&1 | tail -n 100
fi
docker rm -vf "$BUILD_ID"
}
trap "on_exit" exit

ip=$(docker inspect -f '{{.NetworkSettings.IPAddress}}' $BUILD_ID)
export DOCKER_HOST=tcp://$ip:2375

timeout 60 ./wait_on_daemon

docker ps
37 changes: 0 additions & 37 deletions update.sh

This file was deleted.

21 changes: 0 additions & 21 deletions utils.sh

This file was deleted.

6 changes: 6 additions & 0 deletions wait_on_daemon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Wait for docker daemon to be available
echo "Waiting for docker daemon to become available at $DOCKER_HOST"
while [ -z "$(docker ps)" ]; do
sleep 0.3
done
16 changes: 0 additions & 16 deletions wipe.sh

This file was deleted.