[Issue] cicd 파일 수정 #28
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 CI with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
CI: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# .gitignore에 있는 properties파일 추가 | |
- name: Add prod_properties | |
run: | | |
mkdir ./src/main/resources | |
touch ./src/main/resources/application.properties | |
echo "${{ secrets.PROPERTIES }}" > ./src/main/resources/application.properties | |
# .gitingnore에 있는 .env파일 docker compose 실행을 위해 추가 | |
- name: Add .env | |
run: | | |
touch .env | |
echo "${{ secrets.ENV }}" > .env | |
- name: Verify .env file | |
run: | | |
ls -l .env | |
cat .env | |
- 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: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle Wrapper | |
run: ./gradlew clean build --exclude-task test | |
# Docker Image Build and Push | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Build | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }} | |
CD: | |
needs: [ CI ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# .gitignore에 있는 properties파일 추가 | |
- name: Add prod_properties | |
run: | | |
mkdir ./src/main/resources | |
touch ./src/main/resources/application.properties | |
echo "${{ secrets.PROPERTIES }}" > ./src/main/resources/application.properties | |
# .gitingnore에 있는 .env파일 docker compose 실행을 위해 추가 | |
- name: Add .env | |
run: | | |
touch .env | |
echo "${{ secrets.ENV }}" > .env | |
- name: Verify .env file | |
run: | | |
ls -l .env | |
cat .env | |
- name: Deploy .env to EC2 | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.DEPLOYMENT_HOST }} | |
username: ${{ secrets.DEPLOYMENT_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
source: ./.env | |
target: /home/serverking/marketplace | |
- name: Deploy docker compose file | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.DEPLOYMENT_HOST }} | |
username: ${{ secrets.DEPLOYMENT_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
source: ./docker-compose.yml | |
target: /home/serverking/marketplace | |
- name: Deploy remote ssh commands using password | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.DEPLOYMENT_HOST }} | |
username: ${{ secrets.DEPLOYMENT_USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
script_stop: true | |
script: | | |
cd marketplace | |
docker-compose pull | |
docker-compose up -d |