fix: 워크플로우 수정 (#10) #8
Workflow file for this run
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: build and deploy | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
environment: master | |
steps: | |
- name: Checkout Github actions | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
uses : gradle/gradle-build-action@v2 | |
with: | |
arguments: | | |
build | |
--scan | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Docker에 Build & Push | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server:latest | |
deploy: | |
runs-on: ubuntu-latest | |
environment: master | |
needs: build | |
steps: | |
- name: Docker compose | |
uses: appleboy/ssh-action@master | |
with: | |
username: ubuntu | |
host: ${{ secrets.INFRA_PRACTICE_SERVER_IP }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server:latest | |
sudo docker run -d -p 80:8080 --name deploy_container ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server:latest |