-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INFRA] Setting : 임시 배포 github action 설정
- Loading branch information
1 parent
55c0332
commit 1613d5b
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |