Skip to content

Merge pull request #40 from SUIN-BUNDANG-LINE/develop #20

Merge pull request #40 from SUIN-BUNDANG-LINE/develop

Merge pull request #40 from SUIN-BUNDANG-LINE/develop #20

Workflow file for this run

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"]}'