Merge pull request #50 from ChoiWonYu/develop #33
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: Spring CI/CD | |
on: | |
push: | |
branches: [ "master" ] | |
permissions: | |
contents: read | |
jobs: | |
CI: | |
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: Add permission | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 | |
with: | |
arguments: clean bootJar | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/${{secrets.IMAGE_NAME}} . | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{secrets.DOCKER_USERNAME}} | |
password: ${{secrets.DOCKER_PASSWORD}} | |
- name: push image to Docker Hub | |
run: docker push ${{secrets.DOCKER_USERNAME}}/${{secrets.IMAGE_NAME}} | |
deploy: | |
needs: CI | |
name: CD | |
runs-on: self-hosted | |
steps: | |
- name: docker stop container | |
run: | | |
sudo docker compose stop || true | |
- name: pull image from docker hub | |
run: | | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{secrets.IMAGE_NAME}} | |
- name: compose up spring application | |
run: | | |
sudo docker compose --env-file ~/.env -f ~/docker-compose.yml up -d --build | |
sudo docker system prune -f |