Skip to content

Commit e5a87b5

Browse files
Let Travis push tags to Docker Hub
1 parent ef9c430 commit e5a87b5

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ before_install:
99

1010
before_script:
1111
- docker version
12+
- docker login --email=$DOCKER_EMAIL --username=$DOCKER_USERNAME --password=$DOCKER_PASSWORD
1213
# Ancient make binary at TravisCI doesn't support indentation with spaces
1314
- unexpand -t 4 Makefile > Makefile.tmp && mv Makefile.tmp Makefile
1415

1516
script:
1617
- make test
18+
19+
after_success:
20+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then docker push domcode/raffler; fi

build.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
echo "Using docker(`docker version -f "{{.Server.Version}} / {{.Client.Version}}"`) to build containers..."
3+
echo "Using docker(`docker version -f "{{.Server.Version}} / {{.Client.Version}}"`) to build container images..."
44

55
if [[ "$1" && "$1" != "--rebuild" ]]; then
66
dockerfiles=("$1/Dockerfile")
@@ -10,15 +10,15 @@ fi
1010

1111
for file in $dockerfiles; do
1212
dir=${file:0:-11}
13-
container=${dir/-/_}"_raffler"
14-
if [[ $1 == "--rebuild" || $(docker images | awk '{print $1}' | grep -c '^'"$container"'$') -eq 0 ]]; then
15-
echo "Building $container from $dir"
16-
docker build -q -t "$container" "$dir"
13+
tag="domcode/raffler:${dir/-/_}"
14+
if [[ $1 == "--rebuild" || $(docker images | awk '{print $1}' | grep -c '^'"$tag"'$') -eq 0 ]]; then
15+
echo "Building $tag from $dir"
16+
docker build -q -t "$tag" "$dir"
1717
if [[ $? != 0 ]]; then
1818
echo "Build failed!"
1919
exit 1
2020
fi
2121
else
22-
echo "Skipping $container - already exists"
22+
echo "Skipping $tag - already exists"
2323
fi
2424
done

raffle.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ NAMES_FILE=$(realpath "$WORKING_DIR/$1")
1616
cp "$NAMES_FILE" "$NAMES_DIR/current"
1717

1818
# Raffle a raffler ;-)
19-
declare RAFFLER_NAMES=($(docker images | awk '{print $1}' | grep '_raffler$'))
20-
RANDOM_RAFFLER=${RAFFLER_NAMES[$RANDOM % ${#RAFFLER_NAMES[@]} ]}
19+
declare RAFFLER_TAGS=($(docker images | awk '{print $1":"$2}' | grep domcode/raffler))
20+
21+
RANDOM_RAFFLER_TAG=${RAFFLER_TAGS[$RANDOM % ${#RAFFLER_TAGS[@]} ]}
2122

2223
# run raffler in container with names dir mounted
23-
CONTAINER_NAME="${RANDOM_RAFFLER}"
24-
echo -e "Raffling using \033[91m$RANDOM_RAFFLER\e[0m"
24+
echo -e "Raffling using \033[91m$RANDOM_RAFFLER_TAG\e[0m"
2525
echo -e "\033[92mAnd the winner is: "
26-
docker run -v $NAMES_DIR:/var/names "$CONTAINER_NAME"
26+
docker run -v $NAMES_DIR:/var/names "$RANDOM_RAFFLER_TAG"
2727
echo -e "\e[0m"

0 commit comments

Comments
 (0)