-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
168 lines (158 loc) · 4.38 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
variables:
DS_EXCLUDED_ANALYZERS: gemnasium-python
IMAGE_NAME_BASE: "$CI_REGISTRY_IMAGE/base"
IMAGE_NAME_SERVER: "$CI_REGISTRY_IMAGE/server_app"
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
include:
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
- template: Jobs/Secret-Detection.gitlab-ci.yml
stages:
- lint
- build
- test
- deploy
# Lint
lint:black:
image: python:3.8
stage: lint
allow_failure: true
cache:
paths:
- .cache/pip
- venv/
before_script:
- cat /etc/os-release
- python3 -V
- python3 -m venv venv
- source venv/bin/activate
- python3 -m pip install --upgrade pip
- pip3 install black
script:
- black . --line-length 120 --check --verbose
lint:prettier:
image: node:18-bullseye
stage: lint
allow_failure: true
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- web_app/app/node_modules/
before_script:
- cat /etc/os-release
- cd web_app/app/
- npm ci
- npm list
- cd ../..
script:
- npx prettier --check .
# Model
model-unittest:
image: "$IMAGE_NAME_BASE"
stage: test
before_script:
# Configure shell for Anaconda (called in ~/.bashrc, but in CI the shell is not interactive)
- source /opt/conda/etc/profile.d/conda.sh
# Debug info
- cat /etc/os-release
- conda info
script:
# Activate environment
- conda activate WasteDetection
# Run unit tests
- python unittest_model.py
# Webapp
webapp-build:
image: node:18-bullseye
stage: build
script:
- cd web_app/app/
- npm ci
- npm run build
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- web_app/app/node_modules/
artifacts:
paths:
- web_app/app/dist/
expire_in: 1 week
webapp-deploy:
image: ubuntu:latest
stage: deploy
dependencies:
- webapp-build
before_script:
- "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- ssh-add <(echo "$CD_PRIVATE_KEY")
- ssh -P22 [email protected] "rm -r /var/www/gis/waste-detection/*"
- scp -P22 -r web_app/app/dist/* [email protected]:/var/www/gis/waste-detection/
environment:
name: production
url: https://gis.inf.elte.hu/waste-detection/
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
changes:
- web_app/**/*
- .gitlab-ci.yml
.docker-login: &docker-login
- docker version
# Login to GitLab Container Registry
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
baseimage:
stage: build
image: docker:latest
tags:
- docker
- docker-socket
variables:
IMAGE_FOLDER: .
before_script:
- *docker-login
script:
# Build Docker image
- docker build $IMAGE_FOLDER --pull --target base -t "$IMAGE_NAME_BASE:latest"
# Push Docker image to registries
- docker push "$IMAGE_NAME_BASE:latest"
# Remove old, now dangling versions of the image
- DANGLING_NUMBER=$(docker image ls --filter "dangling=true" --filter "reference=$IMAGE_NAME_BASE" --format "{{.ID}}" | wc -l)
- >
if [ $DANGLING_NUMBER -gt 0 ]; then
docker image ls --filter "dangling=true" --filter "reference=$IMAGE_NAME_BASE" --format "{{.ID}}" | xargs docker image rm
fi
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
changes:
- Dockerfile
- environment.yml
- .gitlab-ci.yml
serverapp:
stage: deploy
image: docker:latest
tags:
- docker
- docker-socket
variables:
IMAGE_FOLDER: .
before_script:
- *docker-login
script:
# Build Docker images
- docker build $IMAGE_FOLDER --pull -t "$IMAGE_NAME_SERVER:latest"
# Push Docker images to registries
- docker push "$IMAGE_NAME_SERVER:latest"
# Remove old, now dangling versions of the image
- DANGLING_NUMBER=$(docker image ls --filter "dangling=true" --filter "reference=$IMAGE_NAME_SERVER" --format "{{.ID}}" | wc -l)
- >
if [ $DANGLING_NUMBER -gt 0 ]; then
docker image ls --filter "dangling=true" --filter "reference=$IMAGE_NAME_SERVER" --format "{{.ID}}" | xargs docker image rm
fi
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
changes:
- server_app/**/*
- model/**/*
- .gitlab-ci.yml