Skip to content

Commit

Permalink
Add REGISTRY_PREFIX build variable
Browse files Browse the repository at this point in the history
  • Loading branch information
prodrigestivill committed Mar 4, 2022
1 parent 3a005cf commit e558018
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 71 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ jobs:

- name: Build images
env:
BUILDREV: ${{ steps.vars.outputs.sha_short }}
REGISTRY_PREFIX: ${{ secrets.DOCKERHUB_USERNAME }}/
BUILD_REVISION: ${{ steps.vars.outputs.sha_short }}
run: docker buildx bake --pull

- name: Push images
env:
BUILDREV: ${{ steps.vars.outputs.sha_short }}
REGISTRY_PREFIX: ${{ secrets.DOCKERHUB_USERNAME }}/
BUILD_REVISION: ${{ steps.vars.outputs.sha_short }}
run: docker buildx bake --push
8 changes: 4 additions & 4 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docker buildx inspect --bootstrap
In order to modify the image name or any other configurable parameter run the `generate.sh` script.

```sh
IMAGE_NAME="prodrigestivill/postgres-backup-local" ./generate.sh config.hcl
IMAGE_NAME="postgres-backup-local" ./generate.sh config.hcl
```

### Build the images
Expand All @@ -39,11 +39,11 @@ docker buildx bake --pull -f config.hcl
In order to publish directly to the repository run this command instead:

```sh
docker buildx bake --pull --push -f config.hcl
REGISTRY_PREFIX="dockerhub_username/" docker buildx bake --pull --push -f config.hcl
```

Also, optionally, it can also generate build revision tags from last git commit (like `./publish.sh` script does):
Also, optionally, it can also generate build revision tags from last git commit:

```sh
BUILDREV=$(git rev-parse --short HEAD) docker buildx bake --pull --push -f config.hcl
REGISTRY_PREFIX="dockerhub_username/" BUILD_REVISION=$(git rev-parse --short HEAD) docker buildx bake --pull --push -f config.hcl
```
50 changes: 27 additions & 23 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ group "default" {
targets = ["debian-latest", "alpine-latest", "debian-13", "debian-12", "debian-11", "debian-10", "alpine-13", "alpine-12", "alpine-11", "alpine-10"]
}

variable "BUILDREV" {
variable "REGISTRY_PREFIX" {
default = ""
}

variable "BUILD_REVISION" {
default = ""
}

Expand All @@ -21,9 +25,9 @@ target "debian-latest" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "14"}
tags = [
"prodrigestivill/postgres-backup-local:latest",
"prodrigestivill/postgres-backup-local:14",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:14-debian-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:latest",
"${REGISTRY_PREFIX}postgres-backup-local:14",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:14-debian-${BUILD_REVISION}" : ""
]
}

Expand All @@ -32,9 +36,9 @@ target "alpine-latest" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "14-alpine"}
tags = [
"prodrigestivill/postgres-backup-local:alpine",
"prodrigestivill/postgres-backup-local:14-alpine",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:14-alpine-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:alpine",
"${REGISTRY_PREFIX}postgres-backup-local:14-alpine",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:14-alpine-${BUILD_REVISION}" : ""
]
}

Expand All @@ -43,8 +47,8 @@ target "debian-13" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "13"}
tags = [
"prodrigestivill/postgres-backup-local:13",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:13-debian-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:13",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:13-debian-${BUILD_REVISION}" : ""
]
}

Expand All @@ -53,8 +57,8 @@ target "alpine-13" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "13-alpine"}
tags = [
"prodrigestivill/postgres-backup-local:13-alpine",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:13-alpine-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:13-alpine",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:13-alpine-${BUILD_REVISION}" : ""
]
}

Expand All @@ -63,8 +67,8 @@ target "debian-12" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "12"}
tags = [
"prodrigestivill/postgres-backup-local:12",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:12-debian-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:12",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:12-debian-${BUILD_REVISION}" : ""
]
}

Expand All @@ -73,8 +77,8 @@ target "alpine-12" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "12-alpine"}
tags = [
"prodrigestivill/postgres-backup-local:12-alpine",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:12-alpine-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:12-alpine",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:12-alpine-${BUILD_REVISION}" : ""
]
}

Expand All @@ -83,8 +87,8 @@ target "debian-11" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7"]
args = {"BASETAG" = "11"}
tags = [
"prodrigestivill/postgres-backup-local:11",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:11-debian-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:11",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:11-debian-${BUILD_REVISION}" : ""
]
}

Expand All @@ -93,8 +97,8 @@ target "alpine-11" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "11-alpine"}
tags = [
"prodrigestivill/postgres-backup-local:11-alpine",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:11-alpine-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:11-alpine",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:11-alpine-${BUILD_REVISION}" : ""
]
}

Expand All @@ -103,8 +107,8 @@ target "debian-10" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7"]
args = {"BASETAG" = "10"}
tags = [
"prodrigestivill/postgres-backup-local:10",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:10-debian-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:10",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:10-debian-${BUILD_REVISION}" : ""
]
}

Expand All @@ -113,7 +117,7 @@ target "alpine-10" {
platforms = ["linux/amd64", "linux/arm64", "linux/arm/v7", "linux/s390x", "linux/ppc64le"]
args = {"BASETAG" = "10-alpine"}
tags = [
"prodrigestivill/postgres-backup-local:10-alpine",
notequal("", BUILDREV) ? "prodrigestivill/postgres-backup-local:10-alpine-${BUILDREV}" : ""
"${REGISTRY_PREFIX}postgres-backup-local:10-alpine",
notequal("", BUILD_REVISION) ? "${REGISTRY_PREFIX}postgres-backup-local:10-alpine-${BUILD_REVISION}" : ""
]
}
36 changes: 20 additions & 16 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

DOCKER_BAKE_FILE=${1:-"docker-bake.hcl"}
IMAGE_NAME=${IMAGE_NAME:-"prodrigestivill/postgres-backup-local"}
IMAGE_NAME=${IMAGE_NAME:-"postgres-backup-local"}

GOCRONVER="v0.0.10"
MAIN_TAG="14"
Expand All @@ -25,7 +25,11 @@ group "default" {
targets = [$T]
}
variable "BUILDREV" {
variable "REGISTRY_PREFIX" {
default = ""
}
variable "BUILD_REVISION" {
default = ""
}
Expand All @@ -44,9 +48,9 @@ target "debian-latest" {
platforms = [$P]
args = {"BASETAG" = "$MAIN_TAG"}
tags = [
"$IMAGE_NAME:latest",
"$IMAGE_NAME:$MAIN_TAG",
notequal("", BUILDREV) ? "$IMAGE_NAME:$MAIN_TAG-debian-\${BUILDREV}" : ""
"\${REGISTRY_PREFIX}$IMAGE_NAME:latest",
"\${REGISTRY_PREFIX}$IMAGE_NAME:$MAIN_TAG",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}$IMAGE_NAME:$MAIN_TAG-debian-\${BUILD_REVISION}" : ""
]
}
Expand All @@ -55,9 +59,9 @@ target "alpine-latest" {
platforms = [$P]
args = {"BASETAG" = "$MAIN_TAG-alpine"}
tags = [
"$IMAGE_NAME:alpine",
"$IMAGE_NAME:$MAIN_TAG-alpine",
notequal("", BUILDREV) ? "$IMAGE_NAME:$MAIN_TAG-alpine-\${BUILDREV}" : ""
"\${REGISTRY_PREFIX}$IMAGE_NAME:alpine",
"\${REGISTRY_PREFIX}$IMAGE_NAME:$MAIN_TAG-alpine",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}$IMAGE_NAME:$MAIN_TAG-alpine-\${BUILD_REVISION}" : ""
]
}
EOF
Expand All @@ -69,8 +73,8 @@ target "debian-$TAG" {
platforms = [$P]
args = {"BASETAG" = "$TAG"}
tags = [
"$IMAGE_NAME:$TAG",
notequal("", BUILDREV) ? "$IMAGE_NAME:$TAG-debian-\${BUILDREV}" : ""
"\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG-debian-\${BUILD_REVISION}" : ""
]
}
Expand All @@ -79,8 +83,8 @@ target "alpine-$TAG" {
platforms = [$P]
args = {"BASETAG" = "$TAG-alpine"}
tags = [
"$IMAGE_NAME:$TAG-alpine",
notequal("", BUILDREV) ? "$IMAGE_NAME:$TAG-alpine-\${BUILDREV}" : ""
"\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG-alpine",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG-alpine-\${BUILD_REVISION}" : ""
]
}
EOF
Expand All @@ -93,8 +97,8 @@ target "debian-$TAG" {
platforms = [$P2]
args = {"BASETAG" = "$TAG"}
tags = [
"$IMAGE_NAME:$TAG",
notequal("", BUILDREV) ? "$IMAGE_NAME:$TAG-debian-\${BUILDREV}" : ""
"\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG-debian-\${BUILD_REVISION}" : ""
]
}
Expand All @@ -103,8 +107,8 @@ target "alpine-$TAG" {
platforms = [$P]
args = {"BASETAG" = "$TAG-alpine"}
tags = [
"$IMAGE_NAME:$TAG-alpine",
notequal("", BUILDREV) ? "$IMAGE_NAME:$TAG-alpine-\${BUILDREV}" : ""
"\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG-alpine",
notequal("", BUILD_REVISION) ? "\${REGISTRY_PREFIX}$IMAGE_NAME:$TAG-alpine-\${BUILD_REVISION}" : ""
]
}
EOF
Expand Down
26 changes: 0 additions & 26 deletions publish.sh

This file was deleted.

0 comments on commit e558018

Please sign in to comment.