-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
57 lines (52 loc) · 1.45 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
stages:
- frontend_build
- backend_build
- backend_deploy
variables:
SSH_SERVER: 34.64.87.27
SSH_PORT: 22
SSH_USER: elice
FRONT_TARGET_DIR: /front/build
IMAGE_TAG: $CI_COMMIT_SHA
before_script:
- 'which ssh-agent || (apk add --update openssh-client)'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -p $SSH_PORT $SSH_SERVER >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
frontend_build:
stage: frontend_build
script:
- cd front
- yarn install
- yarn build
tags:
- front
artifacts:
paths:
- front/build/*
backend_build:
stage: backend_build
script:
- cd back
- docker buildx build --platform=linux/amd64 --load --tag daechanjo/wordy:$IMAGE_TAG .
- docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- docker push daechanjo/$IMAGE_TAG
tags:
- back_b
only:
- develop
backend_deploy:
stage: backend_deploy
script:
- scp -P $SSH_PORT -r ./front/build/* $SSH_USER@$SSH_SERVER:$FRONT_TARGET_DIR
- 'ssh -p $SSH_PORT $SSH_USER@$SSH_SERVER "docker pull daechanjo/wordy:$IMAGE_TAG"'
- ssh -p $SSH_PORT $SSH_USER@$SSH_SERVER "sed -i 's|daechanjo/wordy:.*|daechanjo/$IMAGE_TAG|' docker-compose.yml"
- 'ssh -p $SSH_PORT $SSH_USER@$SSH_SERVER "docker-compose down"'
- 'ssh -p $SSH_PORT $SSH_USER@$SSH_SERVER "docker-compose up --build --detach"'
tags:
- back_d
only:
- develop