Skip to content
Snippets Groups Projects
Commit bc441787 authored by Roang's avatar Roang
Browse files

Update release pipeline

* Create a tag for each commit
* Use tags instead of branches for production and latest
parent 0bffdf3a
Branches
Tags
No related merge requests found
...@@ -8,16 +8,19 @@ stages: ...@@ -8,16 +8,19 @@ stages:
workflow: workflow:
rules: rules:
# Allow manual pipeline runs
- if: $FORCE_PIPELINE_RUN == 'true' - if: $FORCE_PIPELINE_RUN == 'true'
# Tags with format "prod-yyyy-mm-dd_HH-MM" will be tagged as production and latest
- if: $CI_COMMIT_TAG - if: $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: ($CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_BRANCH == "production") - if: $CI_COMMIT_BRANCH == "develop"
# prevent duplicate pipeline runs for merge requests
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never when: never
- if: $CI_COMMIT_BRANCH - if: $CI_COMMIT_BRANCH
.default-rules: .default-rules:
rules: rules:
- if: ($CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_BRANCH == "production") - if: $CI_COMMIT_BRANCH == "develop"
- if: $CI_COMMIT_TAG - if: $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $FORCE_PIPELINE_RUN == 'true' - if: $FORCE_PIPELINE_RUN == 'true'
...@@ -375,42 +378,60 @@ test_nginx_static: ...@@ -375,42 +378,60 @@ test_nginx_static:
- crane delete $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID} - crane delete $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID}
- crane delete $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID} - crane delete $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID}
publish: publish-commit:
extends: extends:
- .publish-clean - .publish-clean
script: script:
- crane copy $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID} $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME - crane tag $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID} ${CI_COMMIT_SHORT_SHA}
- crane copy $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID} $CI_REGISTRY_IMAGE/nginx:$CI_COMMIT_REF_NAME - crane tag $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID} ${CI_COMMIT_SHORT_SHA}
rules: rules:
- if: '$CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_BRANCH == "production"' - if: '$CI_COMMIT_BRANCH == "develop" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_TAG'
- when: never - when: never
publish_latest: publish-mr:
extends:
- .publish-image
needs: needs:
- publish - publish-commit
script:
- crane tag $CI_REGISTRY_IMAGE/ci/hub:${CI_COMMIT_SHORT_SHA} mr-${CI_MERGE_REQUEST_ID}
- crane tag $CI_REGISTRY_IMAGE/ci/nginx:${CI_COMMIT_SHORT_SHA} mr-${CI_MERGE_REQUEST_ID}
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- when: never
publish-develop:
extends: extends:
- .publish-image - .publish-image
needs:
- publish-commit
script: script:
- crane tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME latest - crane copy $CI_REGISTRY_IMAGE/ci/hub:${CI_COMMIT_SHORT_SHA} $CI_REGISTRY_IMAGE:development
- crane tag $CI_REGISTRY_IMAGE/nginx:$CI_COMMIT_REF_NAME latest - crane copy $CI_REGISTRY_IMAGE/ci/nginx:${CI_COMMIT_SHORT_SHA} $CI_REGISTRY_IMAGE/nginx:development
rules: rules:
- if: '$CI_COMMIT_BRANCH == "production"' - if: $CI_COMMIT_BRANCH == 'develop'
- when: never - when: never
publish_merge_requests: # Publish to production and add latest tag
publish-production:
extends: extends:
- .publish-clean - .publish-image
needs:
- publish-commit
script: script:
- crane tag $CI_REGISTRY_IMAGE/ci/hub:ci-${CI_PIPELINE_ID} mr-$CI_MERGE_REQUEST_ID - crane copy $CI_REGISTRY_IMAGE/ci/hub:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:production
- crane tag $CI_REGISTRY_IMAGE/ci/nginx:ci-${CI_PIPELINE_ID} mr-$CI_MERGE_REQUEST_ID - crane tag $CI_REGISTRY_IMAGE:production latest
- crane copy $CI_REGISTRY_IMAGE/ci/nginx:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE/nginx:production
- crane tag $CI_REGISTRY_IMAGE/nginx:production latest
rules: rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' - if: '$CI_COMMIT_TAG =~ /^prod-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$/'
- when: never
deploy_develop: deploy_develop:
stage: deploy stage: deploy
allow_failure: true allow_failure: true
needs: needs:
- publish - publish-develop
image: python:3.11-bookworm image: python:3.11-bookworm
script: script:
- 'curl -X POST "$DEPLOYMENT_SERVICEWEBHOOK_URL_DEVELOP"' - 'curl -X POST "$DEPLOYMENT_SERVICEWEBHOOK_URL_DEVELOP"'
...@@ -434,7 +455,7 @@ deploy_production: ...@@ -434,7 +455,7 @@ deploy_production:
stage: deploy stage: deploy
allow_failure: true allow_failure: true
needs: needs:
- publish - publish-production
image: python:3.11-bookworm image: python:3.11-bookworm
script: script:
- 'curl -X POST "$DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION"' - 'curl -X POST "$DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION"'
...@@ -447,8 +468,8 @@ deploy_production: ...@@ -447,8 +468,8 @@ deploy_production:
- if: '$DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION == null || $DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION == ""' - if: '$DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION == null || $DEPLOYMENT_SERVICEWEBHOOK_URL_PRODUCTION == ""'
when: never when: never
# only attempt to deploy on correct branch # only attempt to deploy on correct tag
- if: '$CI_COMMIT_BRANCH == "production"' - if: '$CI_COMMIT_TAG =~ /^prod-\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$/'
when: on_success when: on_success
# otherwise, skip this # otherwise, skip this
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment