From 77c59bf4571ff743437acba1e866e5497cc8e92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=A0=95=EC=9D=BC?= <105261146+12OneTwo12@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:38:13 +0900 Subject: [PATCH] Create gradle.yml for ci/cd --- .github/workflows/gradle.yml | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/gradle.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..09a792d --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,58 @@ +# 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/CD 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@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Change wrapper permissions + run: chmod +x ./gradlew + + - name: Build with Gradle + run: ./gradlew build + + - name: web docker login + run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + - name: web docker build + run: docker build --platform amd64 --build-arg DEPENDENCY=build/dependency -t ${{secrets.DOCKER_USERNAME}}/my-fit . + - name: web docker tag + run: docker tag ${{secrets.DOCKER_USERNAME}}/my-fit ${{secrets.DOCKER_USERNAME}}/my-fit:latest + - name: web docker push + run: docker push ${{secrets.DOCKER_USERNAME}}/my-fit:latest + + - name: executing remote ssh commands using password + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ubuntu + key: ${{ secrets.KEY }} + port: 22 + script: | + docker stop my-fit + docker rm my-fit + docker pull ${{secrets.DOCKER_USERNAME}}/my-fit:latest + docker run --name my-fit -d -p 8080:8080 -v /etc/localtime:/etc/localtime:ro -e TZ=Asia/Seoul ${{secrets.DOCKER_USERNAME}}/my-fit:latest