docker-image.yml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. name: DockerHub - Build & Push
  2. on:
  3. push:
  4. tags:
  5. - v*
  6. jobs:
  7. build:
  8. runs-on: ubuntu-22.04
  9. steps:
  10. - uses: actions/checkout@v4
  11. - name: Set up JDK 17
  12. uses: actions/setup-java@v4
  13. with:
  14. java-version: '17'
  15. distribution: 'temurin'
  16. cache: maven
  17. - name: Cache local Maven repository
  18. uses: actions/cache@v3
  19. with:
  20. path: ~/.m2/repository
  21. key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
  22. restore-keys: |
  23. ${{ runner.os }}-maven-
  24. - name: Build with Maven
  25. run: mvn -B package --file pom.xml -Dmaven.test.skip=true
  26. - name: Get Maven project version
  27. id: version
  28. run: |
  29. echo "VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_OUTPUT"
  30. - name: Set up Docker Buildx
  31. uses: docker/setup-buildx-action@v3
  32. - name: Login to Docker Hub
  33. uses: docker/login-action@v3
  34. with:
  35. username: ${{ secrets.DOCKER_USERNAME }}
  36. password: ${{ secrets.DOCKER_PASSWORD }}
  37. - name: Build and push Docker image
  38. uses: docker/build-push-action@v5
  39. env:
  40. DOCKER_NAMESPACE: ${{ secrets.DOCKER_NAMESPACE }}
  41. VERSION: ${{ steps.version.outputs.version }}
  42. with:
  43. context: snail-job-server-starter/
  44. platforms: linux/amd64,linux/arm64
  45. push: true
  46. tags: |
  47. ${{ env.DOCKER_NAMESPACE }}/snail-job:latest
  48. ${{ env.DOCKER_NAMESPACE }}/snail-job:${{ env.VERSION }}