-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
52 lines (50 loc) · 1.79 KB
/
.gitlab-ci.yml
File metadata and controls
52 lines (50 loc) · 1.79 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
stages:
- build
- deploy
# Build Stage: React 애플리케이션 빌드
build:
stage: build
image: node:16.14.2
script:
- npm install
- npm run build
artifacts:
paths:
- build/
only:
- review
# Deploy Stage: 프론트엔드
deploy:
stage: deploy
image: nginx:alpine
services:
- name: docker:dind
alias: docker
command: [ "--tls=false" ]
variables:
DOCKER_HOST: "tcp://docker:2375"
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
before_script:
# 설치
- apk update && apk add --no-cache docker
- apk add openssh-client
# SSH 키 Setup
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H $GCP_VM_IP >> ~/.ssh/known_hosts
script:
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USER" --password-stdin
- docker build -t $DOCKER_USER/mosoo_react:latest .
- docker push $DOCKER_USER/mosoo_react:latest
# .env 파일 생성
- echo "DOCKER_USER=$DOCKER_USER" > .env
- echo "REACT_APP_API_BASE_URL=$REACT_APP_API_BASE_URL" >> .env
# GCP VM에 전송 및 SSH 접속 후 Docker-compose
- scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa .env $GCP_USER@$GCP_VM_IP:/path/to/your/project/react/
- scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa docker-compose.yml $GCP_USER@$GCP_VM_IP:/path/to/your/project/react/
- ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa $GCP_USER@$GCP_VM_IP "cd /path/to/your/project/react/ && docker pull $DOCKER_USER/mosoo_react:latest && docker-compose down || echo 'Containers were not running or failed to stop.' && docker image prune -f"
- ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa $GCP_USER@$GCP_VM_IP "cd /path/to/your/project/react/ && docker-compose up -d"
only:
- review