Skip to content

Commit

Permalink
Upgrade to Python 3.7, enhance ci pipeline and dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianKreuzberger committed Apr 5, 2020
1 parent fcced92 commit 285e153
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
59 changes: 41 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
sudo: false
language: python
dist: xenial # default is ubuntu 14.04, we need at least 16.04
python:
- 3.5

- 3.6
env:
global:
- IMAGE_NAME=$DOCKER_USERNAME/tempberry-backend
before_install:
# image name
- IMAGE_NAME=$DOCKER_USERNAME/tempberry-backend
# some other build related variables
- DATE="$(date +'%Y%m%d.%H%M')"
- GIT_SHA="$(git rev-parse --short HEAD)"
# get current git branch name
# get some git meta data like branch name, latest tag etc...
- GIT_LAST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "0.0.0")
- GIT_BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2)
- BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
- echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, BRANCH=$BRANCH"

- export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
- export BRANCH_SLUG=$(echo $BRANCH | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z)
- export GIT_SHA=$(git rev-parse --short HEAD)
# Build version string
- |
if [[ "$BRANCH" == "release-"* ]]; then
# extract version from branch name
VERSION=${BRANCH#"release-"}
else
if [[ "$BRANCH" == "$TRAVIS_TAG" ]]; then
# use tag as version
VERSION="${TRAVIS_TAG}"
else
# Development Branch - use last tag with branch name
VERSION="${GIT_LAST_TAG}-${BRANCH_SLUG}"
fi
fi
- export VERSION
- export DATE="$(date +'%Y%m%d')"
- export TIME="$(date +'%H%M')"
jobs:
include:
- stage: test
Expand All @@ -34,17 +48,26 @@ jobs:
# run tests
- python manage.py test

- stage: build and push
- stage: Docker Image Build and Push
if: NOT type = pull_request
install:
- echo "No install needed"
services:
- docker
script:
- docker build -f docker/python/Dockerfile -t $IMAGE_NAME:$GIT_SHA .
- docker build -f docker/python/Dockerfile -t $IMAGE_NAME:$GIT_SHA --build-arg version=${VERSION} . || travis_terminate 1
after_success:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker tag $IMAGE_NAME:$GIT_SHA $IMAGE_NAME:$BRANCH
- docker tag $IMAGE_NAME:$GIT_SHA $IMAGE_NAME:$BRANCH.$DATE
- docker tag $IMAGE_NAME:$GIT_SHA $IMAGE_NAME:$BRANCH.latest
- docker tag $IMAGE_NAME:$GIT_SHA $IMAGE_NAME:${VERSION}
- docker tag $IMAGE_NAME:$GIT_SHA $IMAGE_NAME:${VERSION}-${DATE}
- docker tag $IMAGE_NAME:$GIT_SHA $IMAGE_NAME:${VERSION}-${DATE}.${TIME}
- docker push $IMAGE_NAME
before_deploy:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
deploy:
provider: script
script: docker push "${IMAGE_NAME}"
on:
all_branches: true
after_deploy:
- echo "The following images have been built (and pushed to dockerhub):"
- docker images | grep "${IMAGE_NAME}"
5 changes: 4 additions & 1 deletion docker/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.5-slim
FROM python:3.6-slim

ENV PYTHONUNBUFFERED=1

Expand All @@ -8,6 +8,9 @@ COPY docker/python/run.sh /run.sh
RUN mkdir /app
WORKDIR /app

ARG version=develop
ENV VERSION="${version}"

# first copy requirements, readme and license file
COPY requirements /app/requirements
COPY requirements.txt README.md LICENSE /app/
Expand Down

0 comments on commit 285e153

Please sign in to comment.