[INFRA] Setting : 임시 배포 backend github action 설정오류 수정 #3
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
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 }}" >> backend/src/main/resources/application-prod.properties | |
echo "${{ secrets.APP_PROPERTIES }}" >> backend/src/main/resources/application.properties | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '11' | |
- name: Grant execute permission for gradlew | |
run: chmod +x backend/gradlew | |
- name: Build with Gradle | |
run: ./gradlew build | |
working-directory: backend | |
- 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 |