|
| 1 | +--- |
| 2 | +name: "Push multistage docker images (multi -flavours, -versions, -architectures)" |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + ### |
| 7 | + ### Variables |
| 8 | + ### |
| 9 | + inputs: |
| 10 | + can_deploy: |
| 11 | + description: 'Determines wheather this workflow will also deploy (login and push).' |
| 12 | + required: true |
| 13 | + type: boolean |
| 14 | + matrix: |
| 15 | + description: 'The build matrix' |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + has_refs: |
| 19 | + description: 'The ref build matrix as JSON string (list of git refs to build/deploy).' |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + artifact_prefix: |
| 23 | + description: 'Unique artifact name prefix (to avoid overriding existing artifcats during parallel runs).' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + flavour: |
| 27 | + description: 'The flavour to build (Examples: base, mods, prod or work).' |
| 28 | + required: true |
| 29 | + type: string |
| 30 | + ### |
| 31 | + ### Secrets |
| 32 | + ### |
| 33 | + secrets: |
| 34 | + dockerhub_username: |
| 35 | + description: 'The username for Dockerhub.' |
| 36 | + required: true |
| 37 | + dockerhub_password: |
| 38 | + description: 'The password for Dockerhub.' |
| 39 | + required: true |
| 40 | + |
| 41 | +jobs: |
| 42 | + # ----------------------------------------------------------------------------------------------- |
| 43 | + # JOB: DEPLOY |
| 44 | + # ----------------------------------------------------------------------------------------------- |
| 45 | + test: |
| 46 | + name: ${{ matrix.name }}-${{ matrix.version }}-${{ inputs.flavour }} (${{ matrix.arch }}) ${{ matrix.refs }} |
| 47 | + runs-on: ubuntu-latest |
| 48 | + strategy: |
| 49 | + fail-fast: false |
| 50 | + matrix: |
| 51 | + include: ${{ fromJson(inputs.matrix) }} |
| 52 | + steps: |
| 53 | + |
| 54 | + # ------------------------------------------------------------ |
| 55 | + # Setup repository |
| 56 | + # ------------------------------------------------------------ |
| 57 | + - name: "[SETUP] Checkout repository (current)" |
| 58 | + uses: actions/checkout@v3 |
| 59 | + with: |
| 60 | + fetch-depth: 0 |
| 61 | + if: inputs.has_refs == 0 |
| 62 | + |
| 63 | + - name: "[SETUP] Checkout repository (ref: ${{ matrix.refs }})" |
| 64 | + uses: actions/checkout@v3 |
| 65 | + with: |
| 66 | + fetch-depth: 0 |
| 67 | + ref: ${{ matrix.refs }} |
| 68 | + if: inputs.has_refs != 0 |
| 69 | + |
| 70 | + - name: "[SETUP] Setup QEMU environment" |
| 71 | + uses: docker/setup-qemu-action@v1 |
| 72 | + with: |
| 73 | + image: tonistiigi/binfmt:latest |
| 74 | + platforms: all |
| 75 | + |
| 76 | + - name: "[SETUP] Determine Docker tag" |
| 77 | + id: tag |
| 78 | + |
| 79 | + |
| 80 | + - name: "[SETUP] Set artifact names" |
| 81 | + id: set-artifact-name |
| 82 | + run: | |
| 83 | + PRE_HASH="$( git rev-parse HEAD | head -c 10 )" |
| 84 | + VERSION="${{ matrix.version }}" |
| 85 | + ARCH="$( echo "${{ matrix.arch }}" | sed 's|/|-|g' )" |
| 86 | +
|
| 87 | + NAME_CURR="${{ inputs.artifact_prefix }}-${PRE_HASH}-${VERSION}-${ARCH}-${{ inputs.flavour }}" |
| 88 | + echo "::set-output name=curr::${NAME_CURR}" |
| 89 | +
|
| 90 | +
|
| 91 | + # ------------------------------------------------------------ |
| 92 | + # Artifact Import |
| 93 | + # ------------------------------------------------------------ |
| 94 | + |
| 95 | + ### |
| 96 | + ### Download and import previously built image |
| 97 | + ### |
| 98 | + - name: "[Artifact Load] Download previously built image" |
| 99 | + |
| 100 | + with: |
| 101 | + action: actions/download-artifact@v3 |
| 102 | + with: | |
| 103 | + name: ${{ steps.set-artifact-name.outputs.curr }} |
| 104 | + attempt_limit: 20 |
| 105 | + attempt_delay: 10000 |
| 106 | + |
| 107 | + - name: "[Artifact Load] Import previously built image" |
| 108 | + |
| 109 | + with: |
| 110 | + command: | |
| 111 | + make load INFILE=${{ steps.set-artifact-name.outputs.curr }} |
| 112 | +
|
| 113 | +
|
| 114 | + # ------------------------------------------------------------ |
| 115 | + # Re-tag images |
| 116 | + # ------------------------------------------------------------ |
| 117 | + - name: "[Docker Tag] Retag" |
| 118 | + |
| 119 | + with: |
| 120 | + command: | |
| 121 | + make tag VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} TAG=${{ steps.tag.outputs.docker-tag }} |
| 122 | +
|
| 123 | + - name: "[Docker Tag] Show images" |
| 124 | + run: | |
| 125 | + docker images |
| 126 | +
|
| 127 | +
|
| 128 | + # ------------------------------------------------------------ |
| 129 | + # Login |
| 130 | + # ------------------------------------------------------------ |
| 131 | + - name: Login |
| 132 | + uses: docker/login-action@v1 |
| 133 | + with: |
| 134 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 135 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 136 | + if: ${{ inputs.can_deploy }} |
| 137 | + |
| 138 | + |
| 139 | + # ------------------------------------------------------------ |
| 140 | + # Push images |
| 141 | + # ------------------------------------------------------------ |
| 142 | + - name: Push Image |
| 143 | + |
| 144 | + with: |
| 145 | + command: | |
| 146 | + make push VERSION=${{ matrix.version }} FLAVOUR=${{ inputs.flavour }} TAG=${{ steps.tag.outputs.docker-tag }} |
| 147 | + if: ${{ inputs.can_deploy }} |
0 commit comments