Create README.md #59
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: Deploy to dev server | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
env: | |
HOST: ${{ secrets.HOST }} | |
USERNAME: ${{ secrets.USERNAME }} | |
KEY: ${{ secrets.SSH_KEY }} | |
PORT: ${{ secrets.PORT }} | |
INSTANCE_PATH: ./lifty-backend-dev | |
IMAGE_NAME: shinsion/lifty-server-dev | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Make gradlew executable | |
run: chmod +x ./gradlew # Gradle 스크립트 파일에 실행 권한을 부여합니다. | |
- name: Create application.yml | |
run: | | |
mkdir -p ./src/main/resources | |
cd ./src/main/resources | |
echo "${{ secrets.APPLICATION }}" >> ./application.yml | |
- name: Create Google Credentials JSON | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.GOOGLE_CREDENTIALS }}" | base64 -d > "${{ secrets.GOOGLE_CREDENTIALS_NAME }}" | |
- name: Create Google Credentials JSON | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.GOOGLE_CREDENTIALS }}" | base64 -d > "${{ secrets.GOOGLE_CREDENTIALS_NAME }}" | |
- name: Build with Gradle | |
run: ./gradlew clean build | |
- name: Dockerhub login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker image build and push | |
run: | | |
docker build -t ${{ env.IMAGE_NAME }} . | |
docker push ${{ env.IMAGE_NAME }} | |
- name: Pull Docker image to server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.HOST}} | |
username: ${{ env.USERNAME }} | |
key: ${{ env.KEY }} | |
port: ${{ env.PORT }} | |
script: | | |
cd lifty-backend-dev | |
docker stop lifty-backend-dev | |
docker rm lifty-backend-dev | |
docker rmi ${{ env.IMAGE_NAME }}:latest | |
docker compose up -d |