Skip to content

Refactor: redirect url #97

Refactor: redirect url

Refactor: redirect url #97

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches:
- main
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
## gradle caching
- name: Gradle Caching
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
## 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 }}/studyflex .
docker push ${{ secrets.DOCKER_USERNAME }}/studyflex
## 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 studyflex
sudo docker rm studyflex
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/studyflex
sudo docker run -d -p 8080:8080 --name studyflex ${{ secrets.DOCKER_USERNAME }}/studyflex
sudo docker image prune -f