Skip to content

Chore : CI/CD 구성 (#6) #70

Chore : CI/CD 구성 (#6)

Chore : CI/CD 구성 (#6) #70

Workflow file for this run

name: Java CI/CD with Gradle
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew --warning-mode all build -i
docker-build:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permisson for gradlew
run: chmod +x gradlew
- name: Build with Gradle (without Test)
run: ./gradlew clean build -x test --stacktrace
- name: Docker Hub build & push
run: |
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PWD }}
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} .
docker images
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}
- name: deploy
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.WAS_HOST }}
key: ${{ secrets.WAS_PRIVATE_KEY }}
port: ${{ secrets.WAS_PORT }}
script: |
sudo docker ps
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}
sudo docker image prune -f