-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
107 lines (100 loc) · 3.15 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
stages:
- test
- build
- deploy
variables:
VERSION: $CI_COMMIT_TAG
workflow:
rules:
# - if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "merge_request_event"'
# - if: '$CI_COMMIT_BRANCH == "feat/ci-environment"'
# variables:
# ENVIRONMENT: develop
# CHART_NAME: beep-api-develop
- if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+-staging$/'
variables:
ENVIRONMENT: staging
CHART_NAME: beep-api-staging
IMAGE_NAME: 'hugo08/beep-api-staging'
- if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/'
variables:
ENVIRONMENT: production
CHART_NAME: beep-api
IMAGE_NAME: 'milou666/beep-api'
- when: always
before_script:
- export VERSION=$(echo $CI_COMMIT_TAG | sed 's/-staging//')
lint:
stage: test
image: node:20.18
before_script:
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- pnpm config set store-dir .pnpm-store
script:
- pnpm install
- pnpm typecheck
- pnpm lint
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' || $CI_COMMIT_TAG
when: always
test:
stage: test
image: node:20.18
services:
- name: postgres
alias: postgres
variables:
POSTGRES_DB: backend-test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
- name: redis
alias: redis
variables:
REDIS_PASSWORD: password
before_script:
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- pnpm config set store-dir .pnpm-store
script:
- export $(cat .env.test | xargs)
- export REDIS_HOST=$REDIS_PORT_6379_TCP_ADDR
- export DB_HOST=$POSTGRES_PORT_5432_TCP_ADDR
- export HOST=$HOSTNAME
- pnpm install
- pnpm test
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' || $CI_COMMIT_TAG
when: always
build:
stage: build
rules:
- if: $CI_COMMIT_TAG
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: ['']
needs: ['lint']
script:
- echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"$USER_DOCKERHUB\",\"password\":\"$PASSWORD_DOCKERHUB\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $IMAGE_NAME:$VERSION
environment:
name: $ENVIRONMENT
deploy:
stage: deploy
needs: ['build']
rules:
- if: $CI_COMMIT_TAG
image:
name: alpine/helm:latest
entrypoint: ['']
script:
- wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O yq && chmod +x ./yq
- echo $VERSION
- DOMAIN=$(echo $API_URL_ENDPOINT | awk -F[/:] '{print $4}')
- 'echo "Extracted DOMAIN: $DOMAIN"'
- ./yq '. *= load("helm/api/values.'$ENVIRONMENT'.yaml")' helm/api/values.global.yaml > helm/api/values.yaml
- ./yq -i ".name=\"$CHART_NAME\"" helm/api/Chart.yaml
- helm package helm/api --version $VERSION --app-version $VERSION
- 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@$CHART_NAME-$VERSION.tgz" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/$ENVIRONMENT/charts"'
environment:
name: $ENVIRONMENT