Merge pull request #38 from FTHON-6TEAM/main #24
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: [ "test" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Gradle 권한 부여 | |
- name: Grant permission for gradlew | |
run: chmod +x ./gradlew | |
# 테스트 및 빌드 | |
# - name: Build with Gradle | |
# run: ./gradlew clean bootJar | |
# | |
# - run: ls | |
# - run: ls build | |
# - run: ls build/libs | |
- name: Docker build | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: ./Dockerfile | |
push: false | |
tags: challenger:latest | |
- run: /usr/bin/docker save -o challenger.tar challenger:latest | |
- run: ls | |
# tar 파일 권한 수정 | |
- name: Set permission for tar file | |
run: chmod 664 challenger.tar | |
- name: Send docker image file to test server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.DEVELOP_HOST}} | |
username: ${{ secrets.POSTOFFICE_NAME }} | |
password : ${{ secrets.POSTOFFICE_PASS }} | |
port: ${{ secrets.DEVELOP_PORT}} | |
source: "challenger.tar" | |
target: "/home/fton/backend" | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Bootup server | |
uses: cross-the-world/ssh-scp-ssh-pipelines@latest | |
with: | |
host: ${{ secrets.DEVELOP_HOST}} | |
user: ${{ secrets.POSTOFFICE_NAME }} | |
pass: ${{ secrets.POSTOFFICE_PASS }} | |
port: ${{ secrets.DEVELOP_PORT}} | |
connect_timeout: 120s | |
first_ssh: | | |
docker stop challenger || true; | |
docker rm challenger || true; | |
docker image rm challenger:latest || true; | |
- name: Load versions to image | |
run : sshpass -p ${{ secrets.POSTOFFICE_PASS }} ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=60 -o ServerAliveCountMax=60 -T -p ${{ secrets.DEVELOP_PORT}} ${{ secrets.POSTOFFICE_NAME }}@${{ secrets.DEVELOP_HOST}} " | |
docker load -i /home/fton/backend/challenger.tar; | |
" | |
- name: Run Docker container on server | |
uses: cross-the-world/ssh-scp-ssh-pipelines@latest | |
with: | |
host: ${{ secrets.DEVELOP_HOST}} | |
user: ${{ secrets.POSTOFFICE_NAME }} | |
pass: ${{ secrets.POSTOFFICE_PASS }} | |
port: ${{ secrets.DEVELOP_PORT}} | |
connect_timeout: 120s | |
first_ssh: | | |
docker run -d -p 32468:8080 --name challenger -e SPRING_PROFILES_ACTIVE=dev --network mariadb_mariadb-master-net -v /home/fton/backend/upload:/home/fton/backend/upload challenger:latest; |