mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-13 00:20:04 +01:00
Publish Docker image (#220)
This commit is contained in:
parent
7c6f9ed747
commit
4a3698c7ac
4 changed files with 62 additions and 2 deletions
45
.github/workflows/publish-docker.sh
vendored
Executable file
45
.github/workflows/publish-docker.sh
vendored
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/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"
|
||||
}
|
||||
|
||||
# Publish current branch/tag (e.g. `main` or `v1.2.3`)
|
||||
ver=${GITHUB_REF##*/}
|
||||
publish "$ver"
|
||||
|
||||
# Publish major/minor/latest for version tags
|
||||
if [[ "$GITHUB_REF" = refs/tags/v* ]]; then
|
||||
major_ver=${ver%%.*} # e.g. `v1`
|
||||
publish "$major_ver"
|
||||
|
||||
minor_ver=${ver%.*} # e.g. `v1.2`
|
||||
publish "$minor_ver"
|
||||
|
||||
publish "latest"
|
||||
fi
|
||||
|
||||
# Clear credentials
|
||||
rm -f ~/.docker/config.json
|
||||
Loading…
Add table
Add a link
Reference in a new issue