buildAndRelease.yml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. name: Release
  2. on:
  3. push:
  4. branches: [ main ]
  5. permissions:
  6. contents: write
  7. issues: write
  8. pull-requests: write
  9. env:
  10. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  11. jobs:
  12. build-and-test:
  13. name: Build and Test
  14. runs-on: ubuntu-latest
  15. services:
  16. mongodb:
  17. image: mongo:7.0
  18. options: >-
  19. --health-cmd "mongosh --quiet --eval 'db.runCommand({ping: 1})'"
  20. --health-interval 10s
  21. --health-timeout 5s
  22. --health-retries 5
  23. ports:
  24. - 27017:27017
  25. env:
  26. mongo: mongodb://localhost:27017
  27. database: knotes-test
  28. steps:
  29. - uses: actions/checkout@v3
  30. - name: Set up JDK
  31. uses: actions/setup-java@v3
  32. with:
  33. java-version: '25'
  34. distribution: 'temurin'
  35. - name: Build with Gradle
  36. run: chmod +x ./gradlew && ./gradlew clean build -x test
  37. dockerize:
  38. name: Dockerize Application
  39. needs: build-and-test
  40. runs-on: ubuntu-latest
  41. steps:
  42. - uses: actions/checkout@v3
  43. - name: Set up JDK
  44. uses: actions/setup-java@v3
  45. with:
  46. java-version: '25'
  47. distribution: 'temurin'
  48. - name: Build
  49. run: chmod +x ./gradlew && ./gradlew build -x test
  50. - name: Set up Docker Buildx
  51. uses: docker/setup-buildx-action@v2
  52. - name: Login to Docker Hub
  53. uses: docker/login-action@v2
  54. with:
  55. username: ${{ secrets.DOCKERHUB_USERNAME }}
  56. password: ${{ secrets.DOCKERHUB_TOKEN }}
  57. - name: Build and Push Image
  58. run: |
  59. docker buildx create --use
  60. docker buildx build --platform linux/amd64,linux/arm64 -t lhamacorp/knotes-be:latest --push .
  61. deploy:
  62. name: Deploy
  63. needs: dockerize
  64. runs-on: ubuntu-latest
  65. steps:
  66. - name: Trigger Portainer Webhook
  67. run: curl --location --request POST '${{ secrets.DEPLOY_WEBHOOK }}'