From 0f6717adad3ccac2df01ad06cb9fe1effa9845a7 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Sun, 25 Nov 2018 23:37:12 -0600 Subject: [PATCH] Docker gen multiarch images --- .github/workflows/build-publish.yml | 13 +++---------- internal/template/functions.go | 10 ++++++++++ internal/template/groupby.go | 4 +++- internal/template/template.go | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml index eb68cb2..9af34b4 100644 --- a/.github/workflows/build-publish.yml +++ b/.github/workflows/build-publish.yml @@ -2,18 +2,13 @@ name: Build and publish Docker images on: workflow_dispatch: - schedule: - - cron: "0 0 * * 1" push: - branches: - - main tags: - "*.*.*" paths: - ".dockerignore" - ".github/workflows/build-publish.yml" - "Dockerfile" - - "Dockerfile.debian" - "go.mod" - "go.sum" - "**.go" @@ -23,7 +18,7 @@ jobs: name: Build and publish image strategy: matrix: - base: [alpine, debian] + base: [alpine] runs-on: ubuntu-latest steps: @@ -41,9 +36,7 @@ jobs: uses: docker/metadata-action@v4 with: images: | - ghcr.io/nginx-proxy/docker-gen - nginxproxy/docker-gen - jwilder/docker-gen + btcpayserver/docker-gen tags: | type=semver,pattern={{version}},enable=${{ matrix.base == 'alpine' }} type=semver,pattern={{major}}.{{minor}},enable=${{ matrix.base == 'alpine' }} @@ -82,7 +75,7 @@ jobs: with: context: . build-args: DOCKER_GEN_VERSION=${{ steps.docker-gen_version.outputs.VERSION }} - platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + platforms: linux/amd64,linux/arm/v7,linux/arm64 file: Dockerfile.${{ matrix.base }} push: true tags: ${{ steps.docker_meta.outputs.tags }} diff --git a/internal/template/functions.go b/internal/template/functions.go index 88c7003..ddf98a4 100644 --- a/internal/template/functions.go +++ b/internal/template/functions.go @@ -125,6 +125,16 @@ func coalesce(input ...interface{}) interface{} { return nil } +// coalesceempty returns the first non nil argument or empty +func coalesceempty(input ...interface{}) interface{} { + for _, v := range input { + if v != nil && len(fmt.Sprintf("%v", v)) > 0 { + return v + } + } + return nil +} + // trimPrefix returns a string without the prefix, if present func trimPrefix(prefix, s string) string { return strings.TrimPrefix(s, prefix) diff --git a/internal/template/groupby.go b/internal/template/groupby.go index b7063b9..4692379 100644 --- a/internal/template/groupby.go +++ b/internal/template/groupby.go @@ -40,7 +40,9 @@ func groupByMulti(entries interface{}, key, sep string) (map[string][]interface{ return generalizedGroupByKey("groupByMulti", entries, key, func(groups map[string][]interface{}, value interface{}, v interface{}) { items := strings.Split(value.(string), sep) for _, item := range items { - groups[item] = append(groups[item], v) + if item != "" { + groups[item] = append(groups[item], v) + } } }) } diff --git a/internal/template/template.go b/internal/template/template.go index e005d12..fec399f 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -23,6 +23,21 @@ import ( "github.com/nginx-proxy/docker-gen/internal/utils" ) +func read(path string) (string, error) { + _, err := os.Stat(path) + if err != nil { + if os.IsNotExist(err) { + return "", nil + } + return "", err + } + b, err := os.ReadFile(path) + if err != nil { + return "", err + } + return string(b), nil +} + func getArrayValues(funcName string, entries interface{}) (*reflect.Value, error) { entriesVal := reflect.ValueOf(entries) @@ -61,10 +76,12 @@ func newTemplate(name string) *template.Template { tmpl.Funcs(sprig.TxtFuncMap()).Funcs(template.FuncMap{ "closest": arrayClosest, "coalesce": coalesce, + "coalesceempty": coalesceempty, "contains": contains, "dir": dirList, "eval": eval, "exists": utils.PathExists, + "read": read, "groupBy": groupBy, "groupByKeys": groupByKeys, "groupByMulti": groupByMulti,