Maybe smart image tags?

This commit is contained in:
Neale Pickett 2020-09-18 15:38:33 -06:00
parent cf34a1a3be
commit 34e806df96
2 changed files with 30 additions and 19 deletions

View File

@ -32,23 +32,11 @@ jobs:
- name: Retrieve code
uses: actions/checkout@v2
- name: Get current branch
- name: Gitlab variables
id: vars
run: |
echo "GITHUB_REF: $GITHUB_REF"
case $GITHUB_REF in
refs/tags/*)
TAGS=latest,${GITHUB_REF#refs/tags/}
;;
refs/heads/master)
TAGS=latest
;;
esac
echo "tags: $TAGS"
echo "::set-output name=tags::$TAGS"
run: build/ci/gitlab-vars
- name: Login to GitHub Packages Docker Registry
if: steps.vars.tags != ''
uses: docker/login-action@v1
with:
registry: docker.pkg.github.com
@ -56,7 +44,6 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
if: steps.vars.tags != ''
uses: docker/login-action@v1
with:
username: neale
@ -67,15 +54,14 @@ jobs:
with:
target: moth
file: build/package/Containerfile
tags: |
dirtbags/moth:latest
docker.pkg.github.com/dirtbags/moth/moth:latest
push: ${{ steps.vars.outputs.tags != '' }}
tags: ${{ steps.vars.outputs.moth-tags }}
- name: Build and push moth-devel image
uses: docker/build-push-action@v2
with:
target: moth
file: build/package/Containerfile
tags: |
tags: ${{ steps.vars.outputs.devel-tags }}
dirtbags/moth-devel:latest
docker.pkg.github.com/dirtbags/moth/moth-devel:latest

25
build/ci/gitlab-vars Executable file
View File

@ -0,0 +1,25 @@
#! /bin/sh
case $1 in
-h|-help|--help)
echo "Usage: $0 TARGET"
echo
echo "Sets CI build variables for gitlab"
exit 1
;;
esac
branch=$(git symbolic-ref -q --short HEAD)
if [ "$branch" = "main" ]; then
branch=latest
fi
printf "Branch: %s\n" "$branch"
printf "::set-output name=branch::%s\n" "$branch"
printf "::set-output name=tag::%s\n" "$branch"
# I think it will use whichever comes last
git tag --points-at HEAD | while read tag; do
printf "Tag: %s\n" "$tag"
printf "::set-output name=tag::%s\n" "$tag"
done