Merge pull request #9 from s2hoon/refactor/Transactional #45
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 CI with Gradle | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 19 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '19' | |
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- | |
## create application-dev.properties | |
- name: make application-dev.properties | |
if: contains(github.ref, 'develop') | |
run: | | |
cd ./src/main/resources | |
touch ./application-dev.properties | |
echo "${{ secrets.PROPERTIES_DEV }}" > ./application-dev.properties | |
shell: bash | |
## create application-prod.properties | |
- name: make application-prod.properties | |
if: contains(github.ref, 'main') # branch가 main 일 때, 나머지는 위와 동일 | |
run: | | |
cd ./src/main/resources | |
touch ./application-prod.properties | |
echo "${{ secrets.PROPERTIES_PROD }}" > ./application-prod.properties | |
shell: bash | |
## gradle build | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
## 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 }}/dub-prod . | |
docker push ${{ secrets.DOCKER_USERNAME }}/dub-prod | |
## docker build & push to develop | |
- name: Docker build & push to dev | |
if: contains(github.ref, 'develop') | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile-dev -t ${{ secrets.DOCKER_USERNAME }}/dub-dev . | |
docker push ${{ secrets.DOCKER_USERNAME }}/dub-dev | |
## 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.SSH_KEY }} | |
envs: GITHUB_SHA | |
script: | | |
sudo docker stop dub | |
sudo docker rm dub | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/dub-prod | |
sudo docker run -d -p 8080:8080 --name dub ${{ secrets.DOCKER_USERNAME }}/dub-prod | |
sudo docker image prune -f | |
## deploy to develop | |
- name: Deploy to dev | |
uses: appleboy/ssh-action@master | |
id: deploy-dev | |
if: contains(github.ref, 'develop') | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ec2-user | |
key: ${{ secrets.SSH_KEY }} | |
port: 22 | |
#key: ${{ secrets.PRIVATE_KEY }} | |
script: | | |
sudo docker stop dub-dev | |
sudo docker rm -fv dub-dev | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/dub-dev | |
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/dub-dev | |
sudo docker image prune -f | |