Skip to content

Merge pull request #4 from Sangwook02/feature/3-create-dockerfile #4

Merge pull request #4 from Sangwook02/feature/3-create-dockerfile

Merge pull request #4 from Sangwook02/feature/3-create-dockerfile #4

Workflow file for this run

name: build and deploy
on:
push:
branches: [ "master" ]
permissions:
contents: read
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: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
run : ./gradlew clean build --exclude-task test
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker
run: docker build --platform linux/amd64 -t ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server .
- name: Push Docker
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server:latest
deploy:
runs-on: ubuntu-latest
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 8080:8080 --name deploy_container ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server:latest