-
Notifications
You must be signed in to change notification settings - Fork 1
45 lines (40 loc) · 1.57 KB
/
prod_deploy.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
name: Frontend 프로덕션 서버 EC2 배포
on:
push:
branches:
- main
workflow_dispatch: # 수동 실행 이벤트 추가
jobs:
deploy:
name: 배포 작업
runs-on: ubuntu-latest
env:
# AWS 관련
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ap-northeast-2
EC2_INSTANCE_ID: ${{ secrets.FRONTEND_EC2_INSTANCE_ID }}
# Docker 관련
CONTAINER_NAME: sulmun2yong-production-client
# Next.js 관련
ENV_CONTENT: ${{ secrets.FRONTEND_PRODUCTION_ENV_CONTENT }}
steps:
- name: AWS 로그인
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: SSM으로 EC2에 배포
run: |
aws --no-cli-pager ssm send-command \
--document-name "AWS-RunShellScript" \
--targets "Key=instanceIds, Values=${{ env.EC2_INSTANCE_ID}}" \
--parameters '{"workingDirectory": ["/home/ubuntu/Frontend"],
"commands" : ["git pull origin main",
"echo \"${{ env.ENV_CONTENT }}\" | base64 -d > .env.local",
"docker stop ${{ env.CONTAINER_NAME }} || true",
"docker rm ${{ env.CONTAINER_NAME }} || true",
"docker build -t ${{ env.CONTAINER_NAME }}:latest . ",
"docker run -d -p 3000:3000 --name ${{ env.CONTAINER_NAME }} ${{ env.CONTAINER_NAME }}:latest",
"docker image prune -af"]}'