From 6fa21d88350e5cdc4b7d350427f6a8452165c9bf Mon Sep 17 00:00:00 2001 From: Joshua Van Deren Date: Tue, 4 Jun 2024 23:07:59 -0600 Subject: [PATCH 1/7] Rename old gcloud registry --- docker-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-build.sh b/docker-build.sh index 054f57c..e06e361 100755 --- a/docker-build.sh +++ b/docker-build.sh @@ -25,7 +25,7 @@ _is_new_github_registry() { [ "$INPUT_REGISTRY" = ghcr.io ] } -_is_gcloud_registry() { +_is_gcloud_container_registry() { [[ "$INPUT_REGISTRY" =~ ^(.+\.)?gcr\.io$ ]] } @@ -62,7 +62,7 @@ _set_namespace() { NAMESPACE=${INPUT_USERNAME:?A username is needed if no namespace is provided} elif _is_old_github_registry; then NAMESPACE=$GITHUB_REPOSITORY - elif _is_gcloud_registry; then + elif _is_gcloud_container_registry; then # take project_id from Json Key NAMESPACE=$(echo "${INPUT_PASSWORD}" | sed -rn 's@.+project_id" *: *"([^"]+).+@\1@p' 2> /dev/null) [ "$NAMESPACE" ] || return 1 From 7b45d7dbdcfd49ff74a97ffbf0db8fcc8cabb35d Mon Sep 17 00:00:00 2001 From: Joshua Van Deren Date: Tue, 4 Jun 2024 23:43:57 -0600 Subject: [PATCH 2/7] Add support for gcloud artifact registry --- docker-build.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docker-build.sh b/docker-build.sh index e06e361..0667d4a 100755 --- a/docker-build.sh +++ b/docker-build.sh @@ -25,6 +25,13 @@ _is_new_github_registry() { [ "$INPUT_REGISTRY" = ghcr.io ] } +_is_gcloud_artifact_registry() { + # Docker repository: https://cloud.google.com/artifact-registry/docs/docker/names#docker-repo + # Domain-scoped project: https://cloud.google.com/artifact-registry/docs/docker/names#domain + [[ "$INPUT_REGISTRY" =~ ([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-]+)\/([a-z0-9-]+) ]] \ + || [[ "$INPUT_REGISTRY" =~ ([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-]+)\/([a-z0-9-]+)\/([a-z0-9-]+) ]] +} + _is_gcloud_container_registry() { [[ "$INPUT_REGISTRY" =~ ^(.+\.)?gcr\.io$ ]] } @@ -66,6 +73,8 @@ _set_namespace() { # take project_id from Json Key NAMESPACE=$(echo "${INPUT_PASSWORD}" | sed -rn 's@.+project_id" *: *"([^"]+).+@\1@p' 2> /dev/null) [ "$NAMESPACE" ] || return 1 + if _is_gcloud_artifact_registry; then + NAMESPACE=$INPUT_REGISTRY elif _is_aws_ecr_public; then NAMESPACE=$(_aws_get_public_ecr_registry_name) fi From 99ecd922aea832780ff1c097f277d0ee8d3a77d9 Mon Sep 17 00:00:00 2001 From: Joshua Van Deren Date: Wed, 5 Jun 2024 00:05:49 -0600 Subject: [PATCH 3/7] Update README --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3822024..9e27d0e 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,29 @@ Find working minimal examples for the most known registries in [this repo](https image_name: hello-world ``` -### Google Cloud Registry +### Google Cloud Artifact Registry + +```yml +# https://github.com/google-github-actions/auth +- uses: google-github-actions/auth@v2 + id: auth + with: + token_format: access_token + workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} + service_account: ${{ secrets.SERVICE_ACCOUNT }} + +- uses: whoan/docker-build-with-cache-action@v5 + with: + username: whoan + password: ${{ steps.auth.outputs.access_token }} + # Docker repository + registry: us-west1-docker.pkg.dev/my-project/my-repo + # Domain-scoped project + # registry: us-west1-docker.pkg.dev/example.com/my-project/my-repo + image_name: hello-world +``` + +### Google Cloud Container Registry > More info [here](https://cloud.google.com/container-registry/docs/advanced-authentication#json-key) on how to get GCloud JSON key. From 7180c692cb9dc83d3e9b68ddf5fc7db46931eec6 Mon Sep 17 00:00:00 2001 From: Joshua Van Deren Date: Wed, 5 Jun 2024 00:09:02 -0600 Subject: [PATCH 4/7] Add period (.) for domain scoped projects --- docker-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-build.sh b/docker-build.sh index 0667d4a..7b9e1ca 100755 --- a/docker-build.sh +++ b/docker-build.sh @@ -29,7 +29,7 @@ _is_gcloud_artifact_registry() { # Docker repository: https://cloud.google.com/artifact-registry/docs/docker/names#docker-repo # Domain-scoped project: https://cloud.google.com/artifact-registry/docs/docker/names#domain [[ "$INPUT_REGISTRY" =~ ([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-]+)\/([a-z0-9-]+) ]] \ - || [[ "$INPUT_REGISTRY" =~ ([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-]+)\/([a-z0-9-]+)\/([a-z0-9-]+) ]] + || [[ "$INPUT_REGISTRY" =~ ([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-.]+)\/([a-z0-9-]+)\/([a-z0-9-]+) ]] } _is_gcloud_container_registry() { From ec81c5227efa1a39374c3c6f5fb6fe983f1bb837 Mon Sep 17 00:00:00 2001 From: Joshua Van Deren Date: Wed, 5 Jun 2024 00:10:37 -0600 Subject: [PATCH 5/7] Add star ^ and end $ --- docker-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-build.sh b/docker-build.sh index 7b9e1ca..d28fb9a 100755 --- a/docker-build.sh +++ b/docker-build.sh @@ -28,8 +28,8 @@ _is_new_github_registry() { _is_gcloud_artifact_registry() { # Docker repository: https://cloud.google.com/artifact-registry/docs/docker/names#docker-repo # Domain-scoped project: https://cloud.google.com/artifact-registry/docs/docker/names#domain - [[ "$INPUT_REGISTRY" =~ ([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-]+)\/([a-z0-9-]+) ]] \ - || [[ "$INPUT_REGISTRY" =~ ([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-.]+)\/([a-z0-9-]+)\/([a-z0-9-]+) ]] + [[ "$INPUT_REGISTRY" =~ ^([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-]+)\/([a-z0-9-]+)$ ]] \ + || [[ "$INPUT_REGISTRY" =~ ^([a-z0-9-]+)-docker.pkg.dev\/([a-z0-9-.]+)\/([a-z0-9-]+)\/([a-z0-9-]+)$ ]] } _is_gcloud_container_registry() { From 31c7a8a1265cc9d4e1208dd73a7c8b2a229aa87c Mon Sep 17 00:00:00 2001 From: Joshua Van Deren Date: Wed, 5 Jun 2024 00:13:27 -0600 Subject: [PATCH 6/7] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9e27d0e..98e4c39 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,8 @@ Find working minimal examples for the most known registries in [this repo](https ### Google Cloud Artifact Registry +> More info [here](https://cloud.google.com/artifact-registry/docs/docker/names) on Google Cloud repository and image names. + ```yml # https://github.com/google-github-actions/auth - uses: google-github-actions/auth@v2 From 773d67aa4c61d68c58d33679b45b663815b474f4 Mon Sep 17 00:00:00 2001 From: Joshua Van Deren Date: Wed, 5 Jun 2024 00:30:48 -0600 Subject: [PATCH 7/7] Update logic --- docker-build.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docker-build.sh b/docker-build.sh index d28fb9a..9a0185f 100755 --- a/docker-build.sh +++ b/docker-build.sh @@ -73,8 +73,6 @@ _set_namespace() { # take project_id from Json Key NAMESPACE=$(echo "${INPUT_PASSWORD}" | sed -rn 's@.+project_id" *: *"([^"]+).+@\1@p' 2> /dev/null) [ "$NAMESPACE" ] || return 1 - if _is_gcloud_artifact_registry; then - NAMESPACE=$INPUT_REGISTRY elif _is_aws_ecr_public; then NAMESPACE=$(_aws_get_public_ecr_registry_name) fi @@ -309,6 +307,11 @@ init_variables() { # split tags (to allow multiple comma-separated tags) IFS=, read -ra INPUT_IMAGE_TAG <<< "$INPUT_IMAGE_TAG" + + if _is_gcloud_artifact_registry; then + return + fi + if ! _set_namespace; then echo "Could not set namespace" >&2 exit 1