-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
78 lines (72 loc) · 2.56 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
78 lines (72 loc) · 2.56 KB
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
image: node:18.14.2
variables:
CI_IMG: '"${CI_REGISTRY_IMAGE}:latest"'
TP_URL: "${CI_PROJECT_NAMESPACE}.bham.team"
TP_CONTACT: "${GITLAB_USER_EMAIL}"
stages: # List of stages for jobs, and their order of execution
- check
- build
- test
- package
- deploy
eslint:
stage: check
cache:
key: $CI_COMMIT_REF_SLUG # Run npm ci and maintain cache for each branch
paths:
- .npm/
policy: pull
before_script:
- npm ci --cache .npm --prefer-offline
script:
- npx eslint --ext .ts,.tsx client/ # Lint the client
- npx eslint --ext .ts server/ # Lint the server
tsc:
stage: build
cache:
key: $CI_COMMIT_REF_SLUG # Run npm ci and maintain cache for each branch
paths:
- .npm/
policy: pull
before_script:
- npm ci --cache .npm --prefer-offline
script:
- npx tsc # Build the client using Vite
- npx vite build # and the server using esbuild
- node esbuild.js
artifacts:
paths:
- dist # Upload ./dist to artefacts
expire_in: 1 day
docker:
stage: package
image: docker:20.10.16
services:
- docker:20.10.16-dind
variables:
DOCKER_TLS_CERTDIR: ""
rules:
- if: $CI_COMMIT_BRANCH == "main"
script:
- echo "Containerising application..."
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t ${CI_REGISTRY_IMAGE}:latest -f .cd/Dockerfile .
- docker push ${CI_REGISTRY_IMAGE}:latest
deploy-job:
stage: deploy
environment: production
rules:
- if: $CI_COMMIT_BRANCH == "main"
image: alpine:latest
before_script:
- chmod og= $SSH_KEY
- apk update && apk add openssh-client
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VM_USER@$VM "docker compose -f ~/team-project-deployment/.cd/docker-compose.yml down || true"
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VM_USER@$VM "docker rm -f $(docker ps -a -q) || true"
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VM_USER@$VM "docker volume rm $(docker volume ls -q) || true"
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VM_USER@$VM "rm -rf ~/team-project-deployment || true"
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VM_USER@$VM "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY"
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VM_USER@$VM "docker pull ${CI_REGISTRY_IMAGE}:latest"
script:
- scp -o StrictHostKeyChecking=no -i $SSH_KEY -r . $VM_USER@$VM:~/team-project-deployment
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY $VM_USER@$VM "docker compose -f ~/team-project-deployment/.cd/docker-compose.yml up -d"