Skip to content

Commit

Permalink
[INFRA] Setting : 임시 배포 github action 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
404-not-foundl committed Jun 10, 2024
1 parent 55c0332 commit 1613d5b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
102 changes: 102 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: deploy to EC2

on:
push:
branches:
- develop

jobs:

build-and-push-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: .env setting
run: |
echo "VITE_BASE_URL=${{ secrets.VITE_BASE_URL }}" >> frontend/.env
echo "VITE_USER1_TOKEN=${{ secrets.VITE_USER1_TOKEN }}" >> frontend/.env
echo "VITE_KAKAO_JAVASCRIPT_KEY=${{ secrets.VITE_KAKAO_JAVASCRIPT_KEY }}" >> frontend/.env
- name: Push Docker image latest
uses: docker/build-push-action@v2
with:
context: ./frontend
file: frontend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ggumtle-frontend

build-and-push-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Create application.properties
run: |
echo "${{ secrets.APP_PROPERTIES_PROD }}" >> src/main/resources/application-prod.properties
echo "${{ secrets.APP_PROPERTIES }}" >> src/main/resources/application.properties
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Push Docker image latest
uses: docker/build-push-action@v2
with:
context: ./backend
file: backend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/ggumtle-backend

deploy-frontend:
needs: build-and-push-frontend
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker stop frontend || true
docker rm frontend || true
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/ggumtle-frontend
docker run --name frontend -d \
-p 5173:5173 \
--network=bridge \
--restart unless-stopped \
${{ secrets.DOCKERHUB_USERNAME }}/ggumtle-frontend
docker container prune -f
deploy-backend:
needs: build-and-push-backend
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker stop backend || true
docker rm backend || true
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/ggumtle-backend
docker run --name backend -d \
-p 8081:8081 \
--network=bridge \
--restart unless-stopped \
${{ secrets.DOCKERHUB_USERNAME }}/ggumtle-backend
docker container prune -f

0 comments on commit 1613d5b

Please sign in to comment.