빠른 시작: Node.js 패키지를 Artifact Registry에 저장
이 빠른 시작에서는 비공개 Artifact Registry Node.js 패키지 저장소를 설정하고 여기에 패키지를 업로드하는 방법을 보여줍니다.
시작하기 전에
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
    
    
      
        In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Artifact Registry API. Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
- 
      Install the Google Cloud CLI. 
- 
          외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다. 
- 
        gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다. gcloud init
- 
    
    
      
        In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Artifact Registry API. Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
- 
      Install the Google Cloud CLI. 
- 
          외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다. 
- 
        gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다. gcloud init
- Windows에서 Node.js 패키지 저장소에 연결하려면 PowerShell을 설치하세요.
- Google Cloud 콘솔로 이동합니다. 
- Google Cloud 콘솔 툴바에서 Cloud Shell 활성화를 클릭합니다.  
- 저장소를 만듭니다. - 콘솔- Google Cloud 콘솔에서 저장소 페이지를 엽니다. 
- 저장소 만들기를 클릭합니다. 
- quickstart-nodejs-repo를 저장소 이름으로 지정합니다.
- 형식으로 npm을 선택하고 모드로 Standard를 선택합니다. 
- 위치 유형에서 리전을 선택한 후 - us-central1위치를 선택합니다.
- 만들기를 클릭합니다. 
 - 저장소가 저장소 목록에 추가됩니다. - gcloud- 다음 명령어를 실행하여 'Node.js 저장소'라는 설명과 함께 - us-central1위치에- quickstart-nodejs-repo라는 새 Node.js 패키지 저장소를 만듭니다.- gcloud artifacts repositories create quickstart-nodejs-repo --repository-format=npm \ --location=us-central1 --description="Node.js package repository"
- 다음 명령어를 실행하여 저장소가 생성되었는지 확인합니다. - gcloud artifacts repositories list
 - Artifact Registry 명령어에 대한 자세한 내용을 보려면 - gcloud artifacts명령어를 실행하세요.
- gcloud명령어를 단순화하려면 기본 저장소를- quickstart-nodejs-repo로 설정하고 기본 위치를- us-central1로 설정합니다. 이 값을 설정하면 저장소나 위치가 필요한- gcloud명령어에 값을 지정할 필요가 없습니다.- 저장소를 설정하려면 다음 명령어를 실행하세요. - gcloud config set artifacts/repository quickstart-nodejs-repo- 위치를 설정하려면 다음 명령어를 실행하세요. - gcloud config set artifacts/location us-central1- 이러한 명령어에 대한 자세한 내용은 gcloud config set 문서를 참조하세요. 
- 모든 그림 이모티콘 기호 및 시퀀스와 일치하는 정규 표현식을 제공하는 간단한 패키지인 emoji-regex 패키지를 다운로드하세요. - npm pack emoji-regex- 이 명령어는 패키지의 보관 파일을 다운로드합니다. 
- 보관 파일을 - emoji-regex디렉터리에 추출합니다. 다음 명령어는- emoji-regex버전 10.1.0의 보관 파일에 사용됩니다.- mkdir emoji-regex && tar xvf emoji-regex-10.1.0.tgz -C emoji-regex --strip-components 1
- Artifact Registry에서 - emoji-regex패키지를 설치하는 데 사용할 두 번째 npm 패키지를 만듭니다. 이 패키지의 경우- npm init명령어를 사용하여 기본 패키지를 만듭니다.- mkdir npm-package2 cd npm-package2 npm init -y- 메시지가 표시되면 기본값을 수락합니다. 
- 만든 Artifact Registry 저장소로 인증하도록 - emoji-regex및- npm-package2프로젝트를 모두 구성하세요.- 다음 명령어를 실행합니다. 이 명령어는 npm 구성 파일에 추가할 구성 설정을 반환합니다. - gcloud artifacts print-settings npm --scope=@quickstart- quickstart범위는 저장소와 연결되어 있습니다. 패키지를 게시하거나 설치하는 명령어에 범위를 포함하면 npm이 저장소를 사용합니다. 범위 없이 패키지를 게시하거나 설치하면 구성된 기본 저장소가 사용됩니다. 자세한 내용은 Node.js 개요를 참고하세요.- gcloud명령어의 출력은 다음 예시와 같습니다. PROJECT는 Google Cloud 프로젝트 ID입니다.- @quickstart:registry=https://us-central1-npm.pkg.dev/PROJECT/quickstart-nodejs-repo/ //us-central1-npm.pkg.dev/PROJECT/quickstart-nodejs-repo/:always-auth=true
- 이전 단계의 구성 설정을 각 npm 프로젝트의 - .npmrc파일에 추가합니다. 이 파일은- package.json파일과 동일한 디렉터리에 있습니다.- .npmrc파일에 대해 자세히 알아보려면 Node.js 개요를 참고하세요.- 각 Artifact Registry Node.js 패키지 저장소는 npm 레지스트리 엔드포인트 - https://LOCATION-npm.pkg.dev/PROJECT/REPOSITORY와 연결됩니다. 다른 Artifact Registry Node.js 패키지 저장소를 만들면 npm은 자체 범위가 있는 별도의 레지스트리로 이와 상호작용합니다.
 
- emoji-regex프로젝트와- npm-package2프로젝트 모두에서- package.json을 수정하세요.- name값에- quickstart범위가 포함되어 있는지 확인합니다.- emoji-regex의 경우:
 - "name": "@quickstart/emoji-regex"- npm-package2의 경우:
 - "name": "@quickstart/npm-package2"
- scripts아래에서 Artifact Registry 저장소의 사용자 인증 정보를 업데이트하는 클라이언트 라이브러리인 google-artifactregistry-auth에 대한 스크립트를 추가하세요.- "scripts": { "artifactregistry-login": "npx google-artifactregistry-auth --repo-config=./.npmrc --credential-config=./.npmrc" }
 
- 저장소에 연결하기 위한 액세스 토큰을 새로고침합니다. - npm run artifactregistry-login
- 저장소에 패키지를 추가합니다. - npm또는- yarn명령어를 사용할 수 있습니다.- npm publish- yarn publish
- Google Cloud 콘솔에서 저장소 페이지를 엽니다. 
- 저장소 목록에서 - quickstart-nodejs-repo저장소를 선택합니다.- 패키지 페이지에 저장소의 패키지가 나열됩니다. 
- 패키지를 클릭하여 패키지 버전을 확인합니다. 
- Google Cloud 콘솔에서 저장소 페이지를 엽니다. 
- 저장소 목록에서 - quickstart-nodejs-repo저장소를 선택합니다.
- 삭제를 클릭합니다. 
- quickstart-nodejs-repo저장소를 삭제하려면 다음 명령어를 실행합니다.- gcloud artifacts repositories delete quickstart-nodejs-repo
- 활성 - gcloud구성에 지정한 기본 저장소 및 위치 설정을 삭제하려면 다음 명령어를 실행합니다.- gcloud config unset artifacts/repository gcloud config unset artifacts/location
- 인증 구성 자세히 알아보기
- 저장소 관리 알아보기
- 패키지 관리 알아보기
- DevOps 관련 리소스를 읽고 연구 프로그램을 살펴보세요.
Cloud Shell 실행
이 빠른 시작에서는Google Cloud에서 호스팅되는 리소스를 관리하기 위한 셸 환경인 Cloud Shell을 사용합니다.
Cloud Shell에는 Google Cloud CLI가 사전 설치되어 있습니다. gcloud CLI는 Google Cloud의 기본 명령줄 인터페이스를 제공합니다.
Cloud Shell 시작:
Console 하단의 프레임에서 Cloud Shell 세션이 열립니다.
이 셸을 사용하여 gcloud 명령어를 실행합니다. 
Node.js 패키지 저장소 만들기
Node.js 아티팩트의 저장소를 만듭니다.
npm 구성
패키지를 업로드하고 다운로드하려면 만든 저장소로 인증하도록 npm 프로젝트를 구성해야 합니다. 이 빠른 시작에서는 간단한 패키지를 업로드한 후 두 번째 패키지에 종속 항목으로 설치하게 됩니다.
저장소에 패키지 업로드
저장소에서 패키지 보기
패키지가 저장소에 추가되었는지 확인하려면 다음 안내를 따르세요.
콘솔
gcloud
기본 quickstart-nodejs-repo 저장소의 이미지를 나열하려면 다음 명령어를 실행합니다.
 gcloud artifacts packages list
패키지 버전을 보려면 다음 명령어를 실행합니다.
gcloud artifacts versions list --package=PACKAGE
여기서 PACKAGE는 패키지 ID입니다.
패키지 설치
npm-package2의 Artifact Registry 저장소에서 emoji-regex 패키지를 설치합니다.
npm-package2 디렉터리에서 npm install 또는 yarn add 명령어를 실행합니다.
npm install @quickstart/emoji-regex
yarn add @quickstart/emoji-regex
이 명령어는 npm-package2 프로젝트에 emoji-regex 패키지를 설치합니다.
또한 package.json을 업데이트하여 emoji-regex를 종속 항목으로 설정합니다.
"dependencies": {
  "@quickstart/emoji-regex": "^10.1.0"
}
삭제
이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.
저장소를 삭제하기 전에, 보관할 패키지가 다른 위치에서 사용할 수 있는지 확인합니다.
저장소를 삭제하려면 다음 안내를 따르세요.