|
| 1 | +# This workflow uses actions that are not certified by GitHub. |
| 2 | +# They are provided by a third-party and are governed by |
| 3 | +# separate terms of service, privacy policy, and support |
| 4 | +# documentation. |
| 5 | +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time |
| 6 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle |
| 7 | + |
| 8 | +name: CICD |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + branches: [ "main" ] |
| 13 | + pull_request: |
| 14 | + branches: [ "main" ] |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - name: Set up JDK 17 |
| 26 | + uses: actions/setup-java@v4 |
| 27 | + with: |
| 28 | + java-version: '17' |
| 29 | + distribution: 'temurin' |
| 30 | + |
| 31 | + - name: Setup Gradle |
| 32 | + uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 |
| 33 | + |
| 34 | + - name: Grant execute permission for gradlew |
| 35 | + run: chmod +x gradlew |
| 36 | + |
| 37 | + - name: Build with Gradle Wrapper |
| 38 | + run: ./gradlew build -x test |
| 39 | + |
| 40 | + - name: Login to DockerHub |
| 41 | + uses: docker/login-action@v2 |
| 42 | + with: |
| 43 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 44 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Build Docker |
| 47 | + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/studylog_server . |
| 48 | + - name: Push Docker |
| 49 | + run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/studylog_server:latest |
| 50 | + |
| 51 | + dependency-submission: |
| 52 | + |
| 53 | + runs-on: ubuntu-latest |
| 54 | + permissions: |
| 55 | + contents: write |
| 56 | + |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + - name: Set up JDK 17 |
| 60 | + uses: actions/setup-java@v4 |
| 61 | + with: |
| 62 | + java-version: '17' |
| 63 | + distribution: 'temurin' |
| 64 | + |
| 65 | + - name: Generate and submit dependency graph |
| 66 | + uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 |
| 67 | + |
| 68 | + deploy: |
| 69 | + needs: build |
| 70 | + runs-on: ubuntu-latest |
| 71 | + |
| 72 | + steps: |
| 73 | + - name: Docker compose |
| 74 | + uses: appleboy/ssh-action@v0.1.6 |
| 75 | + with: |
| 76 | + username: ubuntu |
| 77 | + host: ${{ secrets.EC2_HOST }} |
| 78 | + key: ${{ secrets.EC2_SSH_KEY }} |
| 79 | + port: 22 |
| 80 | + timeout: 60s |
| 81 | + script: | |
| 82 | + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/studylog_server:latest |
| 83 | + sudo docker compose -f /home/ubuntu/project/compose.yml up -d |
0 commit comments