[damned-lies] feat: build image with configuration in CI
- From: Guillaume Bernard <gbernard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] feat: build image with configuration in CI
- Date: Tue, 10 May 2022 08:30:02 +0000 (UTC)
commit 5519076bcf749a75daed7f637c43071c9f4ca0c0
Author: Guillaume Bernard <associations guillaume-bernard fr>
Date: Mon May 9 15:06:22 2022 +0200
feat: build image with configuration in CI
.gitlab-ci.yml | 84 +++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 66 insertions(+), 18 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ae64b429..b4d8c977 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -26,6 +26,7 @@ variables:
# The runtime image hosted on Gitlab
RUNTIME_IMAGE_NAME: "${CI_REGISTRY_IMAGE}/damned-lies-runtime:${CI_COMMIT_REF_NAME}-latest"
+
# A job that runs on the runtime image (the one that is used the build the
# production container should inherit from this template.
.job-on-runtime-image:
@@ -33,6 +34,7 @@ variables:
before_script:
- pip install -r requirements.txt
+
# A job that builds an image using buildah should inherit from this template
.job-on-buildah:
image: quay.io/buildah/stable:latest
@@ -44,10 +46,32 @@ variables:
- buildah login --username "${CI_REGISTRY_USER}" --password "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}"
+.build_damned_lies_image:
+ extends: .job-on-buildah
+ variables:
+ # References for the build script
+ CURRENT_VCS_REF_NAME: "${CI_COMMIT_REF_NAME}"
+ BUILT_IMAGE_NAME: "damned-lies-production:${CI_COMMIT_REF_NAME}"
+ IMAGE_TAG: "${CI_REGISTRY_IMAGE}/damned-lies-production:${CI_COMMIT_REF_NAME}-latest"
+ KIND_OF_IMAGE: "production"
+ script:
+ - dnf install -y python3-jinja2-cli
+ - ./containers/production/render_configuration_templates.sh "${KIND_OF_IMAGE}"
+ - ./containers/production/build_buildah_production.sh "${KIND_OF_IMAGE}"
+ - buildah tag "${BUILT_IMAGE_NAME}-${KIND_OF_IMAGE}" "${IMAGE_TAG}"
+ - buildah push "${IMAGE_TAG}"
+ after_script:
+ - mv containers/production/${KIND_OF_IMAGE} configuration
+ artifacts:
+ paths:
+ - configuration
+ expire_in: 1 week
+ name: "${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}"
+
+
##############################################################################
################### Pre Build ###################
##############################################################################
-
build_damned_lies_runtime:
extends: .job-on-buildah
stage: pre_build
@@ -66,6 +90,8 @@ build_damned_lies_runtime:
when: always
- if: $CI_PIPELINE_SOURCE == "trigger"
when: always
+ # It is possible to trigger it manually through the web interface, but
+ # we allow_failure to prevent blocking the other jobs
- when: manual
allow_failure: true
@@ -84,12 +110,11 @@ pages:
artifacts:
paths:
- public
- expire_in: "5 days"
+ expire_in: 1 week
rules:
# Run the job on the default branch only.
- - if: $CI_COMMIT_BRANCH == "${CI_DEFAULT_BRANCH}"
+ - if: $CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH"
when: always
- allow_failure: false
- when: never
allow_failure: true
@@ -99,6 +124,7 @@ pages:
test:
stage: test
extends: .job-on-runtime-image
+ allow_failure: true
script:
- pip install coverage
- python manage.py compile-trans --settings=damnedlies.settings_tests
@@ -109,7 +135,7 @@ test:
coverage: /^TOTAL.*\s+(\d+\%)$/
artifacts:
name: "${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}"
- expire_in: "2 days"
+ expire_in: 1 week
expose_as: "Unit tests coverage"
paths:
- coverage.txt
@@ -131,7 +157,7 @@ static-analysis:prospector:
- prospector | tee prospector.txt
artifacts:
name: "${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}"
- expire_in: 2 days
+ expire_in: 1 week
expose_as: "Prospector Analysis"
paths:
- prospector.txt
@@ -148,7 +174,7 @@ static-analysis:flake8:
- flake8 | tee flake8.txt
artifacts:
name: "${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}"
- expire_in: 2 days
+ expire_in: 1 week
expose_as: "Flake8 Analysis"
paths:
- flake8.txt
@@ -168,7 +194,7 @@ code-string-changes:
- if [[ -s ${TRANSLATION_DIFF_PO_FILENAME} ]]; then exit 1; else exit 0; fi
artifacts:
name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
- expire_in: 2 days
+ expire_in: 1 week
expose_as: "Changed strings PO file"
paths:
- "${TRANSLATION_DIFF_PO_FILENAME}"
@@ -177,15 +203,37 @@ code-string-changes:
##############################################################################
################### Pre Deploy ###################
##############################################################################
-build_damned_lies_production:
- extends: .job-on-buildah
+build_damned_lies_production:staging:
+ extends: .build_damned_lies_image
stage: pre_deploy
variables:
- # References for the build script
- CURRENT_VCS_REF_NAME: "${CI_COMMIT_REF_NAME}"
- BUILT_IMAGE_NAME: "damned-lies-production:${CI_COMMIT_REF_NAME}"
- IMAGE_TAG: "${CI_REGISTRY_IMAGE}/damned-lies-production:${CI_COMMIT_REF_NAME}-latest"
- script:
- - ./containers/production/build_buildah_production.sh
- - buildah tag "${BUILT_IMAGE_NAME}" "${IMAGE_TAG}"
- - buildah push "${IMAGE_TAG}"
+ KIND_OF_DEPLOYMENT: "staging"
+ rules:
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+ when: always
+ - when: never
+
+
+##############################################################################
+################### Deploy ###################
+##############################################################################
+build_damned_lies_production:test:
+ extends: .build_damned_lies_image
+ stage: deploy
+ variables:
+ KIND_OF_DEPLOYMENT: "test"
+ rules:
+ - if: $CI_COMMIT_BRANCH == "develop"
+ when: always
+ - when: never
+
+
+build_damned_lies_production:production:
+ extends: .build_damned_lies_image
+ stage: deploy
+ variables:
+ KIND_OF_DEPLOYMENT: "production"
+ rules:
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+ when: manual
+ - when: never
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]