Skip to content

[FIX] 챌린지 이후 행운이 갱신이 안되는 현상 수정 #76

[FIX] 챌린지 이후 행운이 갱신이 안되는 현상 수정

[FIX] 챌린지 이후 행운이 갱신이 안되는 현상 수정 #76

name: Docker Image CI and Deploy to Amazon EC2
on:
push:
branches: ['main']
pull_request:
branches: ['main']
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Docker Setup Buildx
uses: docker/[email protected]
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set image name with date
run: echo "IMAGE_NAME=bada308/mooluck-react:$(date +%s)" >> $GITHUB_ENV
- name: Build and push the Docker image
run: |
docker build . --file Dockerfile -t ${{ env.IMAGE_NAME }}
docker push ${{ env.IMAGE_NAME }}
- name: Save image name to file
run: echo ${{ env.IMAGE_NAME }} > image-name.txt
- name: Upload image name artifact
uses: actions/[email protected]
with:
name: image-name
path: image-name.txt
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download image name artifact
uses: actions/[email protected]
with:
name: image-name
- name: Read image name from file
id: read-image-name
run: echo "IMAGE_NAME=$(cat image-name.txt)" >> $GITHUB_ENV
- name: SSH into EC2 and deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker pull ${{ env.IMAGE_NAME }}
sudo docker stop mooluck-react || true
sudo docker rm mooluck-react || true
sudo docker run -d --name mooluck-react -p 5173:5173 \
-e VITE_API_URL=${{ secrets.VITE_API_URL }} \
-e VITE_WEBSOCKET_URL=${{ secrets.VITE_WEBSOCKET_URL }} \
-e VITE_NODE_API_URL=${{ secrets.VITE_NODE_API_URL }} \
${{ env.IMAGE_NAME }}