From cb97a507a6a78ba6fc0428477a55f7b4963fd2b2 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Wed, 28 Mar 2018 19:55:29 +0200 Subject: [PATCH] Build docker container in CI For tags, we'll also push and tag that container. --- .gitlab-ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 2 +- release.sh | 24 +++++------------------- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cc312da5..edaad216 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,13 +13,19 @@ variables: PY36_IMAGE: thalia/python-thalia:3.6 PIP_CACHE_DIR: "${CI_PROJECT_DIR}/pip-cache" +stages: + - test + - deploy + pep8: + stage: test image: $PY35_IMAGE before_script: script: - tox -e flake8 .djangotest: &djangotest + stage: test services: - postgres:latest before_script: @@ -44,6 +50,7 @@ python36-django20: DJANGO_VERSION: django20 docs: + stage: test image: $PY35_IMAGE before_script: # install django deps @@ -60,6 +67,45 @@ docs: - ./generate-apidocs.sh - git diff --exit-code +build docker image: + stage: test + services: + - docker:dind + image: thalia/docker-compose + tags: + - docker + before_script: + - echo $GITLAB_REGISTRY_PASSWORD | docker login --username thaliawww --password-stdin registry.gitlab.com + script: + - docker-compose build --build-arg install_dev_requirements=0 web + - docker-compose run --rm web test + - docker tag $DOCKER_LATEST $DOCKER_TAG + - docker push $DOCKER_TAG + variables: + DOCKER_LATEST: registry.gitlab.com/thaliawww/concrexit:latest + DOCKER_TAG: registry.gitlab.com/thaliawww/concrexit:$CI_COMMIT_SHA + +tag docker image: + stage: deploy + services: + - docker:dind + image: docker:git + tags: + - docker + only: + - tags + dependencies: + - build docker image + before_script: + - echo $GITLAB_REGISTRY_PASSWORD | docker login --username thaliawww --password-stdin registry.gitlab.com + script: + - docker pull $DOCKER_TAG + - docker push $DOCKER_TAG_PRODUCTION + variables: + DOCKER_TAG: registry.gitlab.com/thaliawww/concrexit:$CI_COMMIT_SHA + DOCKER_TAG_PRODUCTION: registry.gitlab.com/thaliawww/concrexit:$CI_COMMIT_TAG + + cache: key: "$CI_JOB_NAME" paths: diff --git a/Dockerfile b/Dockerfile index 24c502c6..0143d146 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,4 +67,4 @@ COPY docs /usr/src/app/docs # Cache docs between builds if not mounting to FS VOLUME /concrexit/docs -RUN echo "Don't build releases without release.sh!" +RUN echo "Don't build releases yourself, let CI do it!" diff --git a/release.sh b/release.sh index bb51bd75..cb398d98 100755 --- a/release.sh +++ b/release.sh @@ -42,6 +42,9 @@ version_major=${version%.*} echo "Changing directory to root of repository" cd "${0%/*}" +echo "Making sure we're up-to-date" +git fetch --tags + echo "Changing to branch 'release/$version_major'" git checkout "release/$version_major" @@ -57,23 +60,6 @@ fi if yesno "Do you want to push the tag to the repository?"; then echo "Pushing tags:" git push --tags - echo "Don't forget to fill in the release description" -fi - -if ! yesno "Do you want to build a docker container?"; then - exit 1 -fi - -if [ -n "$(git status --porcelain)" ]; then - echo "Unclean working directory!" - git status - exit 1 -fi - -docker_tag="registry.gitlab.com/thaliawww/concrexit:$version" - -docker build --build-arg install_dev_requirements=0 --pull -t "$docker_tag" . - -if yesno "Do you want to push the container?"; then - docker push "$docker_tag" + echo "Don't forget to fill in the release description on the website:" + echo "https://gitlab.science.ru.nl/thalia/concrexit/tags/v$version/release/edit" fi -- GitLab