-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci-deployment.yml
150 lines (147 loc) · 5.28 KB
/
.gitlab-ci-deployment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
deploy-chromatic:
stage: deploy
environment: $CI_COMMIT_REF_NAME
image: node:20.15.0-alpine3.20
extends:
- .trigger-rules
needs:
# needs the artifact: config and environment variables
- modify-env
# needs the artifact: node_modules to build the app
- install-node
# needs the artifact: storybook
- build-storybook
script:
# manually deploy the storybook build to chromatic for visual regression testing
- npx chromatic --project-token=${CHROMATIC_PROJECT_TOKEN} --exit-zero-on-changes --storybook-build-dir ./storybook
when: manual
# for manual jobs add allow_failure so the whole pipeline won't show up as "blocked"
allow_failure: true
publish-build:
stage: deploy
environment: $CI_COMMIT_REF_NAME
image: alpine:3.20
extends:
- .trigger-rules
variables:
GIT_STRATEGY: none
needs:
# needs the environmental variables for the version number
- set-vars
# make sure to wait for the tests to run correctly
- run-tests
# needs the artifact: the build of the frontend app and storybook buildenv
- combine-builds
before_script:
- apk add curl zip --no-cache
script:
- export PUBLISH_LOCATION="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/envidat-frontend/${BUILD_VERSION}.${CI_COMMIT_REF_NAME}/${BUILD_ZIP_NAME}"
- echo "Going to publish build ${BUILD_NAME} with zip name ${BUILD_ZIP_NAME}"
- echo "to location ${PUBLISH_LOCATION}"
- zip -r ${BUILD_ZIP_NAME} ./
# - ls -l
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
--user "${CI_DEPLOY_USER}:${CI_DEPLOY_PASSWORD}" \
--upload-file ${BUILD_ZIP_NAME} \
"${PUBLISH_LOCATION}"
deploy-to-s3-bucket:
stage: deploy
environment: $CI_COMMIT_REF_NAME
image: alpine:3.20
extends:
- .trigger-rules
needs:
# needs the environmental variables for the version number
- set-vars
# needs the published build for the app and it's storybook
- publish-build
variables:
GIT_STRATEGY: none
RCLONE_CONFIG_SWITCH_TYPE: 's3'
RCLONE_S3_PROVIDER: 'Other'
RCLONE_S3_ENV_AUTH: 'true'
before_script:
- apk add curl unzip --no-cache
- curl -O https://downloads.rclone.org/v1.59.0/rclone-v1.59.0-linux-amd64.zip
- unzip rclone-v1.59.0-linux-amd64.zip
- cp rclone-v1.59.0-linux-amd64/rclone /usr/bin/
- rm rclone-v1.59.0-linux-amd64.zip
- rm -rf rclone-v1.59.0-linux-amd64
- |
if [ "${CI_COMMIT_REF_NAME}" == "main" ]; then
BUCKET_NAME="frontend"
else
BUCKET_NAME="frontend-${CI_COMMIT_REF_NAME}"
fi
if [ "${CI_COMMIT_REF_NAME}" == "develop" ]; then
BUCKET_NAME="frontend-dev"
fi
echo "Target for rclone sync is the bucket: '${BUCKET_NAME}'"
script:
- export PUBLISH_LOCATION="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/envidat-frontend/${BUILD_VERSION}.${CI_COMMIT_REF_NAME}/${BUILD_ZIP_NAME}"
- echo "Going to pull build ${BUILD_NAME} with zip name ${BUILD_ZIP_NAME}"
- echo "from location ${PUBLISH_LOCATION}"
# - ls -l
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
--user "${CI_DEPLOY_USER}:${CI_DEPLOY_PASSWORD}" \
"${PUBLISH_LOCATION}" \
-o ${BUILD_ZIP_NAME}
# use -q for quiet to not list all the files
- unzip -q ${BUILD_ZIP_NAME}
- rm ${BUILD_ZIP_NAME}
- ls -l
- echo "going to rclone sync from ./ to switch:${BUCKET_NAME}"
- rclone sync ./ "switch:${BUCKET_NAME}" --verbose
manual-deploy-to-s3-bucket:
stage: manual-deploy
environment: $CI_COMMIT_REF_NAME
image: alpine:3.20
rules:
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: always
- when: manual
# for manual jobs add allow_failure so the whole pipeline won't show up as "blocked"
allow_failure: true
needs:
# needs the environmental variables for the version number
- set-vars
variables:
GIT_STRATEGY: none
RCLONE_CONFIG_SWITCH_TYPE: 's3'
RCLONE_S3_PROVIDER: 'Other'
RCLONE_S3_ENV_AUTH: 'true'
before_script:
- apk add curl unzip --no-cache
- curl -O https://downloads.rclone.org/v1.59.0/rclone-v1.59.0-linux-amd64.zip
- unzip rclone-v1.59.0-linux-amd64.zip
- cp rclone-v1.59.0-linux-amd64/rclone /usr/bin/
- rm rclone-v1.59.0-linux-amd64.zip
- rm -rf rclone-v1.59.0-linux-amd64
- |
if [ "${CI_COMMIT_REF_NAME}" == "main" ]; then
BUCKET_NAME="frontend"
else
BUCKET_NAME="frontend-${CI_COMMIT_REF_NAME}"
fi
if [ "${CI_COMMIT_REF_NAME}" == "develop" ]; then
BUCKET_NAME="frontend-dev"
fi
echo "Target for rclone sync is the bucket: '${BUCKET_NAME}'"
script:
- export PUBLISH_LOCATION="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/envidat-frontend/${BUILD_VERSION}.${CI_COMMIT_REF_NAME}/${BUILD_ZIP_NAME}"
- echo "Going to pull build ${BUILD_NAME} with zip name ${BUILD_ZIP_NAME}"
- echo "from location ${PUBLISH_LOCATION}"
# - ls -l
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
--user "${CI_DEPLOY_USER}:${CI_DEPLOY_PASSWORD}" \
"${PUBLISH_LOCATION}" \
-o ${BUILD_ZIP_NAME}
# use -q for quiet to not list all the files
- unzip -q ${BUILD_ZIP_NAME}
- rm ${BUILD_ZIP_NAME}
- ls -l
- echo "going to rclone sync from ./ to switch:${BUCKET_NAME}"
- rclone sync ./ "switch:${BUCKET_NAME}" --verbose