mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50: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
|
|
@ -9,8 +9,9 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build & Test
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
@ -54,7 +55,19 @@ jobs:
|
||||||
docker-compose run --rm dev make wait
|
docker-compose run --rm dev make wait
|
||||||
docker-compose run --rm dev make test
|
docker-compose run --rm dev make test
|
||||||
|
|
||||||
- name: Release
|
- name: Publish docker image
|
||||||
|
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: .github/workflows/publish-docker.sh
|
||||||
|
|
||||||
|
- name: Publish release binaries
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
|
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
|
||||||
with:
|
with:
|
||||||
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
|
||||||
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -5,5 +5,6 @@
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
"files.insertFinalNewline": true,
|
"files.insertFinalNewline": true,
|
||||||
"files.trimFinalNewlines": true,
|
"files.trimFinalNewlines": true,
|
||||||
|
"files.trimTrailingWhitespace": true,
|
||||||
"go.formatTool": "goimports"
|
"go.formatTool": "goimports"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ services:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: release
|
target: release
|
||||||
|
image: dbmate_release
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
image: mysql:5.7
|
image: mysql:5.7
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue