Skip to content

Chore : Update gradle.yml #52

Chore : Update gradle.yml

Chore : Update gradle.yml #52

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "CHAT-63-DevOps-ToolChain" ]
pull_request:
branches: [ "CHAT-63-DevOps-ToolChain" ]
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: Docker Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_PWD }}
- name: Set up Docker
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: true
tags: chatdiary/chatdiary-image:latest
- name: Build Docker Image
run: |
docker build -t chatdiary/chatdiary-image:latest .
docker images
- name: Push Docker Image
run: docker push chatdiary/chatdiary-image:latest
deploy:
runs-on: ubuntu-latest
needs: docker-build
steps:
- name: Checkout repository
uses: actions/checkout@v3 # Checkout ์•ก์…˜ ๋ฒ„์ „์„ v3์œผ๋กœ ์ผ์น˜
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
- name: Check if JAR file exists
run: |
if [ -f "./build/libs/chatdiary-0.0.1-SNAPSHOT-plain.jar" ]; then
echo "JAR file exists"
else
echo "JAR file does not exist"
fi
- name: Copy jar file to remote
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
source: "./build/libs/chatdiary-0.0.1-SNAPSHOT-plain.jar"
target: "/home/ec2-user/cicd"
- name: Check deploy script exists
run: |
if [ -f deploy.sh ]; then
echo "deploy.sh exists"
else
echo "deploy.sh does not exist"
exit 1
fi
- name: Copy deploy script file to remote
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
source: "deploy.sh"
target: "/home/ec2-user/cicd"
- name: Execute deploy script
env:
DEPLOY_SERVER: ${{ secrets.HOST }}
DEPLOY_USER: ${{ secrets.USER }}
DEPLOY_KEY: ${{ secrets.PRIVATE_KEY }}
DEPLOY_TARGET_DIR: /home/ec2-user/app
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
chmod +x /home/ec2-user/cicd/deploy.sh
sh /home/ec2-user/cicd/deploy.sh