GoogleCloudPlatform / gcr-cleaner

Delete untagged image refs in Google Container Registry or Artifact Registry
Apache License 2.0
805 stars 112 forks source link

Run locally #5

Closed WLun001 closed 4 years ago

WLun001 commented 4 years ago

How to run it locally?

I tried go run . and on postman

{
    "repo": "gcr.io/PROEJCT_ID/IMAGE"
}

I tried and it return me this error

{
  "error":"failed to clean: failed to list tags for repo gcr.io/PROJECT_ID/IMAGE: Get https://gcr.io/v2/token?scope=repository%3APROJECT_ID%2FfIMAGE%3Apull\u0026service=gcr.io: failed to read metadata: Get http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token: dial tcp 169.254.169.254:80: i/o timeout"
}
sethvargo commented 4 years ago

It's intentionally undocumented because it's not designed to be run locally. However, you can get an oauth2 access token (gcloud auth print-access-token) and set the GCRCLEANER_TOKEN environment variable.

GCRCLEANER_TOKEN="$(gcloud auth print-access-token)" go run .

Note this is not a supported way to run GCR cleaner.

WLun001 commented 4 years ago

Hi @sethvargo , it still hit the same error, after i does the steps above