Merge pull request #152 from DonggeonMoon/dev #176
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" ] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
token: ${{ secrets.ACTIONS_TOKEN }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. | |
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | |
- name: Build with Gradle Wrapper | |
run: ./gradlew bootJar | |
- name: Verify local file exists | |
run: ls -la ./build/libs/PSYThinktank-0.0.1.jar && echo $BASE_DIR && echo $DEPLOY_DIR | |
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html). | |
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version. | |
# | |
# - name: Setup Gradle | |
# uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | |
# with: | |
# gradle-version: '8.5' | |
# | |
# - name: Build with Gradle 8.5 | |
# run: gradle build | |
- name: Build Docker Image | |
run: | | |
docker build -t psythinktank:latest . | |
docker save my-app:latest -o psythinktank.tar | |
- name: Upload JAR file using SCP | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.EC2_PUBLIC_IP }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
source: "./psythinktank.tar" | |
target: ${{ secrets.BASE_DIR }}${{ secrets.DEPLOY_DIR }} | |
strip_components: 3 | |
- name: Deploy on Remote Server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
docker load -i /home/${{ secrets.SERVER_USERNAME }}/psythinktank.tar | |
- name: Restart Docker on EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_PUBLIC_IP }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
script: | | |
sudo docker restart java |