Skip to content

Commit c572d0d

Browse files
committed
Auto deploy pipelines
1 parent 13e1fbf commit c572d0d

5 files changed

Lines changed: 192 additions & 0 deletions

File tree

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ include:
44
- local: '.gitlab/ci/build_rn_sdk.yml'
55
- local: '.gitlab/ci/build_server.yml'
66
- local: '.gitlab/ci/build_app.yml'
7+
- local: '.gitlab/ci/deploy_app.yml'
8+
- local: '.gitlab/ci/deploy_server.yml'
79
- local: '.gitlab/ci/deploy_pages.yml'
810
- local: '.gitlab/ci/scan_dependencies.yml'
911
stages:

.gitlab/ci/build_app.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
changes:
88
- apps/**/*
99
- .gitlab/ci/build_app.yml
10+
- .gitlab/ci/deploy_app.yml
1011
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
1112
when: never
1213
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
1314
changes:
1415
- apps/**/*
1516
- .gitlab/ci/build_app.yml
17+
- .gitlab/ci/deploy_app.yml
1618

1719
.app-build-base:
1820
extends: .app-workflow

.gitlab/ci/build_server.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
changes:
88
- services/server/**/*
99
- .gitlab/ci/build_server.yml
10+
- .gitlab/ci/deploy_server.yml
1011
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
1112
when: never
1213
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
1314
changes:
1415
- services/server/**/*
1516
- .gitlab/ci/build_server.yml
17+
- .gitlab/ci/deploy_server.yml
1618
variables:
1719
RUNNER_SCRIPT_TIMEOUT: 179m
1820
RUST_IMAGE: '${CI_REGISTRY}/${CI_PROJECT_PATH}:base'

.gitlab/ci/deploy_app.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.app-deploy-workflow:
2+
rules:
3+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
4+
changes:
5+
- apps/polycentric/**/*
6+
- .gitlab/ci/build_app.yml
7+
- .gitlab/ci/deploy_app.yml
8+
needs:
9+
- job: app-web-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+
.app-deploy-prepare:
22+
extends: .app-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/app.yml
40+
- 'git commit -m "polycentric-2026 $ENVIRONMENT: bump app 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+
app-deploy-prepare-staging:
51+
extends: .app-deploy-prepare
52+
variables:
53+
ENVIRONMENT: staging
54+
55+
app-deploy-prepare-production:
56+
extends: .app-deploy-prepare
57+
variables:
58+
ENVIRONMENT: polycentric
59+
60+
###############################
61+
# Deploy the manifest changes #
62+
###############################
63+
64+
.app-deploy-apply:
65+
extends: .app-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+
app-deploy-apply-staging:
84+
extends: .app-deploy-apply
85+
needs:
86+
- job: app-deploy-prepare-staging
87+
artifacts: true
88+
89+
app-deploy-apply-production:
90+
extends: .app-deploy-apply
91+
needs:
92+
- job: app-deploy-prepare-production
93+
artifacts: true

.gitlab/ci/deploy_server.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)