From a0032db7c058c592bd07ddcfc87e39f0aea2bc45 Mon Sep 17 00:00:00 2001 From: Stefan Hynek <stefan.hynek@uni-goettingen.de> Date: Thu, 4 Nov 2021 17:30:12 +0100 Subject: [PATCH] ci(gitlab): lint dockerfile; build container image and push to gitlab and harbor registry --- .gitlab-ci.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..1320472 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,50 @@ +--- +workflow: + rules: + - if: $CI_MERGE_REQUEST_IID + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_COMMIT_TAG + +stages: + - test + - build + + +lint dockerfile: + stage: test + image: hadolint/hadolint:latest-debian + before_script: + - mkdir -p reports + script: + - hadolint --format gitlab_codeclimate Dockerfile > reports/hadolint-$(md5sum Dockerfile | cut -d" " -f1).json + artifacts: + name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" + when: always + reports: + codequality: + - "reports/*" + paths: + - "reports/*" + rules: + - if: $CI_MERGE_REQUEST_IID + changes: + - Dockerfile + +build container image: + stage: build + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + script: + - mkdir -p /kaniko/.docker + - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64 | tr -d '\n')\"},\"$harbor_registry\":{\"auth\":\"$HARBOR_ROBOT_TOKEN64\"}}}" > /kaniko/.docker/config.json + - /kaniko/executor + --context $CI_PROJECT_DIR + --dockerfile $CI_PROJECT_DIR/Dockerfile + --build-arg build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ') + --build-arg vcs_ref=${CI_COMMIT_SHORT_SHA} + --build-arg version=${CI_COMMIT_SHORT_SHA} + --destination $CI_REGISTRY_IMAGE/repdav:$CI_COMMIT_SHORT_SHA + --destination $harbor_registry/$harbor_repo/repdav:$CI_COMMIT_SHORT_SHA + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH -- GitLab