mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +01:00
Publish multiarch docker images (#241)
This commit is contained in:
parent
c99d611cb4
commit
52cd75fbc1
2 changed files with 47 additions and 55 deletions
59
.github/workflows/ci.yml
vendored
59
.github/workflows/ci.yml
vendored
|
|
@ -75,13 +75,20 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Check docker environment
|
||||
- name: Configure QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
|
||||
- name: Configure Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
|
||||
- name: Check Docker environment
|
||||
run: |
|
||||
set -x
|
||||
docker version
|
||||
docker buildx version
|
||||
docker-compose version
|
||||
|
||||
- name: Build docker image
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
set -x
|
||||
docker-compose build
|
||||
|
|
@ -103,14 +110,42 @@ jobs:
|
|||
- name: Run make test
|
||||
run: docker-compose run --rm dev make test
|
||||
|
||||
- name: Publish docker image
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
|
||||
env:
|
||||
SRC_IMAGE: dbmate_release
|
||||
DOCKERHUB_IMAGE: ${{ github.repository }}
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
GHCR_IMAGE: ghcr.io/${{ github.repository }}
|
||||
GHCR_USERNAME: ${{ github.actor }}
|
||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: ci/publish-docker.sh
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v1
|
||||
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Generate Docker image tags
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
|
||||
with:
|
||||
images: |
|
||||
${{ github.repository }}
|
||||
ghcr.io/${{ github.repository }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
- name: Publish Docker image
|
||||
uses: docker/build-push-action@v2
|
||||
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
|
||||
with:
|
||||
context: .
|
||||
target: release
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Tag and publish Docker image
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "$DOCKERHUB_TOKEN" | (set -x && docker login --username "$DOCKERHUB_USERNAME" --password-stdin)
|
||||
echo "$GHCR_TOKEN" | (set -x && docker login ghcr.io --username "$GHCR_USERNAME" --password-stdin)
|
||||
|
||||
# Tag and push docker image
|
||||
function docker_push {
|
||||
src=$1
|
||||
dst=$2
|
||||
echo # newline
|
||||
|
||||
(
|
||||
set -x
|
||||
docker tag "$src" "$dst"
|
||||
docker push "$dst"
|
||||
)
|
||||
}
|
||||
|
||||
# Publish image to both Docker Hub and GitHub Container Registry
|
||||
function publish {
|
||||
tag=$1
|
||||
docker_push "$SRC_IMAGE" "$DOCKERHUB_IMAGE:$tag"
|
||||
docker_push "$SRC_IMAGE" "$GHCR_IMAGE:$tag"
|
||||
}
|
||||
|
||||
if [[ "$GITHUB_REF" = refs/tags/v* ]]; then
|
||||
# Publish major/minor/patch/latest version tags
|
||||
ver=${GITHUB_REF#refs/tags/v}
|
||||
|
||||
publish "$ver" # e.g. `1.2.3`
|
||||
publish "${ver%.*}" # e.g. `1.2`
|
||||
publish "${ver%%.*}" # e.g. `1`
|
||||
publish "latest"
|
||||
else
|
||||
# Publish branch
|
||||
publish "${GITHUB_REF##*/}"
|
||||
fi
|
||||
|
||||
# Clear credentials
|
||||
rm -f ~/.docker/config.json
|
||||
Loading…
Add table
Add a link
Reference in a new issue