diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..9c7e095a Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml new file mode 100644 index 00000000..75cb3752 --- /dev/null +++ b/.github/workflows/action.yml @@ -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 \ No newline at end of file