Armazenar outros formatos no Artifact Registry

Saiba como configurar um repositório de formato genérico do Artifact Registry e fazer upload de um arquivo YAML.

Antes de começar

  1. 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.
  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. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  7. Enable the Artifact Registry API.

    Enable the API

  8. Iniciar o Cloud Shell

  9. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  10. Neste guia de início rápido, você vai usar o Cloud Shell para executar comandos gcloud.

    Criar um repositório genérico

    1. Para criar um repositório de formato genérico chamado quickstart-generic-repo no local us-central1 com a descrição Generic repository, execute o seguinte comando:

      gcloud artifacts repositories create quickstart-generic-repo \
          --repository-format=generic \
          --location=us-central1 \
          --description="Generic repository"
      
    2. Para verificar se o repositório foi criado, execute o seguinte comando:

      gcloud artifacts repositories list
      
    3. Para simplificar os comandos gcloud, execute os comandos a seguir para definir o repositório padrão como quickstart-generic-repo e o local padrão como us-central1.

      1. Para definir o repositório padrão como quickstart-generic-repo, execute o seguinte comando:

        gcloud config set artifacts/repository quickstart-generic-repo
        
      2. Para definir o local padrão como us-central1, execute o seguinte comando:

        gcloud config set artifacts/location us-central1
        

      Depois que os valores forem definidos, não será necessário especificá-los nos comandos gcloud que exigem um repositório ou local.

    Fazer upload de um artefato para o repositório

    1. No diretório inicial, crie um arquivo para fazer upload no repositório:

      echo "hello world" > hello.yaml
      
    2. Para fazer upload do arquivo como um artefato para o repositório, execute o seguinte comando:

      gcloud artifacts generic upload \
          --source=hello.yaml \
          --package=my-package \
          --version=1.0.0
      

      Em que:

      • hello.yaml é o caminho do arquivo para upload;
      • my-package é o pacote para upload.
      • 1.0.0 é a versão do artefato. Não é possível substituir uma versão existente no repositório.

    Ver artefatos no repositório

    Para verificar se o artefato foi adicionado ao repositório, liste todos os artefatos executando o seguinte comando:

    gcloud artifacts files list
    

    A resposta inclui os detalhes do arquivo no formato PACKAGE:VERSION:FILE_NAME.

    No exemplo a seguir, hello.yaml é o FILE_NAME:

    FILE: my-package:1.0.0:hello.yaml
    CREATE_TIME: 2023-03-09T20:55:07
    UPDATE_TIME: 2023-03-09T20:55:07
    SIZE (MB): 0.000
    OWNER: projects/my-project/locations/us-central1/repositories/quickstart-generic-repo/packages/my-package/versions/1.0.0
    

    Baixar um artefato genérico

    Para baixar um artefato genérico do repositório, execute o seguinte comando:

    gcloud artifacts generic download \
        --name=hello.yaml \
        --package=my-package \
        --version=1.0.0 \
        --destination=DESTINATION
    

    Em que:

    • hello.yaml é o nome do arquivo a ser baixado.
    • my-package é o pacote a ser baixado.
    • 1.0.0 é a versão do artefato.

    Substitua DESTINATION pelo diretório no sistema de arquivos local em que você quer salvar o download. A pasta de destino precisa existir ou o comando vai falhar.

    Limpar

    Para evitar cobranças na sua conta do Google Cloud pelos recursos usados neste tutorial, exclua o projeto que os contém ou mantenha o projeto e exclua o repositório.

    Excluir o projeto

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    Excluir o repositório

    Antes de remover um repositório, verifique se os pacotes que você quer manter estão disponíveis em outro local.

    1. Para excluir o repositório quickstart-generic-repo, execute o seguinte comando:

      gcloud artifacts repositories delete quickstart-generic-repo
      
    2. Se você quiser remover as configurações padrão de repositório e localização que definiu para a configuração ativa gcloud, execute os seguintes comandos:

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

    A seguir