Merge pull request #139 from MYONGSIK/develop #42
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Java CD with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: write-all | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 1) μν¬νλ‘μ° μ€ν μ κΈ°λ³Έμ μΌλ‘ 체ν¬μμ νμ | |
- uses: actions/checkout@v3 | |
# 2) JDK 11 λ²μ μ€μΉ | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
# 3) Gradle Caching | |
- name: Gradle Cashing | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# 4) Gradle κΆν λΆμ¬ | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# 5) Build exclude test package | |
#- name: Build with gradle | |
# run: ./gradlew build -x test | |
# 6) Set for yml | |
- name: Make application-secret.yml | |
run: | | |
cd ./src/main/resources | |
touch ./application-secret.yml | |
echo "${{ secrets.PROPERTIES_TEST }}" > ./application-secret.yml | |
shell: bash | |
# 7) λΉλ | |
- name: Build with gradle | |
run: ./gradlew bootJar | |
# 8) Docker λΉλ & νΈμ¬ | |
- name: docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/myongsik . | |
docker push ${{ secrets.DOCKER_USERNAME }}/myongsik | |
# 9) Deploy (PROD1) | |
- name: Deploy (PROD1) | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
docker stop myongsik_prod1 | |
docker rm myongsik_prod1 | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/myongsik | |
sudo docker run -d --name myongsik_prod1 -v /var/log/app:/var/log/app -v /etc/localtime:/etc/localtime:ro -e JAVA_OPTS=-Djasypt.encryptor.password=${{ secrets.YML_PASSWORD }} -e TZ=Asia/Seoul -e ENVIRONMENT_VALUE=-Dspring.profiles.active=prod -p 8085:8080 ${{ secrets.DOCKER_USERNAME }}/myongsik:latest | |
docker rmi -f $(docker images -f "dangling=true" -q) |