✨ Crawlling #29
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 Boot & Gradle CI/CD | |
on: | |
push: | |
branches: [ "main" ] | |
paths: | |
- 'Backend/**' # Backend 폴더 내의 변경사항만 감지 | |
pull_request: | |
branches: [ "main" ] | |
paths: | |
- 'Backend/**' # Backend 폴더 내의 변경사항만 감지 | |
jobs: | |
build: | |
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' | |
# application-prod.yml 생성 | |
- name: make application.yml | |
run: | | |
cd Backend/src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.APPLICATION_PROD }}" > ./application.yml | |
- name: check | |
run: | | |
cd Backend/src/main/resources | |
ls -al | |
cat ./application.yml | |
- name: Grant execute permission for gradlew | |
run: chmod +x Backend/gradlew # 경로를 Backend 폴더 내부로 변경 | |
- name: Build with Gradle | |
run: cd Backend && ./gradlew clean build --exclude-task test # Backend 폴더로 이동 후 빌드 | |
- name: DockerHub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker Image Build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} -f Backend/Dockerfile Backend # Dockerfile 위치와 빌드 컨텍스트 변경 | |
- name: DockerHub Push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
- name: Application Run | |
uses: appleboy/ssh-action@v0.1.6 | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
sudo docker kill ${{ secrets.PROJECT_NAME }} | |
sudo docker rm -f ${{ secrets.PROJECT_NAME }} | |
sudo docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} | |
sudo docker run -p ${{ secrets.PORT }}:${{ secrets.PORT }} \ | |
--name ${{ secrets.PROJECT_NAME }} \ | |
-d ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROJECT_NAME }} |