|
| 1 | +name: Docker Multi-Arch |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + GLOBAL_FRAMEWORK: |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: maven |
| 10 | + description: Framework used for the build (e.g., maven, node, nodejs, etc.) |
| 11 | + GLOBAL_IMAGE_NAME: |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + GLOBAL_REPO_NAME: |
| 15 | + type: string |
| 16 | + default: docker.io |
| 17 | + IMAGE_TAG: |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + IS_RELEASE: |
| 21 | + required: false |
| 22 | + type: boolean |
| 23 | + default: false |
| 24 | + PATH_TO_DOCKERFILE: |
| 25 | + required: true |
| 26 | + type: string |
| 27 | + RELEASE_TYPE: |
| 28 | + required: false |
| 29 | + type: string |
| 30 | + default: minor |
| 31 | + description: Type of release - Major, Minor, or Patch |
| 32 | + secrets: |
| 33 | + CI_SECRET_READER_PERIODIC_TOKEN: |
| 34 | + required: true |
| 35 | + VAULT_ADDR: |
| 36 | + required: true |
| 37 | + VAULTCA: |
| 38 | + required: true |
| 39 | + |
| 40 | +jobs: |
| 41 | + docker-build: |
| 42 | + name: Docker Build |
| 43 | + runs-on: ${{ matrix.runs-on }} |
| 44 | + |
| 45 | + strategy: |
| 46 | + matrix: |
| 47 | + arch: [amd64, arm64] |
| 48 | + include: |
| 49 | + - arch: amd64 |
| 50 | + runs-on: ubuntu-24.04 |
| 51 | + - arch: arm64 |
| 52 | + runs-on: ubuntu-24.04-arm |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + with: |
| 57 | + persist-credentials: false |
| 58 | + |
| 59 | + - name: Import Secrets |
| 60 | + uses: hashicorp/vault-action@v3 |
| 61 | + with: |
| 62 | + url: ${{ secrets.VAULT_ADDR }} |
| 63 | + token: ${{ secrets.CI_SECRET_READER_PERIODIC_TOKEN }} |
| 64 | + caCertificate: ${{ secrets.VAULTCA }} |
| 65 | + secrets: | |
| 66 | + ci/data/gh-workflows/maven-danubetech-nexus username | MAVEN_USERNAME ; |
| 67 | + ci/data/gh-workflows/maven-danubetech-nexus password | MAVEN_PASSWORD |
| 68 | +
|
| 69 | + - name: Setup Docker Buildx |
| 70 | + uses: docker/setup-buildx-action@v3 |
| 71 | + with: |
| 72 | + install: true |
| 73 | + version: latest |
| 74 | + |
| 75 | + - name: Docker Build and Cache |
| 76 | + uses: docker/build-push-action@v6 |
| 77 | + with: |
| 78 | + context: . |
| 79 | + file: ${{ inputs.PATH_TO_DOCKERFILE }} |
| 80 | + push: false |
| 81 | + build-args: | |
| 82 | + DANUBETECH_MAVEN_INTERNAL_USERNAME=${{ env.MAVEN_USERNAME }} |
| 83 | + DANUBETECH_MAVEN_INTERNAL_PASSWORD=${{ env.MAVEN_PASSWORD }} |
| 84 | + cache-from: type=gha,scope=docker-build-${{ matrix.arch }} |
| 85 | + cache-to: type=gha,scope=docker-build-${{ matrix.arch }},mode=max |
| 86 | + platforms: linux/${{ matrix.arch }} |
| 87 | + |
| 88 | + docker-publish: |
| 89 | + name: Docker Publish |
| 90 | + runs-on: ubuntu-24.04 |
| 91 | + needs: docker-build |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: Checkout |
| 95 | + uses: actions/checkout@v4 |
| 96 | + with: |
| 97 | + persist-credentials: false |
| 98 | + |
| 99 | + - name: Import Secrets |
| 100 | + uses: hashicorp/vault-action@v3 |
| 101 | + with: |
| 102 | + url: ${{ secrets.VAULT_ADDR }} |
| 103 | + token: ${{ secrets.CI_SECRET_READER_PERIODIC_TOKEN }} |
| 104 | + caCertificate: ${{ secrets.VAULTCA }} |
| 105 | + secrets: | |
| 106 | + ci/data/gh-workflows/${{ inputs.GLOBAL_REPO_NAME }} username | DOCKER_USERNAME ; |
| 107 | + ci/data/gh-workflows/${{ inputs.GLOBAL_REPO_NAME }} password | DOCKER_PASSWORD ; |
| 108 | + ci/data/gh-workflows/maven-danubetech-nexus username | MAVEN_USERNAME ; |
| 109 | + ci/data/gh-workflows/maven-danubetech-nexus password | MAVEN_PASSWORD |
| 110 | +
|
| 111 | + - name: Setup Docker Buildx |
| 112 | + uses: docker/setup-buildx-action@v3 |
| 113 | + with: |
| 114 | + install: true |
| 115 | + version: latest |
| 116 | + |
| 117 | + - name: Get version |
| 118 | + if: inputs.IS_RELEASE |
| 119 | + id: get_version |
| 120 | + uses: danubetech/github-action-read-version@main |
| 121 | + with: |
| 122 | + framework: ${{ inputs.GLOBAL_FRAMEWORK }} |
| 123 | + version-core: ${{ inputs.RELEASE_TYPE }} |
| 124 | + |
| 125 | + - name: Docker Metadata |
| 126 | + id: metadata |
| 127 | + uses: docker/metadata-action@v5 |
| 128 | + with: |
| 129 | + images: ${{ inputs.GLOBAL_REPO_NAME }}/${{ inputs.GLOBAL_IMAGE_NAME }} |
| 130 | + tags: | |
| 131 | + type=raw,value=${{ inputs.IMAGE_TAG }},enable=${{ inputs.IMAGE_TAG != '' }} |
| 132 | + type=sha,prefix=${{ steps.get_version.outputs.version }},enable=${{ inputs.IS_RELEASE }} |
| 133 | +
|
| 134 | + - name: Login to Docker Registry |
| 135 | + uses: docker/login-action@v3 |
| 136 | + with: |
| 137 | + registry: ${{ inputs.GLOBAL_REPO_NAME }} |
| 138 | + username: ${{ env.DOCKER_USERNAME }} |
| 139 | + password: ${{ env.DOCKER_PASSWORD }} |
| 140 | + |
| 141 | + - name: Docker Push |
| 142 | + uses: docker/build-push-action@v6 |
| 143 | + with: |
| 144 | + context: . |
| 145 | + file: ${{ inputs.PATH_TO_DOCKERFILE }} |
| 146 | + push: true |
| 147 | + tags: ${{ steps.metadata.outputs.tags }} |
| 148 | + labels: ${{ steps.metadata.outputs.labels }} |
| 149 | + build-args: | |
| 150 | + DANUBETECH_MAVEN_INTERNAL_USERNAME=${{ env.MAVEN_USERNAME }} |
| 151 | + DANUBETECH_MAVEN_INTERNAL_PASSWORD=${{ env.MAVEN_PASSWORD }} |
| 152 | + cache-from: | |
| 153 | + type=gha,scope=docker-build-arm64 |
| 154 | + type=gha,scope=docker-build-amd64 |
| 155 | + platforms: linux/amd64,linux/arm64 |
0 commit comments