From 9a9d8e903313582e08f6738806c75dee7c9dc425 Mon Sep 17 00:00:00 2001 From: Blair Vanderlugt Date: Fri, 5 Feb 2021 15:53:15 +0000 Subject: [PATCH] Update apps/cic-eth/.gitlab-ci.yml, ci_templates/.cic-template.yml, apps/contract-migration/.gitlab-ci.yml files --- apps/cic-eth/.gitlab-ci.yml | 22 +++++--- apps/contract-migration/.gitlab-ci.yml | 21 +++++--- ci_templates/.cic-template.yml | 72 ++++++++++++++++++-------- 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/apps/cic-eth/.gitlab-ci.yml b/apps/cic-eth/.gitlab-ci.yml index 982bfa7..5559aff 100644 --- a/apps/cic-eth/.gitlab-ci.yml +++ b/apps/cic-eth/.gitlab-ci.yml @@ -1,12 +1,20 @@ -.contract-migration-changes-target: +variables: + APP_NAME: cic-eth + DOCKERFILE_PATH: $APP_NAME/docker/Dockerfile + +.this_changes_target: rules: - changes: - - $CONTEXT/cic-eth/* + - $CONTEXT/$APP_NAME/* -build-cic-eth: +build-mr-cic-eth: extends: - - .contract-migration-changes-target - - .py-build - variables: - DOCKERFILE_PATH: cic-eth/docker/Dockerfile + - .this_changes_target + - .py_build_merge_request + +build-push-cic-eth: + extends: + - .this_changes_target + - .py_build_push + diff --git a/apps/contract-migration/.gitlab-ci.yml b/apps/contract-migration/.gitlab-ci.yml index b31f8d1..4fc4653 100644 --- a/apps/contract-migration/.gitlab-ci.yml +++ b/apps/contract-migration/.gitlab-ci.yml @@ -1,11 +1,18 @@ -.contract-migration-changes-target: +variables: + APP_NAME: contract-migration + DOCKERFILE_PATH: $APP_NAME/docker/Dockerfile + +.this_changes_target: rules: - changes: - - $CONTEXT/contract-migration/* + - $CONTEXT/$APP_NAME/* -build-contract-migration: +build-mr-contract-migration: extends: - - .contract-migration-changes-target - - .py-build - variables: - DOCKERFILE_PATH: contract-migration/docker/Dockerfile + - .this_changes_target + - .py_build_merge_request + +build-push-contract-migration: + extends: + - .this_changes_target + - .py_build_push diff --git a/ci_templates/.cic-template.yml b/ci_templates/.cic-template.yml index 3b7d40a..e1c943b 100644 --- a/ci_templates/.cic-template.yml +++ b/ci_templates/.cic-template.yml @@ -1,25 +1,55 @@ -.py-build: - stage: build - image: docker:19.03.13 - variables: - # docker host - DOCKER_HOST: tcp://docker:2376 - # container, thanks to volume mount from config.toml - DOCKER_TLS_CERTDIR: "/certs" - # These are usually specified by the entrypoint, however the - # Kubernetes executor doesn't run entrypoints - # https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4125 - DOCKER_TLS_VERIFY: 1 - DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client" - CONTEXT: apps/ - services: - - docker:19.03.13-dind - before_script: - - docker info +image: docker:19.03.13 + +variables: + # docker host + DOCKER_HOST: tcp://docker:2376 + # container, thanks to volume mount from config.toml + DOCKER_TLS_CERTDIR: "/certs" + # These are usually specified by the entrypoint, however the + # Kubernetes executor doesn't run entrypoints + # https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4125 + DOCKER_TLS_VERIFY: 1 + DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client" + # We are building these from the apps dir to easily share the requirements file there. + # It would be nicer to build from the app dir context. TODO figure out a nice way to do this in local DOCKER_TLS_VERIFY + CONTEXT: apps/ + +services: + - docker:19.03.13-dind + +before_script: + - docker info + +.py_build_merge_request: + stage: build + before_script: - cd $CONTEXT - - pwd - - ls -la + variables: + CI_DEBUG_TRACE: "true" + IMAGE_TAG: $APP_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME-$CI_COMMIT_SHORT_SHA + script: + - docker build -t $IMAGE_TAG -f $DOCKERFILE_PATH . + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + when: always + +.py_build_push: + stage: build + before_script: + - cd $CONTEXT + - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" $CI_REGISTRY --password-stdin + variables: + CI_DEBUG_TRACE: "true" + IMAGE_TAG: $APP_NAME:$CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA + LATEST_TAG: $APP_NAME:$CI_COMMIT_BRANCH-latest script: - - docker build -t $CI_PROJECT_PATH_SLUG:$CI_COMMIT_SHORT_SHA -f $DOCKERFILE_PATH . + - docker build -t $IMAGE_TAG -f $DOCKERFILE_PATH . + - docker push $IMAGE_TAG + - docker tag $IMAGE_TAG $LATEST_TAG + - docker push $LATEST_TAG + rules: + - if: $CI_COMMIT_BRANCH == "master" + when: always +