-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
101 lines (96 loc) · 4.76 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
stages:
- build
- deploy
build-BE:
tags:
- shell1
stage: build
image: alpine
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- cd backend
- docker pull $CI_REGISTRY_IMAGE/backend:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE/backend:latest --tag $CI_REGISTRY_IMAGE/backend:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE/backend:latest .
- docker push $CI_REGISTRY_IMAGE/backend:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE/backend:latest
build-FE:
tags:
- shell1
stage: build
image: alpine
variables:
CI: "false"
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- cd frontend
- docker pull $CI_REGISTRY_IMAGE/frontend:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE/frontend:latest --tag $CI_REGISTRY_IMAGE/frontend:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE/frontend:latest --build-arg NPM_TOKEN=$CI_JOB_TOKEN .
- docker push $CI_REGISTRY_IMAGE/frontend:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE/frontend:latest
deploy_staging:
tags:
- shell1
stage: deploy
# image: alpine
environment:
name: staging
url: http://$DEPLOYMENT_HOST_IP:$DEPLOYMENT_STAGING_HOST_PORT
before_script:
# - apk add openssh-client
- eval $(ssh-agent -s)
- ssh-add - <<< "${KEY_PROD}"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
script:
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "rm -rf mda_staging.env; echo VERSION=$CI_COMMIT_SHA >> mda_staging.env; echo PORT=$DEPLOYMENT_STAGING_HOST_PORT >> mda_staging.env; echo PORT_DB=$DEPLOYMENT_STAGING_DB_HOST_PORT >> mda_staging.env;"
- scp docker-compose.yaml $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP:mda_staging_docker-compose.yaml
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY"
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker-compose --env-file mda_staging.env -p mda_staging -f mda_staging_docker-compose.yaml pull"
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker-compose --env-file mda_staging.env -p mda_staging -f mda_staging_docker-compose.yaml up -d "
only:
- main
deploy_prod:
tags:
- shell1
stage: deploy
environment:
name: production
url: http://$DEPLOYMENT_HOST_IP:$DEPLOYMENT_PRODUCTION_HOST_PORT
before_script:
- eval $(ssh-agent -s)
- ssh-add - <<< "${KEY_PROD}"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
script:
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "rm -rf mda_prod.env; echo VERSION=$CI_COMMIT_SHA >> mda_prod.env; echo PORT=$DEPLOYMENT_PRODUCTION_HOST_PORT >> mda_prod.env; echo PORT_DB=$DEPLOYMENT_PRODUCTION_DB_HOST_PORT >> mda_prod.env;"
- scp docker-compose.yaml $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP:mda_prod_docker-compose.yaml
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY"
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker-compose --env-file mda_prod.env -p mda_prod -f mda_prod_docker-compose.yaml pull"
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker-compose --env-file mda_prod.env -p mda_prod -f mda_prod_docker-compose.yaml up -d "
when: manual
only:
- main
deploy_staging_qa:
tags:
- shell1
stage: deploy
# image: alpine
environment:
name: staging_qa
url: http://$DEPLOYMENT_HOST_IP:$DEPLOYMENT_STAGING_QA_HOST_PORT
before_script:
# - apk add openssh-client
- eval $(ssh-agent -s)
- ssh-add - <<< "${KEY_PROD}"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
script:
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "rm -rf mda_staging_qa.env; echo VERSION=$CI_COMMIT_SHA >> mda_staging_qa.env; echo PORT=$DEPLOYMENT_STAGING_QA_HOST_PORT >> mda_staging_qa.env; echo PORT_DB=$DEPLOYMENT_STAGING_QA_DB_HOST_PORT >> mda_staging_qa.env;"
- scp docker-compose.yaml $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP:mda_staging_qa_docker-compose.yaml
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY"
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker-compose --env-file mda_staging_qa.env -p mda_staging_qa -f mda_staging_qa_docker-compose.yaml pull"
- ssh -o StrictHostKeyChecking=no $DEPLOYMENT_ACCOUNT@$DEPLOYMENT_HOST_IP "docker-compose --env-file mda_staging_qa.env -p mda_staging_qa -f mda_staging_qa_docker-compose.yaml up -d "
only:
- develop