diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..ba1bd4bf2f7bd62b63e6ad1ee22f894e53926c5c --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +image: docker:latest + +.runner_tags: &runner_tags + tags: + - dind + +services: + - docker:dind + +variables: + CONTAINER_TEST_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME" + CONTAINER_RELEASE_IMAGE: "$CI_REGISTRY_IMAGE:latest" + CONTAINER_TAG_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" + +stages: + - build + - test + - release + +before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + +build: + <<: *runner_tags + stage: build + script: + - docker pull "$CONTAINER_TEST_IMAGE" + - docker build --pull --cache-from "$CONTAINER_TEST_IMAGE" -t "$CONTAINER_TEST_IMAGE" . + - docker push "$CONTAINER_TEST_IMAGE" + +test: + <<: *runner_tags + stage: test + before_script: + - apk add --update py-pip + - pip install docker-compose + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + - docker pull "$CONTAINER_TEST_IMAGE" + - docker-compose -f docker-compose.yml up -d postgres redis + - sleep 5 + - docker-compose -f docker-compose.yml run --rm web + after_script: + - docker rm -f csentry_postgres + - docker rm -f csentry_redis + +release-image: + <<: *runner_tags + stage: release + script: + - docker pull "$CONTAINER_TEST_IMAGE" + - docker tag "$CONTAINER_TEST_IMAGE" "$CONTAINER_RELEASE_IMAGE" + - docker tag "$CONTAINER_TEST_IMAGE" "$CONTAINER_TAG_IMAGE" + - docker push "$CONTAINER_RELEASE_IMAGE" + - docker push "$CONTAINER_TAG_IMAGE" + only: + - tags diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index ec8832e05cd5b45dce8a91f36c2fb9febd43c3d3..0000000000000000000000000000000000000000 --- a/Jenkinsfile +++ /dev/null @@ -1,61 +0,0 @@ -pipeline { - agent { label 'docker-compose' } - - environment { - GIT_TAG = sh(returnStdout: true, script: 'git describe --exact-match || true').trim() - } - - stages { - stage('Refresh') { - steps { - slackSend (color: 'good', message: "STARTED: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") - sh 'make clean' - sh 'make refresh' - } - } - stage('Build') { - steps { - ansiColor('xterm') { - sh 'make build' - } - } - } - stage('Test') { - steps { - sh 'make db_image' - /* let the time to postgres to start */ - sh 'sleep 5' - sh 'make test_image' - } - } - stage('Push') { - when { - not { environment name: 'GIT_TAG', value: '' } - } - environment { - DOCKERHUB = credentials('dockerhub') - } - steps { - sh 'docker login -u $DOCKERHUB_USR -p $DOCKERHUB_PSW' - sh 'make tag' - sh 'make push' - sh 'docker logout' - } - } - } - - post { - always { - sh 'make clean' - /* clean up the workspace */ - deleteDir() - } - failure { - slackSend (color: 'danger', message: "FAILED: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") - } - success { - slackSend (color: 'good', message: "SUCCESSFUL: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") - } - } - -} diff --git a/Makefile b/Makefile index e005aacff0922fe57b983e48314871a74632b96f..dba31491fb6417d0db39bf0152253058c27b5801 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: help build tag push refresh release db initdb test db_image test_image -OWNER := europeanspallationsource +OWNER := registry.esss.lu.se/ics-infrastructure GIT_TAG := $(shell git describe --always) IMAGE := csentry diff --git a/docker-compose.yml b/docker-compose.yml index 9d9e587900a47cbea6985fb5ae6f9af43f279bbe..df27b226ae1bea60a135d453ed16f343a8593075 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: web: - image: europeanspallationsource/csentry:latest + image: registry.esss.lu.se/ics-infrastructure/csentry:master container_name: csentry_web command: pytest --cov=app -v depends_on: