cicd: main 브랜치가 프로덕션 서버에 반영되도록 변경 #37
This file contains hidden or 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: CI/CD | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/[email protected] | |
| - name: Log in to Docker Hub | |
| uses: docker/[email protected] | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and Push Docker image | |
| if: github.ref == 'refs/heads/dev' | |
| uses: docker/[email protected] | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROD_IMAGE_NAME }}:latest | |
| platforms: linux/amd64 | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: SSH to Server and Deploy | |
| if: github.ref == 'refs/heads/dev' | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.PROD_SERVER_HOST }} | |
| port: ${{ secrets.PROD_SERVER_PORT }} | |
| username: ${{ secrets.PROD_SERVER_USERNAME }} | |
| key: ${{ secrets.PROD_SERVER_KEY }} | |
| script: | | |
| cd /home/ubuntu/dasom | |
| mkdir -p ./env | |
| echo "${{ secrets.ENV }}" > ./env/prodEnv | |
| ./deploy.sh |