diff --git a/.github/workflows/gradle.yml b/.github/workflows/deploy.dev.yml similarity index 56% rename from .github/workflows/gradle.yml rename to .github/workflows/deploy.dev.yml index 1f650111..76ac93c1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/deploy.dev.yml @@ -4,7 +4,7 @@ # 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 +name: Deploy Backend on Development Server on: workflow_dispatch: @@ -12,13 +12,21 @@ on: permissions: contents: read +env: + HOST: ${{ secrets.HOST }} + USERNAME: ${{ secrets.USERNAME }} + KEY: ${{ secrets.KEY }} + PORT: ${{ secrets.PORT }} + INSTANCE_PATH: ./backend-dev + IMAGE_NAME: shinsion/uspray-server + + jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - name: Set up JDK 11 uses: actions/setup-java@v3 @@ -43,3 +51,27 @@ jobs: - name: Build with Gradle run: ./gradlew clean build + + - name: Dockerhub login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + 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: | + docker stop uspray-server + docker rm uspray-server + docker rmi ${{ env.IMAGE_NAME }}: latest + docker-compose up -d \ No newline at end of file diff --git a/.github/workflows/deploy.dev2.yml b/.github/workflows/deploy.dev2.yml new file mode 100644 index 00000000..76ac93c1 --- /dev/null +++ b/.github/workflows/deploy.dev2.yml @@ -0,0 +1,77 @@ +# 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 Backend on Development Server + +on: + workflow_dispatch: + +permissions: + contents: read + +env: + HOST: ${{ secrets.HOST }} + USERNAME: ${{ secrets.USERNAME }} + KEY: ${{ secrets.KEY }} + PORT: ${{ secrets.PORT }} + INSTANCE_PATH: ./backend-dev + IMAGE_NAME: shinsion/uspray-server + + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - 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 }}" base64 -d > application.yml + + - name: Create service-account-file.json + run: | + mkdir -p ./src/main/resources/firebase + cd ./src/main/resources/firebase + echo "${{ secrets.SERVICE_ACCOUNT_FILE }}" base64 -d > service-account-file.json + + - name: Build with Gradle + run: ./gradlew clean build + + - name: Dockerhub login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + 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: | + docker stop uspray-server + docker rm uspray-server + docker rmi ${{ env.IMAGE_NAME }}: latest + docker-compose up -d \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..fca2d81c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:11-jdk + +WORKDIR /app + +ARG JAR_FILE=build/libs/uspray-0.0.1-SNAPSHOT.jar + +COPY ${JAR_FILE} . + +ENTRYPOINT ["java","-jar","uspray-0.0.1-SNAPSHOT.jar"] \ No newline at end of file