fix: 옵션 위치 수정 #11
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: CI/CD using github actions & docker | |
on: | |
push: | |
branches: [ "main", "develop" ] | |
permissions: | |
contents: read | |
jobs: | |
CI-CD: | |
runs-on: ubuntu-latest | |
steps: | |
# JDK setting | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.SUBMODULE_TOKEN }} | |
submodules: recursive | |
# 서브 모듈 설정 | |
- name: Update and Init Submodule | |
run: git submodule update --remote --recursive --init | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# gradle caching - 빌드 시간 향상 | |
- name: Gradle Caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# gradle build | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Separate Layered jar | |
run: java -Djarmode=layertools -jar build/libs/class-registration-1.0-SNAPSHOT.jar extract | |
# docker build & push to production | |
- name: Docker build & push to prod | |
if: contains(github.ref, 'main') | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile.prod -t ${{ secrets.DOCKER_USERNAME }}/docker-team-b-prod . | |
docker push ${{ secrets.DOCKER_USERNAME }}/docker-team-b-prod | |
## deploy to production | |
- name: Deploy to prod | |
uses: appleboy/ssh-action@master | |
id: deploy-prod | |
if: contains(github.ref, 'main') | |
with: | |
host: ${{ secrets.HOST_PROD }} | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} | |
envs: GITHUB_SHA | |
script: | | |
ssh -t -i "${{ secrets.PEM_NAME }}" ${{ secrets.WAS_HOST }}@${{ secrets.WAS_IP }} | |
sudo docker ps | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/docker-team-b-prod | |
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/docker-team-b-prod | |
sudo docker image prune -f |