Skip to content

bug : dir 위치 수정 #22

bug : dir 위치 수정

bug : dir 위치 수정 #22

Workflow file for this run

name: Java CI,CD with Gradle
on:
push:
branches: [ "main" ]
jobs:
build-docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name : Copy properties
env:
privacy_yml : ${{ secrets.PRIVACY_YML }}
privacy_yml_dir : ./src/main/resources
privacy_yml_FILE_NAME : privacy.yml
run: |
cd $privacy_yml_dir
echo $privacy_yml | base64 --decode > $privacy_yml_dir/$privacy_yml_FILE_NAME
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Spring Boot 어플리케이션 Build
- name: Build with Gradle Wrapper
run: ./gradlew build
# Docker 이미지 Build
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/spring-cicd-test .
# DockerHub Login (push 하기 위해)
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# Docker hub 로 push
- name: Docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/spring-cicd-test
# 위 과정에서 푸시한 이미지를 ec2에서 풀받아서 실행
run-docker-image-on-ec2:
needs: build-docker-image
runs-on: self-hosted
steps:
- name: docker pull
run : sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/spring-cicd-test
- name: docker stop container
run: |
if [ $(sudo docker ps -a -q -f name=spring-cicd-test) ]; then
sudo docker stop spring-cicd-test
fi
- name: docker run new container
run: sudo docker run --rm -it -d -p 80:8080 --name spring-cicd-test ${{ secrets.DOCKERHUB_USERNAME }}/spring-cicd-test
- name: delete old docker image
run: sudo docker system prune -f