Build x86-64 and arm and push a multi-architecture image

Signed-off-by: Slava <20563034+veaceslavdoina@users.noreply.github.com>
This commit is contained in:
Slava 2023-05-11 20:44:38 +03:00 committed by GitHub
parent c777387556
commit 2a14cea7d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 108 additions and 34 deletions

View File

@ -1,125 +1,199 @@
name: docker name: Docker
on: on:
push: push:
branches: branches:
- "main" - main
tags: tags:
- "v*.*.*" - "v*.*.*"
workflow_dispatch: workflow_dispatch:
env:
DOCKER_FILE: docker/codex.Dockerfile
DOCKER_REPO: codexstorage/nim-codex
jobs: jobs:
docker-amd64: # Linux amd64
linux-amd64:
name: Linux amd64
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
tags: ${{ steps.tags.outputs.tags }}
env:
PLATFORM: linux/amd64
SUFFIX: linux-amd64
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Docker meta - name: Docker - Meta
id: meta id: meta
uses: docker/metadata-action@v4 uses: docker/metadata-action@v4
with: with:
images: thatbenbierens/nim-codex-amd64 images: ${{ env.DOCKER_REPO }}
flavor: |
latest=false
tags: | tags: |
type=semver,pattern={{version}} type=semver,pattern={{version}},suffix=-${{ env.SUFFIX }}
type=sha type=sha,suffix=-${{ env.SUFFIX }},enable=${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Login to Docker Hub - name: Docker - Set tags output
if: github.event_name != 'pull_request'
id: tags
run: echo "tags=${{ steps.meta.outputs.tags }}" >> "$GITHUB_OUTPUT"
- name: Docker - Login to Docker Hub
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and export to Docker - name: Docker - Build and export to Docker
id: build id: build
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
file: docker/codex.Dockerfile file: ${{ env.DOCKER_FILE }}
platforms: linux/amd64 platforms: ${{ env.PLATFORM }}
load: true load: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
- name: Minify docker image - name: Docker - Minify image
uses: kitabisa/docker-slim-action@v1 uses: kitabisa/docker-slim-action@v1
id: slim
env: env:
DSLIM_HTTP_PROBE: false DSLIM_HTTP_PROBE: false
with: with:
target: ${{ steps.meta.outputs.tags }} target: ${{ steps.meta.outputs.tags }}
overwrite: true overwrite: true
- name: Show slim report - name: Docker - Show slim report
run: echo "${{ steps.slim.outputs.report }}" run: echo "${REPORT}" | jq -r
env:
REPORT: ${{ steps.slim.outputs.report }}
- name: Push to Docker registry - name: Docker - Push to Docker registry
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
id: push id: push
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
file: docker/codex.Dockerfile file: ${{ env.DOCKER_FILE }}
platforms: linux/amd64 platforms: ${{ env.PLATFORM }}
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
docker-arm64: # Linux arm64
linux-arm64:
name: Linux arm64
runs-on: buildjet-4vcpu-ubuntu-2204-arm runs-on: buildjet-4vcpu-ubuntu-2204-arm
outputs:
tags: ${{ steps.tags.outputs.tags }}
env:
PLATFORM: linux/arm64
SUFFIX: linux-arm64
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Docker meta - name: Docker - Meta
id: meta id: meta
uses: docker/metadata-action@v4 uses: docker/metadata-action@v4
with: with:
images: thatbenbierens/nim-codex-arm64 images: ${{ env.DOCKER_REPO }}
flavor: |
latest=false
tags: | tags: |
type=semver,pattern={{version}} type=semver,pattern={{version}},suffix=-${{ env.SUFFIX }}
type=sha type=sha,suffix=-${{ env.SUFFIX }},enable=${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Set up Docker Buildx - name: Docker - Set tags output
uses: docker/setup-buildx-action@v2 if: github.event_name != 'pull_request'
id: tags
run: echo "tags=${{ steps.meta.outputs.tags }}" >> "$GITHUB_OUTPUT"
- name: Login to Docker Hub - name: Docker - Login to Docker Hub
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and export to Docker - name: Docker - Build and export to Docker
id: build id: build
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
file: docker/codex.Dockerfile file: ${{ env.DOCKER_FILE }}
platforms: linux/arm64 platforms: ${{ env.PLATFORM }}
load: true load: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
- name: Minify docker image - name: Docker - Minify image
uses: kitabisa/docker-slim-action@v1 uses: kitabisa/docker-slim-action@v1
id: slim
env: env:
DSLIM_HTTP_PROBE: false DSLIM_HTTP_PROBE: false
with: with:
target: ${{ steps.meta.outputs.tags }} target: ${{ steps.meta.outputs.tags }}
overwrite: true overwrite: true
- name: Show slim report - name: Docker - Show slim report
run: echo "${{ steps.slim.outputs.report }}" run: echo "${REPORT}" | jq -r
env:
REPORT: ${{ steps.slim.outputs.report }}
- name: Push to Docker registry - name: Docker - Push to Docker registry
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
id: push id: push
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: . context: .
file: docker/codex.Dockerfile file: ${{ env.DOCKER_FILE }}
platforms: linux/arm64 platforms: ${{ env.PLATFORM }}
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
# Push single image
publish:
name: Push single image
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [linux-amd64, linux-arm64]
steps:
- name: Docker - Meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_REPO }}
tags: |
type=semver,pattern={{version}}
type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Docker - Set tags
run: |
# Transform multi-line tags in to the comma-seperated
TAGS=$(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ',' | awk '{gsub(/,$/,"");}1')
echo "TAGS=${TAGS}" >>$GITHUB_ENV
echo "${TAGS}"
- name: Docker - Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker - Create and push manifest images
uses: Noelware/docker-manifest-action@master
with:
inputs: ${{ env.TAGS }}
images: ${{ needs.linux-amd64.outputs.tags }},${{ needs.linux-arm64.outputs.tags }}
push: true