|
| 1 | +name: 'Docker Build Action' |
| 2 | +description: 'Builds a Docker image using a specified Dockerfile and context' |
| 3 | + |
| 4 | +inputs: |
| 5 | + context: |
| 6 | + description: 'The Docker build context (path to the directory containing the Dockerfile)' |
| 7 | + required: true |
| 8 | + default: '.' |
| 9 | + dockerfile: |
| 10 | + description: 'The path to the Dockerfile (relative to the context)' |
| 11 | + required: true |
| 12 | + default: 'Dockerfile' |
| 13 | + build-arg-version-name: |
| 14 | + description: 'The name of the build argument' |
| 15 | + required: true |
| 16 | + build-arg-version-value: |
| 17 | + description: 'The value of the build argument' |
| 18 | + required: true |
| 19 | + tag: |
| 20 | + description: 'The tag to use for the image' |
| 21 | + required: true |
| 22 | + image-name: |
| 23 | + description: 'The name of the image to build' |
| 24 | + required: true |
| 25 | + push: |
| 26 | + description: 'Determines if the built image should be pushed' |
| 27 | + required: true |
| 28 | + default: 'no' |
| 29 | + container-registry: |
| 30 | + description: 'container registry address (example: ghcr.io)' |
| 31 | + required: false |
| 32 | + container-registry-username: |
| 33 | + description: 'container registry username' |
| 34 | + required: false |
| 35 | + container-registry-password: |
| 36 | + description: 'container registry password' |
| 37 | + required: false |
| 38 | + |
| 39 | +runs: |
| 40 | + using: 'composite' |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Login to GitHub Container Registry |
| 47 | + uses: docker/login-action@v3 |
| 48 | + if: ${{ inputs.push == 'true' }} |
| 49 | + with: |
| 50 | + logout: false |
| 51 | + registry: ${{ inputs.container-registry }} |
| 52 | + username: ${{ inputs.container-registry-username }} |
| 53 | + password: ${{ inputs.container-registry-password }} |
| 54 | + |
| 55 | + - name: Set up QEMU |
| 56 | + uses: docker/setup-qemu-action@v3 |
| 57 | + |
| 58 | + - name: Set up Docker Buildx |
| 59 | + uses: docker/setup-buildx-action@v3 |
| 60 | + |
| 61 | + - name: Extract metadata (tags, labels) for Docker image |
| 62 | + id: meta |
| 63 | + uses: docker/metadata-action@v5 |
| 64 | + with: |
| 65 | + images: | |
| 66 | + ${{ inputs.container-registry }}/${{ github.repository_owner }}/${{ inputs.image-name }} |
| 67 | + tags: | |
| 68 | + type=raw,enable={{is_default_branch}},value=${{ inputs.tag }}-latest,priority=300 |
| 69 | + type=raw,enable={{is_default_branch}},value=${{ inputs.tag }},priority=200 |
| 70 | +
|
| 71 | + - name: Build image and push (optional) |
| 72 | + uses: docker/build-push-action@v6 |
| 73 | + with: |
| 74 | + platforms: linux/amd64,linux/arm64 |
| 75 | + push: ${{ inputs.push == 'true' }} |
| 76 | + context: ${{ inputs.context }} |
| 77 | + file: ${{ inputs.dockerfile }} |
| 78 | + tags: ${{ steps.meta.outputs.tags }} |
| 79 | + labels: ${{ steps.meta.outputs.labels }} |
| 80 | + build-args: | |
| 81 | + ${{ inputs.build-arg-version-name }}=${{ inputs.build-arg-version-value }} |
0 commit comments