File size: 2,564 Bytes
679ee5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: 'Docker Build Action'
description: 'Build the docker image'
inputs:
  registry:
    required: true
    description: The registry to tag the image with
  image:
    required: true
    description: The image to tag the image with
  version:
    required: true
    description: The image version to tag with
  push:
    required: false
    description: Push the image?
    default: 'false'

outputs:
  tag:
    description: The docker tag of the built image
    value: ${{ steps.build_meta.outputs.tag }}
  version:
    description: The docker version of the built image
    value: ${{ steps.meta.outputs.version }}
  digest:
    description: The docker build digest of the built image
    value: ${{ steps.build_meta.outputs.digest }}

runs:
  using: 'composite'
  steps:
    - name: Context
      id: context
      shell: bash
      run: |
        git_repo_url="${{ github.server_url }}/${{ github.repository }}"

        echo "git_build_url=$git_repo_url/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT
        echo "git_sha=${{ github.sha }}" >> $GITHUB_OUTPUT
        echo "metadata_file=buildx-bake-metadata.json" >> $GITHUB_OUTPUT

        cat $GITHUB_OUTPUT

    - name: Docker meta
      id: meta
      uses: docker/metadata-action@v5
      with:
        bake-target: web
        images: ${{ inputs.registry }}/${{ inputs.image }}
        tags: |
          # use raw tag to allow the calling workflow to define the version of the image
          # and to prevent multiple tags from being associated with a build
          type=raw,value=${{ inputs.version }}

    - name: Build Image
      id: build
      shell: bash
      env:
        DOCKER_TAGS_FILE: ${{ steps.meta.outputs.bake-file-tags }}
        DOCKER_ANNOTATIONS_FILE: ${{ steps.meta.outputs.bake-file-annotations }}
        DOCKER_METADATA_FILE: ${{ steps.context.outputs.metadata_file }}
        DOCKER_PUSH: ${{ inputs.push }}
      run: |
        make setup \
          DOCKER_TARGET="production" \
          DOCKER_VERSION="${{ steps.meta.outputs.version }}"

        make docker_build_web \
          DOCKER_COMMIT="${{ steps.context.outputs.git_sha }}" \
          DOCKER_BUILD="${{ steps.context.outputs.git_build_url }}"

    - name: Get image digest
      id: build_meta
      shell: bash
      run: |
        metadata=$(cat ${{ steps.context.outputs.metadata_file }})
        echo "digest=$(echo $metadata | jq -r '.web."containerimage.digest"')" >> $GITHUB_OUTPUT
        echo "tag=$(echo $metadata | jq -r '.web."image.name"')" >> $GITHUB_OUTPUT
        cat $GITHUB_OUTPUT