Skip to content

[Chore] Dockerfile에서 JAR 파일 명시 #6

[Chore] Dockerfile에서 JAR 파일 명시

[Chore] Dockerfile에서 JAR 파일 명시 #6

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Gradle Build (test는 제외)
- name: Build with Gradle
run: ./gradlew build -x test
# 도커 허브에 로그인
- name: Docker Hub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER_NAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_USER_NAME }}/eatmate .
- name: Push Docker image
run: docker push ${{ secrets.DOCKER_USER_NAME }}/eatmate
# 환경별 yml 파일 생성(1) - application.yml
- name: make application.yml
if: |
contains(github.ref, 'develop')
run: |
mkdir ./src/main/resources # resources 폴더 생성
cd ./src/main/resources # resources 폴더로 이동
touch ./application.yml # application.yml 생성
echo "${{ secrets.YML }}" > ./application.yml # github actions에서 설정한 값을 application.yml 파일에 쓰기
shell: bash
# 환경별 yml 파일 생성(2) - dev
- name: make application-dev.yml
if: contains(github.ref, 'develop')
run: |
cd ./src/main/resources
touch ./application-dev.yml
echo "${{ secrets.YML_DEV }}" > ./application-dev.yml
shell: bash
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "publish=8080" -f "status=running")
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then
sudo docker stop $EXISTING_CONTAINER_ID
sudo docker rm $EXISTING_CONTAINER_ID
fi
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "status=exited")
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then
sudo docker rm $EXISTING_CONTAINER_ID
fi
sudo docker pull ${{ secrets.DOCKER_USER_NAME }}/eatmate
sudo docker run --name spring -d -p 8080:8080 --env-file ./eatmate-dev.env -e TZ=Asia/Seoul ${{ secrets.DOCKER_USER_NAME }}/eatmate
sudo docker image prune -a -f
debug: true # Enable debugging output