Skip to content

Commit

Permalink
Docker gen multiarch images
Browse files Browse the repository at this point in the history
  • Loading branch information
rockstardev authored and NicolasDorier committed Dec 13, 2023
1 parent ccceeb6 commit faf124b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ name: Build and publish Docker images

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 1"
push:
branches:
- main
tags:
- "*.*.*"
- "btcpay-*.*.*"
paths:
- ".dockerignore"
- ".github/workflows/build-publish.yml"
- "Dockerfile"
- "Dockerfile.debian"
- "go.mod"
- "go.sum"
- "**.go"
Expand All @@ -23,7 +18,7 @@ jobs:
name: Build and publish image
strategy:
matrix:
base: [alpine, debian]
base: [alpine]
runs-on: ubuntu-latest

steps:
Expand All @@ -34,16 +29,14 @@ jobs:

- name: Retrieve version
id: docker-gen_version
run: echo "VERSION=$(git describe --tags)" >> "$GITHUB_OUTPUT"
run: echo "VERSION=$(git describe --tags | sed 's/btcpay-//')" >> "$GITHUB_OUTPUT"

- name: Get Docker tags
id: docker_meta
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' }}
Expand Down Expand Up @@ -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 }}
Expand Down
10 changes: 10 additions & 0 deletions internal/template/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion internal/template/groupby.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
}
Expand Down
17 changes: 17 additions & 0 deletions internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ioutil.ReadFile(path)

Check failure on line 34 in internal/template/template.go

View workflow job for this annotation

GitHub Actions / assets

undefined: ioutil
if err != nil {
return "", err
}
return string(b), nil
}

func getArrayValues(funcName string, entries interface{}) (*reflect.Value, error) {
entriesVal := reflect.ValueOf(entries)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit faf124b

Please sign in to comment.