Artifact Registry์— Go ๋ชจ๋“ˆ ์ €์žฅ

๋น„๊ณต๊ฐœ Artifact Registry Go ์ €์žฅ์†Œ๋ฅผ ์„ค์ •ํ•˜๊ณ , ์ €์žฅ์†Œ์— ๋ชจ๋“ˆ์„ ์—…๋กœ๋“œํ•˜๊ณ , ๋ชจ๋“ˆ์„ ์ข…์† ํ•ญ๋ชฉ์œผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Artifact Registry API.

    Enable the API

  5. Install the Google Cloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Artifact Registry API.

    Enable the API

  11. Install the Google Cloud CLI.

  12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  13. To initialize the gcloud CLI, run the following command:

    gcloud init
  14. Go 1.15 ์ด์ƒ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
  15. package-go-module gcloud CLI ๋ถ€๊ฐ€๊ธฐ๋Šฅ์ธ
    ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
    gcloud components install package-go-module

์ €์žฅ์†Œ ๋งŒ๋“ค๊ธฐ

์ƒˆ ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ค๊ณ  ๊ตฌ์„ฑํ•˜๋ ค๋ฉด ๋‹ค์Œ ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

  1. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์ƒˆ ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

    gcloud artifacts repositories create REPOSITORY \
        --repository-format=go \
        --location=LOCATION \
        --description=DESCRIPTION
    

    ๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

    • REPOSITORY์€ ์ €์žฅ์†Œ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ์˜ ์ €์žฅ์†Œ ์œ„์น˜๋งˆ๋‹ค ์ €์žฅ์†Œ ์ด๋ฆ„์ด ๊ณ ์œ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    • LOCATION์€ ์ €์žฅ์†Œ์˜ ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ์œ„์น˜์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์„ ์„ค์ •ํ•˜๋Š” ๊ฒฝ์šฐ ์ด ํ”Œ๋ž˜๊ทธ๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ง€์›๋˜๋Š” ์ €์žฅ์†Œ ์œ„์น˜ ๋ชฉ๋ก์„ ๋ณด๋ ค๋ฉด gcloud artifacts locations list ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    • DESCRIPTION์€ ์„ ํƒ์‚ฌํ•ญ์œผ๋กœ, ์ €์žฅ์†Œ์˜ ์„ค๋ช…์ž…๋‹ˆ๋‹ค. ์ €์žฅ์†Œ ์„ค๋ช…์€ ์•”ํ˜ธํ™”๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ฏผ๊ฐํ•œ ์ •๋ณด๋Š” ํฌํ•จํ•˜์ง€ ๋งˆ์„ธ์š”.
  2. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์ €์žฅ์†Œ ์„ธ๋ถ€์ •๋ณด๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

      gcloud artifacts repositories describe --location=LOCATION REPOSITORY
    

    ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

      Encryption: Google-managed key
      Repository Size: 0.000MB
      createTime: '2022-06-03T20:20:01.644813Z'
      format: GO
      mode: STANDARD_REPOSITORY
      name: projects/my-project/locations/us-west1/repositories/my-repo
      updateTime: '2022-06-03T20:20:01.644813Z'
    

gcloud ๋ช…๋ น์–ด ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •

ํ”„๋กœ์ ํŠธ, ์ €์žฅ์†Œ, ์œ„์น˜ ๊ฐ’์˜ ๊ธฐ๋ณธ๊ฐ’์„ ๊ตฌ์„ฑํ•˜์—ฌ gcloud CLI ๋ช…๋ น์–ด๋ฅผ ๋‹จ์ˆœํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์ด ๊ตฌ์„ฑ๋˜๋ฉด --project, --location, --repository ํƒœ๊ทธ๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Go ๋ชจ๋“ˆ ํŒจํ‚ค์ง• ๋ฐ ์—…๋กœ๋“œ

package-go-module gcloud CLI ๋ถ€๊ฐ€๊ธฐ๋Šฅ์€ Go ๋ชจ๋“ˆ์„ ํŒจํ‚ค์ง•ํ•˜์—ฌ gcloud ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•œ Artifact Registry ๋ฒ„์ „ ์ง€์ • ๋ฐ ์—…๋กœ๋“œ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

Go ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ

๋จผ์ € ์ €์žฅ์†Œ์— ์—…๋กœ๋“œํ•  ๊ฐ„๋‹จํ•œ Go ๋ชจ๋“ˆ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

  1. ํ™ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ๋ชจ๋“ˆ์— 'foo'๋ผ๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

    mkdir foo
    
  2. ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋ชจ๋“ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  go mod init๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋ชจ๋“ˆ์šฉ go.mod ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

      cd foo \
      go mod init example.com/foo
    

    example.com/foo๋ฅผ ๋ชจ๋“ˆ ๊ฒฝ๋กœ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Go ๋ชจ๋“ˆ ์ฐธ์กฐ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

  3. ๋‹ค์Œ ์ฝ˜ํ…์ธ ๋กœ foo ๋””๋ ‰ํ„ฐ๋ฆฌ์— foo.go๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

    
    package foo
    
    const HelloWorld = "Hello World!"
    

๋ชจ๋“ˆ ํŒจํ‚ค์ง• ๋ฐ ์—…๋กœ๋“œ

๋ชจ๋“ˆ์„ ํŒจํ‚ค์ง•ํ•˜๊ณ  ์ €์žฅ์†Œ์— ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

  gcloud artifacts go upload --project=PROJECT \
      --repository=REPOSITORY \
      --location=LOCATION \
      --module-path=example.com/foo \
      --version=VERSION \
      --source=SOURCE_LOCATION

๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

  • PROJECT๋ฅผ Google Cloud ํ”„๋กœ์ ํŠธ ID๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
  • REPOSITORY๋ฅผ ํŒจํ‚ค์ง€๊ฐ€ ์ €์žฅ๋œ ์ €์žฅ์†Œ์˜ ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
  • LOCATION์„ ์ €์žฅ์†Œ์˜ ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ์œ„์น˜๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
  • example.com/foo๋ฅผ ๋ชจ๋“ˆ ๊ฒฝ๋กœ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Go ๋ชจ๋“ˆ ์ฐธ์กฐ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.
  • VERSION์„ vX.Y.Z ํ˜•์‹์œผ๋กœ ๋œ ๋ชจ๋“ˆ์˜ ์‹œ๋งจํ‹ฑ ๋ฒ„์ „์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ X๋Š” ์ฃผ ๋ฒ„์ „์ด๊ณ  Y๋Š” ๋ถ€ ๋ฒ„์ „์ด๊ณ  Z๋Š” ํŒจ์น˜ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค.
  • SOURCE_LOCATION์„ Go ๋ชจ๋“ˆ์˜ ๋ฃจํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ ๊ฒฝ๋กœ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. --source ํ”Œ๋ž˜๊ทธ๋ฅผ ์ƒ๋žตํ•˜๋ฉด ๊ธฐ๋ณธ๊ฐ’์€ ํ˜„์žฌ ๋””๋ ‰ํ„ฐ๋ฆฌ์ž…๋‹ˆ๋‹ค.

๋ชจ๋“ˆ์ด Artifact Registry์— ์—…๋กœ๋“œ๋ฉ๋‹ˆ๋‹ค.

Go ๋ชจ๋“ˆ ๋งŒ๋“ค๊ธฐ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ด ํŠœํ† ๋ฆฌ์–ผ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋ชจ๋“ˆ ๋‚˜์—ด

๊ธฐ๋ณธ๊ฐ’์ด ๊ตฌ์„ฑ๋œ ๊ฒฝ์šฐ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๊ธฐ๋ณธ ํ”„๋กœ์ ํŠธ, ์ €์žฅ์†Œ, ์œ„์น˜์—์„œ ์—…๋กœ๋“œ๋œ Go ๋ชจ๋“ˆ์„ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค.

  gcloud artifacts packages list

๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

  Listing items under project my-project, location us-west1, repository my-repo.

  PACKAGE                   CREATE_TIME          UPDATE_TIME
  example.com/foo           2022-06-03T20:43:39  2022-06-20T20:37:40

๋ชจ๋“ˆ ๋ฒ„์ „ ์„ธ๋ถ€์ •๋ณด ๋ณด๊ธฐ

๊ธฐ๋ณธ๊ฐ’์ด ๊ตฌ์„ฑ๋œ ๊ฒฝ์šฐ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๊ธฐ๋ณธ ํ”„๋กœ์ ํŠธ, ์ €์žฅ์†Œ, ์œ„์น˜์˜ ๋ชจ๋“ˆ ๋ฒ„์ „์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

  gcloud artifacts versions list --package=MODULE_PATH

๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

  Listing items under project my-project, location us-west1, repository my-repo, package example.com/foo.

  VERSION  DESCRIPTION  CREATE_TIME          UPDATE_TIME
  v0.1.0                2022-06-03T20:43:39  2022-06-03T20:43:39
  v0.1.1                2022-06-20T20:37:40  2022-06-20T20:37:40

๋ชจ๋“ˆ ๋‹ค์šด๋กœ๋“œ

Artifact Registry์— ์ €์žฅ๋œ ๋ชจ๋“ˆ์„ ๊ฐ€์ ธ์˜ค๋ ค๋ฉด Artifact Registry์—์„œ ์ข…์† ํ•ญ๋ชฉ์„ ์ฐพ๊ณ  ์ฒดํฌ์„ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์šฐํšŒํ•˜๋„๋ก Go์— ์ง€์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Go ํ™˜๊ฒฝ ์„ค์ •

  1. Artifact Registry์—์„œ ๋ชจ๋“ˆ, ๊ณต๊ฐœ Go ๋ชจ๋“ˆ ํ”„๋ก์‹œ, ๊ทธ๋ฆฌ๊ณ  ์†Œ์Šค์˜ ์ˆœ์„œ๋Œ€๋กœ ๋‹ค์šด๋กœ๋“œํ•˜๋„๋ก Go์— ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค.

      export GOPROXY=https://LOCATION-go.pkg.dev/PROJECT/REPOSITORY,https://proxy.golang.org,direct
    

    ๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

    • LOCATION์€ ์ €์žฅ์†Œ์˜ ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ์œ„์น˜์ž…๋‹ˆ๋‹ค.
    • PROJECT๋Š” Google Cloud ํ”„๋กœ์ ํŠธ ID์ž…๋‹ˆ๋‹ค.
    • REPOSITORY๋Š” ํŒจํ‚ค์ง€๊ฐ€ ์ €์žฅ๋œ ์ €์žฅ์†Œ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
  2. ๊ณต๊ฐœ ์ฒดํฌ์„ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“ˆ์„ ๊ฒ€์‚ฌ์—์„œ ์ œ์™ธํ•ฉ๋‹ˆ๋‹ค.

      export GONOSUMDB=MODULE_PATH_REGEX
    

    ์—ฌ๋Ÿฌ ๋ชจ๋“ˆ์„ ์ œ์™ธํ•˜๋ ค๋ฉด MODULE_PATH_REGEX๋ฅผ ๋ชจ๋“ˆ ๊ฒฝ๋กœ ๋˜๋Š” ์ •๊ทœ์‹์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

    ๊ณต๊ฐœ ์ฒดํฌ์„ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ example.com/foo ๋ชจ๋“ˆ์ด ๊ฒ€์‚ฌ๋˜์ง€ ์•Š๋„๋ก ์ œ์™ธํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      export GONOSUMDB=example.com/foo
    

    example.com์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ชจ๋“ˆ ๊ฒฝ๋กœ๊ฐ€ ์žˆ๋Š” ๋ชจ๋“  ๋ชจ๋“ˆ์ด ๊ณต๊ฐœ ์ฒดํฌ์„ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒ€์‚ฌ๋˜์ง€ ์•Š๋„๋ก ์ œ์™ธํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      export GONOSUMDB=example.com/*
    

Artifact Registry์— ์ธ์ฆ

Artifact Registry์—์„œ ์ข…์† ํ•ญ๋ชฉ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ํŒจํ‚ค์ง•๋œ Go ๋ชจ๋“ˆ์„ ๋‹ค์šด๋กœ๋“œํ•  ๋•Œ Go ๋ฐ”์ด๋„ˆ๋ฆฌ๋Š” netrc ํŒŒ์ผ์˜ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Artifact Registry์— ์ธ์ฆํ•ฉ๋‹ˆ๋‹ค. ์ธ์ฆ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋‹จ์ˆœํ™”ํ•˜๋ ค๋ฉด Go ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ๋„์šฐ๋ฏธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Artifact Registry์— ์ธ์ฆํ•  ์ˆ˜ ์žˆ๋„๋ก netrc ํŒŒ์ผ์˜ ํ† ํฐ์„ ์ƒˆ๋กœ๊ณ ์นจํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

netrc ํŒŒ์ผ์˜ ์œ„์น˜๋Š” netrc ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. NETRC ๋ณ€์ˆ˜๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ go ๋ช…๋ น์–ด๋Š” UNIX ๊ณ„์—ด ํ”Œ๋žซํผ์—์„œ $HOME/.netrc๋ฅผ, Windows์—์„œ๋Š” %USERPROFILE%\_netrc๋ฅผ ์ฝ์Šต๋‹ˆ๋‹ค.

Artifact Registry๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ธ์ฆ ๋ฐฉ๋ฒ•์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

๋‹จ๊ธฐ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด(๊ถŒ์žฅ)
Artifact Registry Go ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ๋„์šฐ๋ฏธ ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ netrc ํŒŒ์ผ์˜ ์ธ์ฆ ํ† ํฐ์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.
์„œ๋น„์Šค ๊ณ„์ • ํ‚ค ์‚ฌ์šฉ

์‚ฌ์šฉ์ž ํ™˜๊ฒฝ์—์„œ ์ธ์ฆ์— ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ ์ด ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์„ธ์š”. netrc ํŒŒ์ผ์— ์•”ํ˜ธํ™”๋˜์ง€ ์•Š์€ ์„œ๋น„์Šค ๊ณ„์ • ํ‚ค๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

GONOPROXY์— Go ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ๋„์šฐ๋ฏธ ์ถ”๊ฐ€

Go ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ๋„์šฐ๋ฏธ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์— GONOPROXY ๋ชฉ๋ก์— ์ถ”๊ฐ€ํ•˜์—ฌ Go๊ฐ€ GitHub์—์„œ ์ง์ ‘ ๋‹ค์šด๋กœ๋“œํ•˜๋„๋ก ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์†Œ์Šค์—์„œ ์ง์ ‘ ๋‹ค์šด๋กœ๋“œํ•˜๋ ค๋Š” ๋‹ค๋ฅธ ๋ชจ๋“ˆ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ ์˜ˆ์‹œ์™€ ๊ฐ™์ด ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„๋œ ๋ชฉ๋ก์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  export GONOPROXY=MODULE_PATH1, MODULE_PATH2

์—ฌ๊ธฐ์„œ MODULE_PATH1 ๋ฐ MODULE_PATH2๋Š” ์†Œ์Šค์—์„œ ๋‹ค์šด๋กœ๋“œํ•  ๋ชจ๋“ˆ์˜ ๋ชจ๋“ˆ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.

Go ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ๋„์šฐ๋ฏธ๋ฅผ GONOPROXY ๋ชฉ๋ก์— ์ถ”๊ฐ€ํ•˜๊ณ  ์‹คํ–‰ํ•˜์—ฌ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•˜๋ ค๋ฉด ๋‹ค์Œ ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

  1. Go ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ๋„์šฐ๋ฏธ๋ฅผ GONOPROXY์— ์ถ”๊ฐ€

      export GONOPROXY=github.com/GoogleCloudPlatform/artifact-registry-go-tools
    
  2. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ Go ๋ชจ๋“ˆ ํŒจํ‚ค์ง€ ๋„๊ตฌ๋กœ Artifact Registry ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ netrc ํŒŒ์ผ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

      GOPROXY=proxy.golang.org \
          go run github.com/GoogleCloudPlatform/artifact-registry-go-tools/cmd/auth@v0.1.0 \
          add-locations --locations=LOCATION \
          [--json_key=path/to/service/account/key.json]
    

    ์—ฌ๊ธฐ์„œ LOCATION์€ ์ €์žฅ์†Œ์˜ ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ์œ„์น˜์ž…๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ์œ„์น˜๋ฅผ ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„๋œ ๋ชฉ๋ก์œผ๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

    Go ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด ๋„์šฐ๋ฏธ๋Š” Artifact Registry ์ธ์ฆ์„ ์œ„ํ•ด netrc ํŒŒ์ผ์— ์„ค์ •์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. --json_key ํ”Œ๋ž˜๊ทธ๋ฅผ ์ „๋‹ฌํ•˜๋ฉด ํ‚ค๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ ์ธ์ฆ์— ์‚ฌ์šฉ๋˜๋Š” netrc ํŒŒ์ผ์— ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค.

๋ชจ๋“ˆ์„ ์ข…์† ํ•ญ๋ชฉ์œผ๋กœ ์‚ฌ์šฉ

  1. Artifact Registry์— ์ธ์ฆํ•˜๋Š” ๋ฐ ๋‹จ๊ธฐ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ OAuth ํ† ํฐ์„ ์ƒˆ๋กœ๊ณ ์นจํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

      GOPROXY=proxy.golang.org \
      go run github.com/GoogleCloudPlatform/artifact-registry-go-tools/cmd/auth@v0.1.0 refresh
    
  2. ํ™ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ์— 'bar'๋ผ๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

      mkdir bar
    
  3. ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋ชจ๋“ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  go mod init๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ํŒจํ‚ค์ง€์šฉ go.mod ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

      cd bar \
      go mod init example.com/bar
    

    example.com/bar๋ฅผ ๋ชจ๋“ˆ ๊ฒฝ๋กœ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Go ๋ชจ๋“ˆ ์ฐธ์กฐ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

  4. Artifact Registry์— ์ €์žฅ๋œ foo ๋ฒ„์ „์„ ์š”๊ตฌํ•˜๋ ค๋ฉด go.mod ํŒŒ์ผ์„ ๋‹ค์Œ๊ณผ ๋น„์Šทํ•˜๊ฒŒ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    
    module example.com/bar
    
    go 1.19
    
    require example.com/foo v0.1.0
    

    ๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

    • example.com/foo๋Š” ํ•„์ˆ˜ ๋ชจ๋“ˆ์˜ ๋ชจ๋“ˆ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.
    • v0.1.0์€ Artifact Registry์— ์ €์žฅ๋œ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค.
  5. ๋‹ค์Œ ์ฝ˜ํ…์ธ ๋กœ bar ๋””๋ ‰ํ„ฐ๋ฆฌ์— main.go๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

      
      package main
    
      import (
        "fmt"
    
        foo "example.com/foo"
      )
    
      func main() {
        fmt.Println(foo.HelloWorld)
      }
    
      
    
  6. foo ํŒจํ‚ค์ง€๋ฅผ ํฌํ•จํ•˜์—ฌ ์ข…์† ํ•ญ๋ชฉ์„ ๋‹ค์šด๋กœ๋“œํ•˜๋ ค๋ฉด go mod tidy๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      go mod tidy
    
  7. bar ๋ชจ๋“ˆ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      go run .
    

    ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

      Hello World!
    

์‚ญ์ œ

์ด ํŽ˜์ด์ง€์—์„œ ์‚ฌ์šฉํ•œ ๋ฆฌ์†Œ์Šค ๋น„์šฉ์ด Google Cloud ๊ณ„์ •์— ์ฒญ๊ตฌ๋˜์ง€ ์•Š๋„๋ก ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€์—์„œ ์‚ฌ์šฉํ•œ ๋ฆฌ์†Œ์Šค ๋น„์šฉ์ด Google Cloud ๊ณ„์ •์— ์ฒญ๊ตฌ๋˜์ง€ ์•Š๋„๋ก ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ €์žฅ์†Œ๋ฅผ ์‚ญ์ œํ•˜๊ธฐ ์ „์—, ๋ณด๊ด€ํ•  ๋ชจ๋“ˆ์„ ๋‹ค๋ฅธ ์œ„์น˜์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

  1. ์ €์žฅ์†Œ๋ฅผ ์‚ญ์ œํ•˜๋ ค๋ฉด ๋‹ค์Œ ์•ˆ๋‚ด๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

      gcloud artifacts repositories delete \
          --location=LOCATION \
          --project=PROJECT \
          REPOSITORY
    

    ๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

    • LOCATION์„ ์ €์žฅ์†Œ์˜ ๋ฆฌ์ „ ๋˜๋Š” ๋ฉ€ํ‹ฐ ๋ฆฌ์ „ ์œ„์น˜๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
    • PROJECT๋ฅผ Google Cloud ํ”„๋กœ์ ํŠธ ID๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
    • REPOSITORY๋ฅผ ์ €์žฅ์†Œ ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
  2. ํ™œ์„ฑ gcloud ๊ตฌ์„ฑ์— ์ง€์ •ํ•œ ๊ธฐ๋ณธ ์ €์žฅ์†Œ์™€ ์œ„์น˜ ์„ค์ •์„ ์‚ญ์ œํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

      gcloud config unset artifacts/repository
      gcloud config unset artifacts/location
    

๋‹ค์Œ ๋‹จ๊ณ„