-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
110 lines (103 loc) · 3.36 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
stages:
- test
- build
- deploy
test:
stage: test
services:
- mysql:latest
variables:
DB_HOST: mysql
DB_USERNAME: sail
MYSQL_DATABASE: testing
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: sail
MYSQL_ROOT_HOST: mysql
MYSQL_PASSWORD: password
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
image: docker-hub.sandstorm.de/docker-infrastructure/php-app/build:8.2-v2
cache:
key: cleema-app__composer
paths:
- .composer-cache
script:
- COMPOSER_CACHE_DIR=.composer-cache composer install --ignore-platform-req=ext-gd
# - vendor/bin/sail up -d --env=testing
- php artisan migrate --env=testing
# ⁄- php artisan db:seed --class=ShieldSeeder --env=testing
# - php artisan test
- vendor/bin/pest
package_app_staging:
stage: build
image: docker-hub.sandstorm.de/docker-infrastructure/php-app/build:8.2-v2
needs:
- test
cache:
key: cleema__composer
paths:
- .composer-cache
script:
- COMPOSER_CACHE_DIR=.composer-cache composer install --no-dev --ignore-platform-req=ext-gd
- npm install
- npm run build
# replaced $CI_REGISTRY_IMAGE with $CI_REGISTRY/$CI_PROJECT_NAME because of invalid path/groupName (contains '.' -> 'cleema.app')
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:staging || true
- docker build --cache-from $CI_REGISTRY_IMAGE:main -t $CI_REGISTRY_IMAGE:staging -f deployment/staging/Dockerfile .
- docker push $CI_REGISTRY_IMAGE:staging
package_app_production:
stage: build
only:
- tags
image: docker-hub.sandstorm.de/docker-infrastructure/php-app/build:8.2-v2
needs:
- test
cache:
key: cleema__composer
paths:
- .composer-cache
script:
- COMPOSER_CACHE_DIR=.composer-cache composer install --no-dev --ignore-platform-req=ext-gd
- npm install
- npm run build
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:production || true
- docker build --cache-from $CI_REGISTRY_IMAGE:production -t $CI_REGISTRY_IMAGE:production -f deployment/production/Dockerfile .
- docker push $CI_REGISTRY_IMAGE:production
deploy_staging:
stage: deploy
when: manual
image:
name: bitnami/kubectl:1.15.0
entrypoint: [ "" ]
needs:
- package_app_staging
#- e2e_test
environment:
name: staging
script:
- export KUBECONFIG=$KUBECONFIG_K3S2021
- kubectl get namespace cleema-app-staging
- kubectl apply -f deployment/staging/database.yaml
- kubectl apply -f deployment/staging/app.yaml
# enforce a redeploy by changing the release identifier
- 'kubectl -n cleema-app-staging patch --type merge OneContainerOnePort app -p "{\"spec\":{\"releaseIdentifier\": \"$CI_JOB_ID\"}}"'
deploy_production:
stage: deploy
only:
- tags
image:
name: bitnami/kubectl:1.15.0
entrypoint: [""]
needs:
- package_app_production
#- e2e_test
environment:
name: production
script:
- export KUBECONFIG=$KUBECONFIG_K3S2021
- kubectl get namespace cleema-app-production
- kubectl apply -f deployment/production/database.yaml
- kubectl apply -f deployment/production/app.yaml
# enforce a redeploy by changing the release identifier
- 'kubectl -n cleema-app-production patch --type merge OneContainerOnePort app -p "{\"spec\":{\"releaseIdentifier\": \"$CI_JOB_ID\"}}"'