merge : pull origin develop #21
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: Java CD with Gradle | |
on: | |
push: | |
branches: [ "develop", "main", "Server/CD" ] | |
paths: ["Server/banchango/**"] | |
pull_request: | |
branches: [ "develop", "main", "Server/CD" ] | |
paths: ["Server/banchango/**"] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
- name: make application-prod.yml | |
run: | | |
cd ./Server/banchango/src/main/resources | |
touch ./application-prod.properties | |
echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.properties | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./Server/banchango/gradlew | |
- name: Build with Gradle | |
run: | | |
cd Server/banchango | |
./gradlew clean build -x test | |
- name: Docker build | |
run: | | |
cd Server/banchango | |
docker login -u ${{ secrets.SERVER_DOCKER_USERNAME }} -p ${{ secrets.SERVER_DOCKER_PASSWORD }} | |
docker build -t app . | |
docker tag app ${{ secrets.SERVER_DOCKER_USERNAME }}/banchango:latest | |
docker push ${{ secrets.SERVER_DOCKER_USERNAME }}/banchango:latest | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ec2-user | |
key: ${{ secrets.SERVER_PEM_KEY }} # pem 키 | |
# 도커 작업 | |
script: | | |
docker pull ${{ secrets.SERVER_DOCKER_USERNAME }}/banchango:latest | |
docker stop $(docker ps -a -q) | |
docker run -d --log-driver=syslog -p 8080:8080 ${{ secrets.SERVER_DOCKER_USERNAME }}/banchango:latest | |
docker rm $(docker ps --filter 'status=exited' -a -q) | |
docker image prune -a -f |