-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
98 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Docker Images Multi-Platform | ||
name: Build and Publish Docker Images Demo | ||
|
||
on: | ||
push: | ||
|
@@ -10,113 +10,111 @@ permissions: | |
contents: read | ||
packages: write | ||
|
||
env: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | ||
ACR_USERNAME: ${{ secrets.ACR_USERNAME }} | ||
ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }} | ||
|
||
jobs: | ||
build: | ||
|
||
xpert-api: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
service: | ||
- { name: "xpert-api", context: ".deploy/api", image_name: "metadc/xpert-api-demo" } | ||
# - { name: "xpert-webapp", context: ".deploy/webapp", image_name: "xpert-webapp-demo" } | ||
platform: [ "linux/amd64", "linux/arm64" ] | ||
environment: production | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ env.DOCKERHUB_USERNAME }} | ||
password: ${{ env.DOCKERHUB_TOKEN }} | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Extract metadata for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ matrix.service.image_name }} | ||
- name: Build and Push Docker Images | ||
uses: docker/build-push-action@v6 | ||
with: | ||
- uses: actions/checkout@v4 | ||
- name: Build | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
file: ${{ matrix.service.context }}/Dockerfile | ||
platforms: ${{ matrix.platform }} | ||
build-args: COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} | ||
file: ./.deploy/api/Dockerfile | ||
load: true | ||
platforms: linux/amd64 | ||
tags: | | ||
${{ matrix.service.image_name }}:latest | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=image,name=${{ matrix.service.image_name }},push-by-digest=true,name-canonical=true,push=true | ||
ghcr.io/xpert-ai/xpert-api-demo:latest | ||
metadc/xpert-api-demo:latest | ||
registry.cn-hangzhou.aliyuncs.com/metad/xpert-api-demo:latest | ||
cache-from: type=registry,ref=metadc/xpert-api-demo:latest | ||
cache-to: type=inline | ||
- name: Docker images list | ||
run: | | ||
sudo docker image list | ||
- name: Login to DockerHub | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Push to Docker Hub Registry | ||
run: | | ||
docker push metadc/xpert-api-demo:latest | ||
- name: Login to GitHub Container Registry | ||
uses: docker/[email protected] | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Push to Github Registry | ||
run: | | ||
docker push ghcr.io/xpert-ai/xpert-api-demo:latest | ||
- uses: aliyun/acr-login@v1 | ||
with: | ||
login-server: https://registry.cn-hangzhou.aliyuncs.com | ||
username: "${{ secrets.ACR_USERNAME }}" | ||
password: "${{ secrets.ACR_PASSWORD }}" | ||
|
||
- name: Push to Aliyun Registry | ||
run: | | ||
docker push registry.cn-hangzhou.aliyuncs.com/metad/xpert-api-demo:latest | ||
xpert-webapp: | ||
|
||
- name: Export digest | ||
run: | | ||
mkdir -p /tmp/digests | ||
digest="${{ steps.build.outputs.digest }}" | ||
touch "/tmp/digests/${digest#sha256:}" | ||
- name: Upload digest | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: digests-${{ matrix.service.name }}-${{ matrix.platform }} | ||
path: /tmp/digests/* | ||
if-no-files-found: error | ||
retention-days: 1 | ||
|
||
create-manifest: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
service: | ||
- { name: "xpert-api", image_name: "xpert-api-demo" } | ||
# - { name: "xpert-webapp", image_name: "xpert-webapp-demo" } | ||
environment: production | ||
|
||
steps: | ||
- name: Download digests | ||
uses: actions/download-artifact@v4 | ||
with: | ||
path: /tmp/digests | ||
pattern: digests-${{ matrix.service.name }}-* | ||
merge-multiple: true | ||
|
||
- name: Login to DockerHub | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ env.DOCKERHUB_USERNAME }} | ||
password: ${{ env.DOCKERHUB_TOKEN }} | ||
|
||
- name: Extract metadata for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: metadc/${{ matrix.service.image_name }} | ||
- uses: actions/checkout@v4 | ||
- name: Build | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
file: ./.deploy/webapp/Dockerfile | ||
load: true | ||
platforms: linux/amd64 | ||
tags: | | ||
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-') }} | ||
type=ref,event=branch | ||
type=sha,enable=true,priority=100,prefix=,suffix=,format=long | ||
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }} | ||
- name: Create manifest list and push | ||
working-directory: /tmp/digests | ||
run: | | ||
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | ||
$(printf 'metadc/${{ matrix.service.image_name }}@sha256:%s ' *) | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect metadc/${{ matrix.service.image_name }}:${{ steps.meta.outputs.version }} | ||
ghcr.io/xpert-ai/xpert-webapp-demo:latest | ||
metadc/xpert-webapp-demo:latest | ||
registry.cn-hangzhou.aliyuncs.com/metad/xpert-webapp-demo:latest | ||
cache-from: type=registry,ref=metadc/xpert-webapp-demo:latest | ||
cache-to: type=inline | ||
- name: Docker images list | ||
run: | | ||
sudo docker image list | ||
- name: Login to DockerHub | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Push to Docker Hub Registry | ||
run: | | ||
docker push metadc/xpert-webapp-demo:latest | ||
- name: Login to GitHub Container Registry | ||
uses: docker/[email protected] | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Push to Github Registry | ||
run: | | ||
docker push ghcr.io/xpert-ai/xpert-webapp-demo:latest | ||
- uses: aliyun/acr-login@v1 | ||
with: | ||
login-server: https://registry.cn-hangzhou.aliyuncs.com | ||
username: "${{ secrets.ACR_USERNAME }}" | ||
password: "${{ secrets.ACR_PASSWORD }}" | ||
|
||
- name: Push to Aliyun Registry | ||
run: | | ||
docker push registry.cn-hangzhou.aliyuncs.com/metad/xpert-webapp-demo:latest |