diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..b7c5873 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,63 @@ +# 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" ] + 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: make application.yml + run: | + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.APPLICATION }}" > ./application.yml + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test + + - name: Docker build + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t app . + docker tag app ${{ secrets.DOCKER_USERNAME }}/samsung:latest + docker push ${{ secrets.DOCKER_USERNAME }}/samsung:latest + + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ec2-user + key: ${{ secrets.PRIVATE_KEY }} + script: | + docker pull ${{ secrets.DOCKER_USERNAME }}/hackathon:latest + docker stop $(docker ps -a -q) + docker run -d --log-driver=syslog -p 8080:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.DOCKER_USERNAME }}/hackathon:latest + docker rm $(docker ps --filter 'status=exited' -a -q) + docker image prune -a -f +