|
| 1 | +name: Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + image-suffix: |
| 7 | + description: Image name under ghcr.io/<owner>/<repo>/ (e.g. service-alarm-server). |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + context: |
| 11 | + description: Docker build context directory. |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + maven-args: |
| 15 | + description: Maven goals/flags for the package step. |
| 16 | + type: string |
| 17 | + default: --update-snapshots package |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + |
| 23 | +jobs: |
| 24 | + build-and-push-image: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 28 | + with: |
| 29 | + persist-credentials: false |
| 30 | + - name: Set up Java |
| 31 | + uses: ./.github/actions/setup-java |
| 32 | + - name: Build with Maven |
| 33 | + run: mvn --batch-mode $MAVEN_ARGS |
| 34 | + env: |
| 35 | + MAVEN_ARGS: ${{ inputs.maven-args }} |
| 36 | + - name: Login to the registry |
| 37 | + uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee |
| 38 | + with: |
| 39 | + registry: ghcr.io |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + - name: Extract meta-data for Docker |
| 43 | + id: meta |
| 44 | + uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 |
| 45 | + with: |
| 46 | + images: ghcr.io/${{ github.repository }}/${{ inputs.image-suffix }} |
| 47 | + - name: Set up Docker Build |
| 48 | + uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 |
| 49 | + - name: Build and publish the Docker image |
| 50 | + uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf |
| 51 | + with: |
| 52 | + context: ${{ inputs.context }} |
| 53 | + push: true |
| 54 | + platforms: linux/amd64,linux/arm64 |
| 55 | + tags: ${{ steps.meta.outputs.tags }} |
| 56 | + labels: ${{ steps.meta.outputs.labels }} |
| 57 | + cache-from: type=gha |
| 58 | + cache-to: type=gha,mode=max |
0 commit comments