Skip to content

Commit

Permalink
Merge pull request #135 from sayyyho/develop
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
sayyyho authored Oct 6, 2024
2 parents 25f8476 + edd237f commit 749b8e7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
67 changes: 21 additions & 46 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,32 @@
name: Deploy to AWS EC2 using Docker
name: Deploy

on:
push:
branches:
- main

env:
DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_IMAGE_NAME }}
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_SSH_USER: ${{ secrets.EC2_SSH_USER }}
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
branches: ["main"]

jobs:
build-and-push-docker:
build:
runs-on: ubuntu-latest
container:
image: pandoc/latex

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create .env file
run: |
echo "VITE_BASE_URL=${{ secrets.VITE_BASE_URL }}" > .env
echo "VITE_GA_MEASUREMENT_ID=${{ secrets.VITE_GA_MEASUREMENT_ID }}" >> .env
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ env.DOCKER_IMAGE_NAME }}:latest
- uses: actions/checkout@v3

- name: Login to Docker Hub using Access Token
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: creates output
run: sh ./build.sh

- name: Push the Docker image
run: docker push ${{ env.DOCKER_IMAGE_NAME }}:latest

deploy-to-ec2:
needs: build-and-push-docker
runs-on: ubuntu-latest

steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@master
- name: Pushes to origin repository
id: push_directory
uses: cpina/github-action-push-to-another-repository@main
env:
API_TOKEN_GITHUB: ${{ secrets.AUTO_ACTIONS }}
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_SSH_USER }}
key: ${{ env.PRIVATE_KEY }}
script: |
CONTAINER_ID=$(sudo docker ps -aq --filter "name=dgu-booth")
if [ ! -z "$CONTAINER_ID" ]; then
sudo docker stop $CONTAINER_ID || true
sudo docker rm -f $CONTAINER_ID || true
fi
sudo docker pull ${{ env.DOCKER_IMAGE_NAME }}:latest
sudo docker run --name dgu-booth-$(date +%s) -d -p 80:80 -p 3000:3000 -e TZ=Asia/Seoul ${{ env.DOCKER_IMAGE_NAME }}:latest
sudo docker image prune -f
source-directory: "output"
destination-github-username: sayyyho
destination-repository-name: 2024_fall_festival_front
user-email: "323psh@naver.com"
commit-message: "배포"

- name: Test get variable exported by push-to-another-repository
run: echo $DESTINATION_CLONED_DIRECTORY
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!/bin/sh

cd ../

mkdir output

cp -R ./2024_fall_festival_front/* ./output

cp -R ./output ./2024_fall_festival_front

0 comments on commit 749b8e7

Please sign in to comment.