Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Google Cloud Artifact Registry #159

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,31 @@ Find working minimal examples for the most known registries in [this repo](https
image_name: hello-world
```

### Google Cloud Registry
### 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
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.

Expand Down
16 changes: 14 additions & 2 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ _is_new_github_registry() {
[ "$INPUT_REGISTRY" = ghcr.io ]
}

_is_gcloud_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-]+)$ ]]
}

_is_gcloud_container_registry() {
[[ "$INPUT_REGISTRY" =~ ^(.+\.)?gcr\.io$ ]]
}

Expand Down Expand Up @@ -62,7 +69,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
Expand Down Expand Up @@ -300,6 +307,11 @@ init_variables() {

# split tags (to allow multiple comma-separated tags)
IFS=, read -ra INPUT_IMAGE_TAG <<< "$INPUT_IMAGE_TAG"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather move this condition as an elif insode _set_namespace (after the elif of _is_gcloud_container_registry.
Let me know if you want me to do it if it's not clear.

Thanks for the contribution!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate it man!

I was not sure if it would be confusing to call _set_namespace just to keep $NAMESPACE empty for _is_gcloud_artifact_registry. However, I can move this condition 👍🏻 .

Also, this PR is not quite ready yet. The error I had seen via #158 makes me believe I may had done something incorrect since this error is thrown in entrypoint.sh#L29-L32. I have not had a chance to test this PR yet, but I'll try to get to it at some point 🙂

if _is_gcloud_artifact_registry; then
return
fi

if ! _set_namespace; then
echo "Could not set namespace" >&2
exit 1
Expand Down