-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
143 lines (130 loc) · 3.01 KB
/
.gitlab-ci.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
default:
image: node:18
before_script:
# install pnpm
- wget -qO /bin/pnpm "https://github.com/pnpm/pnpm/releases/latest/download/pnpm-linuxstatic-x64" && chmod +x /bin/pnpm
- pnpm config set store-dir .pnpm-store
cache:
key:
files:
- pnpm-lock.yaml
paths:
- .pnpm-store
variables:
BUCKET_NAME: 'federated-web-app-bucket'
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
stages:
- lint
- build
- test
- e2e
- deploy
lint:
stage: lint
script:
- pnpm install
- pnpm lint
build:
needs:
- lint
stage: build
script:
- pnpm install
- pnpm build
artifacts:
paths:
- apps/*/dist
- apps/*/.wp_federation
- packages/*/dist
- packages/*/.wp_federation
test:
needs:
- build
stage: test
dependencies:
- build
script:
- pnpm install
- pnpm test:ci
test:infra:
stage: test
script:
- pnpm install
- cd infra
- pnpm infra:test:ci
e2e:
stage: e2e
needs:
- build
image: mcr.microsoft.com/playwright:v1.29.0-focal
# to boost execution speed if needed - apply sharding https://playwright.dev/docs/ci#sharding-1
script:
- pnpm install
- pnpm e2e
artifacts:
paths:
- e2e/playwright-report
- e2e/test-results
.deploy:
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
needs:
- build
- test
- e2e
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == 'main'
when: manual
- when: never
dependencies:
- build
before_script:
- aws --version
script:
# place main in root
- >
if [ "$SOURCE" == "apps/main" ]; then
DESTINATION_PATH=""
else
DESTINATION_PATH="${SOURCE}/dist"
fi
- aws s3 sync ${SOURCE}/dist s3://${BUCKET_NAME}/${DESTINATION_PATH}
# get distribution id by origin (bucket)
- CLOUDFRONT_ID=$( aws cloudfront list-distributions --query "DistributionList.Items[*].{id:Id,origin:Origins.Items[0].Id,domainName:Origins.Items[0].DomainName}[?domainName=='${BUCKET_NAME}.s3.${AWS_DEFAULT_REGION}.amazonaws.com'].id" --output text)
- aws cloudfront create-invalidation --distribution-id ${CLOUDFRONT_ID} --paths "/${SOURCE}/*"
deploy:infra:
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
stage: deploy
needs:
- test:infra
rules:
- if: $CI_COMMIT_BRANCH == 'main'
when: manual
- when: never
before_script:
- curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &&\
- apt-get install -y nodejs
# install pnpm (for Ubuntu, which is used in aws-base)
- npm install -g pnpm
- pnpm config set store-dir .pnpm-store
script:
- pnpm i
- cd infra
- pnpm infra:diff
- pnpm infra:deploy -- --parameters bucketName=${BUCKET_NAME}
deploy:main:
extends: .deploy
variables:
SOURCE: apps/main
deploy:app1:
extends: .deploy
variables:
SOURCE: apps/app1
deploy:app2:
extends: .deploy
variables:
SOURCE: apps/app2
deploy:shared:
extends: .deploy
variables:
SOURCE: packages/shared