|
| 1 | +.server-deploy-workflow: |
| 2 | + rules: |
| 3 | + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH |
| 4 | + changes: |
| 5 | + - services/server/**/* |
| 6 | + - .gitlab/ci/build_server.yml |
| 7 | + - .gitlab/ci/deploy_server.yml |
| 8 | + needs: |
| 9 | + - job: server-image |
| 10 | + artifacts: false |
| 11 | + |
| 12 | +variables: |
| 13 | + MANIFEST_GIT_REPO: https://gitlab.futo.org/devops/manifest-inventory.git |
| 14 | + MANIFEST_GIT_USER_EMAIL: $GITLAB_USER_EMAIL |
| 15 | + MANIFEST_GIT_USER_NAME: $GITLAB_USER_NAME |
| 16 | + |
| 17 | +################################################################# |
| 18 | +# Prepare the manifest changes as .patch files so we can review # |
| 19 | +################################################################# |
| 20 | + |
| 21 | +.server-deploy-prepare: |
| 22 | + extends: .server-deploy-workflow |
| 23 | + stage: deploy |
| 24 | + image: |
| 25 | + name: alpine/git:latest |
| 26 | + entrypoint: [''] |
| 27 | + before_script: |
| 28 | + - wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 |
| 29 | + - chmod +x /usr/local/bin/yq |
| 30 | + script: |
| 31 | + # Pull in the manifest repository |
| 32 | + - git clone "https://gitlab-ci-token:${MANIFEST_GIT_TOKEN}@${MANIFEST_GIT_REPO#https://}" manifest-inventory |
| 33 | + - cd manifest-inventory |
| 34 | + # Use 'yq' to change the yaml value to the current commit |
| 35 | + - yq -i ".image.version.$ENVIRONMENT = strenv(CI_COMMIT_SHA)" inventory/polycentric-2026/server.yml |
| 36 | + # Commit the change in the manifest repo |
| 37 | + - git config user.email "$MANIFEST_GIT_USER_EMAIL" |
| 38 | + - git config user.name "$MANIFEST_GIT_USER_NAME" |
| 39 | + - git add inventory/polycentric-2026/server.yml |
| 40 | + - 'git commit -m "polycentric-2026 $ENVIRONMENT: bump server to $CI_COMMIT_SHA"' |
| 41 | + # Export the commit as a patch artifact |
| 42 | + - git format-patch -1 -o "$CI_PROJECT_DIR/deploy-patches/" |
| 43 | + # Print the patch in the job log for review |
| 44 | + - cat "$CI_PROJECT_DIR/deploy-patches/"*.patch |
| 45 | + artifacts: |
| 46 | + paths: |
| 47 | + - deploy-patches/ |
| 48 | + expire_in: 1 week |
| 49 | + |
| 50 | +server-deploy-prepare-staging: |
| 51 | + extends: .server-deploy-prepare |
| 52 | + variables: |
| 53 | + ENVIRONMENT: staging |
| 54 | + |
| 55 | +server-deploy-prepare-production: |
| 56 | + extends: .server-deploy-prepare |
| 57 | + variables: |
| 58 | + ENVIRONMENT: polycentric |
| 59 | + |
| 60 | +############################### |
| 61 | +# Deploy the manifest changes # |
| 62 | +############################### |
| 63 | + |
| 64 | +.server-deploy-apply: |
| 65 | + extends: .server-deploy-workflow |
| 66 | + stage: deploy |
| 67 | + image: |
| 68 | + name: alpine/git:latest |
| 69 | + entrypoint: [''] |
| 70 | + when: manual |
| 71 | + script: |
| 72 | + # Pull in the manifest repository |
| 73 | + - git clone "https://gitlab-ci-token:${MANIFEST_GIT_TOKEN}@${MANIFEST_GIT_REPO#https://}" manifest-inventory |
| 74 | + - cd manifest-inventory |
| 75 | + # Show the patch we are about to apply |
| 76 | + - cat "$CI_PROJECT_DIR/deploy-patches/"*.patch |
| 77 | + # Apply the patch and push it to the manifest repo |
| 78 | + - git config user.email "$MANIFEST_GIT_USER_EMAIL" |
| 79 | + - git config user.name "$MANIFEST_GIT_USER_NAME" |
| 80 | + - git am "$CI_PROJECT_DIR/deploy-patches/"*.patch |
| 81 | + - git push origin HEAD |
| 82 | + |
| 83 | +server-deploy-apply-staging: |
| 84 | + extends: .server-deploy-apply |
| 85 | + needs: |
| 86 | + - job: server-deploy-prepare-staging |
| 87 | + artifacts: true |
| 88 | + |
| 89 | +server-deploy-apply-production: |
| 90 | + extends: .server-deploy-apply |
| 91 | + needs: |
| 92 | + - job: server-deploy-prepare-production |
| 93 | + artifacts: true |
0 commit comments