Skip to content

Commit

Permalink
#171 added docker build to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
bugy committed Feb 6, 2019
1 parent 5a3658e commit d2a37ca
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
37 changes: 27 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ addons:
env:
global:
- OWNER=${TRAVIS_REPO_SLUG%/*}
- secure: "GtWCiMPNz3MDDTvXqaVsgZBvlxYRZuTY6sUEhWTL37zJZHgRLlxTCTD27hHZp2P4B6G6KGV/0iEvMYxqzo6jMrzcEnt7TlGetteqI18dhV1dIQGH6uy8Y/PktkK2g2FuJeGV3FRK4+a21v6zzSuUaFa26k97mPapa4LS83XXj7rc13ll23HhhtObVF/a1n3U0Xwe4FkdoxbKlecJUnNujESxFk4xQl4N1tFv15fldDlFq0XWs26eEp3LU/n7wkMzbg9WEqPvDeaYlvir9VpvcYWpVvf8Uz+wpvW1jnE2R6bK1TDv5BNzQwbf2JtN284yZ8I1nwZtOJkc1RUr5wUFxCD0p8tc30sAlKemI385v2t1ccoBYMwH8LHFIUoSXoolHZBsnZeADqpo3a0d8hVFWv4AcxC27Q6SfMCltl0+ogAoQ7wVfkRT++044p415Ar4raEqIkqTm64FaRNMS0v2y5mS2634PMSGMRnK+NBrWz1yFKxsiuPKypIWygtrJ4pyiL2yPBZupnCluEgqva3q6AmMDlNuSUmcTEnCRGB01U2if6/oSEgISH1VK2lsRSxuoG5dFFuezwv90YENh/7pw0/hgge7EOse6OzDsU3uNRWcTuXF7eEBhjM1wBHWHlaAwV9vfHMZX4sHWP4R4CZhPjVEPRz6HPEg1tFCs2EvkuI="
- COMMIT=${TRAVIS_COMMIT::8}
# GITHUB_TOKEN
- secure: GtWCiMPNz3MDDTvXqaVsgZBvlxYRZuTY6sUEhWTL37zJZHgRLlxTCTD27hHZp2P4B6G6KGV/0iEvMYxqzo6jMrzcEnt7TlGetteqI18dhV1dIQGH6uy8Y/Pktk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54ijNYoKCqvKHqmamkrXQEdiImBlTg8NpmBNHJgHdL6PRqi3NxLzJzdqKtz5pkI4MVVLYFXsUApD0AWvEOPejLnfVEGber5cA/Hm3HhqB7M9ja2BFml+oYBLc3mnzjKd/FT3VwWMiijfTJVvr6feFrhSQGiRyBLmaoRNmUSjUsfR0=
# DOCKER_PASSWORD
- secure: S22ffhnZOs1yFdBwJO9+uzy9DB3e7ehLWbj47U1zavsMKMDyDw0lkOIy8PMERFh4roBoM5dG95RIVbfNbrPXQxnY5Og2w7RTTv3eeHGdYzh+34Dppfk8mhEAhn3NL98sOe6is/5sEDvZ2ykPFLvoJmyV15V7Wvtuy1Zx+0lyZ0R0tX6sVJUWDlClHspCuSIKK+iptL5yLu4TtvX9Wks/c3kH6GIXYIJIeC63D+RRhuetbtGKND/RtFkq5IDP9qMZNXUAT/Mb8hrsk9HntFgl79dG2ChvBpDE8/LqjYDBiFTiUAtJfBhC0pVB3WaEwGTU/hWe8WTjl29JIkGcoaeT7+wncJ72lEPJoO60YWSdtWfTlNlUiN27AcxGqk39MDhB5NAbuJpKvcFLMmWFY2uJefrR6XVEXBZ+9yAwzuZmj0GYFOQTuczAqncyj/3BuOEqfIkkQ5BLAS5BUuzSEbHOjwasqbTVcWM1H3cv2ZYATXQQN8KhcZ5c5lxy8eD0NXHKvBFlS3HOXOXn3P6PqGgFHzjL+yyHMvzIXBJY4jEr8FIH16dwbXDqb4gi4lrrCZHDeIhVKsmLSUJjhmiKeP7dWcfUOGMxzLRmqA8r58TXcN3OvBrqNN63nUSG+Wb6XxmzLwE4PrlBy0fTRymG8WXrdE/Z2lglBhc8J3A8ER9c46s=
before_install:
- sudo apt-get -y install python3-pip python3-setuptools
install:
Expand All @@ -31,19 +37,30 @@ before_script:
script:
- python3 tools/build.py
before_deploy:
- git config --local user.name 'bugy'
- git config --local user.email '[email protected]'
- git tag -f 'dev'
- git remote add gh https://${OWNER}:${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
- git push -f gh dev
- git remote remove gh
- if ! [ "$BEFORE_DEPLOY_RUN" ]; then
export BEFORE_DEPLOY_RUN=1;

git config --local user.name 'bugy'
git config --local user.email '[email protected]'
git tag -f 'dev'
git remote add gh https://${OWNER}:${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
git push -f gh dev
git remote remove gh

fi
deploy:
provider: releases
- provider: releases
name: dev
api_key: $GITHUB_TOKEN
api_key: "$GITHUB_TOKEN"
file: build/script-server.zip
prerelease: true
overwrite: true
skip_cleanup: true
on:
branch: master
branch: master
- provider: script
script: tools/deploy_docker.sh
on:
tags: false
all_branches: true
condition: $TRAVIS_BRANCH =~ ^stable|master$
8 changes: 8 additions & 0 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.6

COPY build/script-server /app
WORKDIR /app
RUN pip install -r requirements.txt

EXPOSE 5000
CMD [ "python3", "launcher.py" ]
26 changes: 26 additions & 0 deletions tools/deploy_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e

if [ -z "$DOCKER_USER" ] || [ -z "$DOCKER_PASSWORD" ] || [ -z "$TRAVIS_BRANCH" ] || [ -z "$COMMIT" ]; then
echo 'Some environment variables are not set'
exit -1
fi

IMAGE_NAME='bugy/script-server'

unzip -o build/script-server.zip -d build/script-server

docker build -f tools/Dockerfile -t "$IMAGE_NAME":"$COMMIT" .

docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"

if [ "$TRAVIS_BRANCH" == "stable" ]; then
docker tag "$IMAGE_NAME":"$COMMIT" "$IMAGE_NAME":latest
elif [ "$TRAVIS_BRANCH" == "master" ]; then
docker tag "$IMAGE_NAME":"$COMMIT" "$IMAGE_NAME":dev
else
docker tag "$IMAGE_NAME":"$COMMIT" "$IMAGE_NAME":"$TRAVIS_BRANCH"
fi

docker push "$IMAGE_NAME"

This comment has been minimized.

Copy link
@cicdteam

cicdteam Feb 7, 2019

Hi @bugy !

In fact here you push ONLY :latest tag. as docker push somename equivalent to docker push somename:latest

Also, why you avoid using github tags ? I thing it better then push images tagged with commit SHA1.

Let say you have such structure in docker hub:

  • bugy/script-server:1.13.0, bugy/script-server:latest - release 1.13.0 (and it's latest release, so image tagged as latest too)
  • bugy/script-server:1.12.0 - release 1.12.0
  • bugy/script-server:1.11.0 - release 1.11.0
  • bugy/script-server:dev - dev version (built from master branch on each commit)

This comment has been minimized.

Copy link
@bugy

bugy Feb 7, 2019

Author Owner

Hi @pureclouds, thanks for valuable comments. I'm really a beginner in docker, so your help is really helpful!

In fact here you push ONLY :latest tag. as docker push somename equivalent to docker push somename:latest

Hm, I'm not sure about this: I saw it in a couple of examples and also yesterday 2 tags were pushed on the commit: ae96fe8 and dev. Am I missing something?

Also, why you avoid using github tags ? I thing it better then push images tagged with commit SHA1.

That's a nice one, I didn't think about it - this is quite elegant way to get version. However there is a problem, that I don't run CI on tags (to avoid building the same commit twice). So either I need to change it or make versioning in other way. Will think about it

This comment has been minimized.

Copy link
@cicdteam

cicdteam Feb 7, 2019

Oh, i was a little bit wrong :) docker push pushes all tags for image if not tag specified. But anyway, tagging docker images with related github tags more preferable I think.

This comment has been minimized.

Copy link
@bugy

bugy Feb 7, 2019

Author Owner

Perfect, agreed, I'll have a look
May be I will go another way round and assign versions/git tags from CI itself, based on the last version. Need to check

This comment has been minimized.

Copy link
@cicdteam

cicdteam Feb 7, 2019

Regarding default Travis variables you can look if TRAVIS_TAG has value and use it for tagging docker images.

TRAVIS_TAG: If the current build is for a git tag, this variable is set to the tag’s name.

TRAVIS_BRANCH:

  • for push builds, or builds not triggered by a pull request, this is the name of the branch.
  • for builds triggered by a pull request this is the name of the branch targeted by the pull request.
  • for builds triggered by a tag, this is the same as the name of the tag (TRAVIS_TAG).

This comment has been minimized.

Copy link
@bugy

bugy Feb 7, 2019

Author Owner

Yep, thank you. The problem is, that I don't really want to trigger build on tags, since there are no code changes and not all commits are tagged anyway.

0 comments on commit d2a37ca

Please sign in to comment.