-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
72 lines (67 loc) · 2.23 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
default:
image: docker:24.0.5
services:
- docker:24.0.5-dind
stages:
- build
- test
- deploy
variables:
# Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
REDIS_HOST: $REDIS_HOST
REDIS_PORT: $REDIS_PORT
REDIS_PASSWORD: $REDIS_PASSWORD
REDIS_DB: $REDIS_DB
AES_KEY: $AES_KEY
JWT_ACCESS_SECRET: $JWT_ACCESS_SECRET
JWT_REFRESH_SECRET: $JWT_REFRESH_SECRET
ACCESS_TOKEN_EXPIRES_IN: $ACCESS_TOKEN_EXPIRES_IN
REFRESH_TOKEN_EXPIRES_IN: $REFRESH_TOKEN_EXPIRES_IN
VERIFICATION_EXPIRES_IN: $VERIFICATION_EXPIRES_IN
build_frontend:
stage: build
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t "$CONTAINER_TEST_IMAGE"_frontend ./frontend
- docker push "$CONTAINER_TEST_IMAGE"_frontend
rules:
- changes:
- frontend/**/*
build_backend:
stage: build
before_script:
- apk add curl bash
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t "$CONTAINER_TEST_IMAGE"_backend ./backend
- docker push "$CONTAINER_TEST_IMAGE"_backend
rules:
- changes:
- backend/**/*
deploy:
stage: deploy
image: alpine
before_script:
# install envsubst and ssh-add
- apk add gettext openssh-client
script:
# create the new docker-compose.yml
- envsubst < docker-compose.tmpl > docker-compose.yml
# start ssh-agent and import ssh private key
- eval `ssh-agent`
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# add server to list of known hosts
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- touch ~/.ssh/known_hosts
- chmod 600 ~/.ssh/known_hosts
- ssh-keyscan -H 54.254.163.171 > ~/.ssh/known_hosts
# upload docker-compose to the server
- scp docker-compose.yml ec2-user@54.254.163.171:~/myas/
# docker login and restart services
- ssh ec2-user@54.254.163.171 "cd myas && docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY && docker-compose down && docker-compose pull && docker-compose up -d"