deploy #65
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: deploy | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| checks: write | |
| pull-requests: write | |
| actions: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Make application.yml | |
| run: | | |
| mkdir -p ./src/main/resources | |
| cd ./src/main/resources | |
| touch ./application.yml | |
| if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
| echo "${{ secrets.APPLICATION_PROD }}" >> ./application.yml | |
| else | |
| echo "${{ secrets.APPLICATION_DEV }}" >> ./application.yml | |
| fi | |
| shell: bash | |
| - name: Build with Gradle | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew bootJar | |
| - name: Docker Build & Push | |
| run: | | |
| docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
| if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
| IMAGE_TAG="${{ secrets.DOCKER_IMAGE_TAG_PROD }}" | |
| else | |
| IMAGE_TAG="${{ secrets.DOCKER_IMAGE_TAG_DEV }}" | |
| fi | |
| docker build -t ${{ secrets.DOCKER_REPO }}/$IMAGE_TAG . | |
| docker push ${{ secrets.DOCKER_REPO }}/$IMAGE_TAG | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| environment: [ dev, prod ] | |
| steps: | |
| - name: deploy | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ matrix.environment == 'prod' && secrets.HOST_PROD || secrets.HOST_DEV }} | |
| username: ubuntu | |
| key: ${{ matrix.environment == 'prod' && secrets.KEY_PROD || secrets.KEY_DEV }} | |
| port: 22 | |
| script: | | |
| if [ "${{ matrix.environment }}" == "prod" ]; then | |
| IMAGE_TAG="${{ secrets.DOCKER_IMAGE_TAG_PROD }}" | |
| COMPOSE_CMD="sudo docker compose" | |
| else | |
| IMAGE_TAG="${{ secrets.DOCKER_IMAGE_TAG_DEV }}" | |
| COMPOSE_CMD="sudo docker compose -f docker-compose-app.yml" | |
| fi | |
| sudo docker pull ${{ secrets.DOCKER_REPO }}/$IMAGE_TAG | |
| $COMPOSE_CMD down | |
| $COMPOSE_CMD up -d | |
| if: | | |
| (matrix.environment == 'prod' && github.ref == 'refs/heads/main') || | |
| (matrix.environment == 'dev' && github.ref != 'refs/heads/main') | |
| # host: ${{ secrets.HOST }} | |
| # username: ubuntu | |
| # key: ${{ secrets.KEY }} | |
| # port: 22 | |
| # script: | | |
| # sudo docker pull ${{ secrets.DOCKER_REPO }}/rb_backend | |
| # sudo docker compose -f docker-compose-app.yml down | |
| # sudo docker compose -f docker-compose-app.yml up -d |