-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
67 lines (60 loc) · 1.85 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
stages:
- test
- docker-build
- staging
variables:
STAGING_SERVER_SSH_HOST: "192.168.10.3"
STAGING_SERVER_SSH_PORT: "33"
# config for prefilled-db image
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: toor
MONGO_INITDB_DATABASE: PAQMAN
code_quality:
stage: test
image: node:15-alpine
script:
- cd frontend/ && npx prettier --check .
#frontend_tests:
# stage: test
# image: node:15-alpine
# script:
# - echo "done"
backend_tests:
stage: test
image: golang:1.16
services:
- name: registry.git.leon.wtf/paqman/database-presets/prefilled-db:full
alias: mongo
script:
- cd server/ && CI=true go test -v ./...
build_and_push_image:
stage: docker-build
rules:
- if: $CI_COMMIT_REF_NAME == "main"
image: docker:dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $CI_REGISTRY_IMAGE:dev .
- docker push $CI_REGISTRY_IMAGE:dev
stage_on_webserver:
stage: staging
rules:
- if: $CI_COMMIT_REF_NAME == "main"
environment:
name: Staging
url: https://paqman.leon.wtf
image: docker:dind
before_script:
# import SSH private key from Gitlab variable
- eval $(ssh-agent -s)
- echo "$STAGING_SERVER_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# scan target server and add keys to known_hosts
- ssh-keyscan -p $STAGING_SERVER_SSH_PORT $STAGING_SERVER_SSH_HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
# push docker-compose.yml in repository root to server and execute it
- scp -P $STAGING_SERVER_SSH_PORT ./docker-compose.yml paqman@$STAGING_SERVER_SSH_HOST:~/docker-compose.yml
- ssh paqman@$STAGING_SERVER_SSH_HOST -p $STAGING_SERVER_SSH_PORT "docker compose pull && docker compose up -d && docker compose ps"