|
| 1 | +--- |
| 2 | +name: Build Product Image |
| 3 | +description: This action builds a product Docker image with a specific version |
| 4 | +inputs: |
| 5 | + image-name: |
| 6 | + description: | |
| 7 | + The local name of the built image, for example: `kafka` or |
| 8 | + `csi-provisioner` |
| 9 | + required: true |
| 10 | + image-index-manifest-tag: |
| 11 | + description: | |
| 12 | + Human-readable tag (usually the version) without architecture information, |
| 13 | + for example: `3.4.1-stackable0.0.0-dev` |
| 14 | + container-file: |
| 15 | + description: Path to Containerfile (or Dockefile) |
| 16 | + default: Dockerfile |
| 17 | + build-context: |
| 18 | + description: Path to the build-context |
| 19 | + default: . |
| 20 | + # TODO (@NickLarsenNZ): Allow optional buildx cache |
| 21 | + # build-cache-username: |
| 22 | + # description: Build cache username |
| 23 | + # default: github |
| 24 | + # build-cache-password: |
| 25 | + # description: Build cache password |
| 26 | + # required: true |
| 27 | +outputs: |
| 28 | + image-manifest-tag: |
| 29 | + description: | |
| 30 | + Human-readable tag (usually the version) with architecture information, |
| 31 | + for example: `3.4.1-stackable0.0.0-dev-amd64` |
| 32 | + value: ${{ steps.build-image.outputs.IMAGE_MANIFEST_TAG }} |
| 33 | +runs: |
| 34 | + using: composite |
| 35 | + steps: |
| 36 | + - name: Free Disk Space (Ubuntu) |
| 37 | + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 |
| 38 | + with: |
| 39 | + # This might remove tools that are actually needed, if set to "true" but |
| 40 | + # frees about 6 GB. |
| 41 | + tool-cache: false |
| 42 | + |
| 43 | + # All of these default to true, but feel free to set to "false" if |
| 44 | + # necessary for your workflow. |
| 45 | + android: true |
| 46 | + dotnet: true |
| 47 | + haskell: true |
| 48 | + large-packages: true |
| 49 | + docker-images: true |
| 50 | + swap-storage: true |
| 51 | + |
| 52 | + - name: Setup Docker Buildx |
| 53 | + uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 |
| 54 | + |
| 55 | + # TODO (@NickLarsenNZ): Allow optional buildx cache |
| 56 | + # # Needed if you pass the --cache argument to the bake command below |
| 57 | + # - name: Login to the docker build cache registry |
| 58 | + # uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 59 | + # with: |
| 60 | + # registry: build-repo.stackable.tech:8083 |
| 61 | + # username: ${{ inputs.build-cache-username }} |
| 62 | + # password: ${{ inputs.build-cache-password }} |
| 63 | + |
| 64 | + - name: Build ${{ inputs.image-name }}:${{ inputs.image-index-manifest-tag }} |
| 65 | + id: build-image |
| 66 | + env: |
| 67 | + IMAGE_NAME: ${{ inputs.image-name }} |
| 68 | + IMAGE_INDEX_MANIFEST_TAG: ${{ inputs.image-index-manifest-tag }} |
| 69 | + CONTAINER_FILE: ${{ inputs.container-file }} |
| 70 | + BUILD_CONTEXT: ${{ inputs.build-context }} |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | +
|
| 75 | + IMAGE_ARCH="$(uname -m | sed -e 's#x86_64#amd64#' | sed -e 's#aarch64#arm64#')" |
| 76 | + echo "IMAGE_ARCH=${IMAGE_ARCH}" | tee -a "$GITHUB_ENV" |
| 77 | +
|
| 78 | + IMAGE_MANIFEST_TAG="${IMAGE_INDEX_MANIFEST_TAG}-${IMAGE_ARCH}" |
| 79 | + echo "IMAGE_MANIFEST_TAG=${IMAGE_MANIFEST_TAG}" | tee -a $GITHUB_OUTPUT |
| 80 | +
|
| 81 | + docker buildx build \ |
| 82 | + --file "${CONTAINER_FILE}" \ |
| 83 | + --platform "linux/${IMAGE_ARCH}" \ |
| 84 | + --tag "localhost/${IMAGE_NAME}:${IMAGE_MANIFEST_TAG}" \ |
| 85 | + # TODO (@NickLarsenNZ): Allow optional buildx cache |
| 86 | + # --cache-to ... \ |
| 87 | + # --cache-from ... \ |
| 88 | + "${BUILD_CONTEXT}" |
0 commit comments