From 9b81ce8da8de06742a11f2c86be7b09c9bb9168d Mon Sep 17 00:00:00 2001 From: Eoin McAfee Date: Wed, 20 Sep 2023 11:28:53 +0100 Subject: [PATCH] test --- README.md | 23 +++++++++++++++++++++++ cmd/drone-gcr/main.go | 23 ++++++++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a94b421..5fdf294 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,28 @@ docker run --rm \ plugins/docker --dry-run ``` +### GAR (Google Artifact Registry) + +```yaml +kind: pipeline +name: default +type: docker + +steps: + - name: push-to-gar + image: plugins/gcr + pull: never + settings: + tag: latest + repo: harness/drone + registry_type: GAR + location: us + project_id: projectID + image_name: drone + json_key: + from_secret: gcr_json_key +``` + ## Developer Notes - When updating the base image, you will need to update for each architecture and OS. @@ -137,3 +159,4 @@ docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator ``` Create your pull request for the release. Get it merged then tag the release. + diff --git a/cmd/drone-gcr/main.go b/cmd/drone-gcr/main.go index 5f0015c..8a986a3 100644 --- a/cmd/drone-gcr/main.go +++ b/cmd/drone-gcr/main.go @@ -38,6 +38,11 @@ func loadConfig() Config { } } + location := getenv("PLUGIN_LOCATION") + projectID := getenv("PLUGIN_PROJECT_ID") + imageName := getenv("PLUGIN_IMAGE_NAME") + repo := getenv("PLUGIN_REPO") + password := getenv( "PLUGIN_JSON_KEY", "GCR_JSON_KEY", @@ -47,7 +52,7 @@ func loadConfig() Config { workloadIdentity := parseBoolOrDefault(false, getenv("PLUGIN_WORKLOAD_IDENTITY")) username, password = setUsernameAndPassword(username, password, workloadIdentity) - registryType := os.Getenv("PLUGIN_REGISTRY_TYPE") + registryType := getenv("PLUGIN_REGISTRY_TYPE") if registryType == "" { registryType = "GCR" } @@ -57,22 +62,22 @@ func loadConfig() Config { switch registryType { case "GCR": registry = "gcr.io" + if !strings.HasPrefix(repo, registry) { + repo = path.Join(registry, repo) + } case "GAR": - location := getenv("PLUGIN_GAR_LOCATION") - if location == "" { - logrus.Fatalf("Error: For GAR, PLUGIN_GAR_LOCATION must be set") + if location == "" || projectID == "" || imageName == "" { + logrus.Fatalf("Error: For GAR, LOCATION, PROJECT_ID and IMAGE must be set") } registry = fmt.Sprintf("%s-docker.pkg.dev", location) + if !strings.HasPrefix(repo, registry) { + repo = path.Join(registry, projectID, repo, imageName) + } default: logrus.Fatalf("Unsupported registry type: %s", registryType) } } - repo := getenv("PLUGIN_REPO") - if !strings.HasPrefix(repo, registry) { - repo = path.Join(registry, repo) - } - return Config{ Repo: repo, Registry: registry,