Armazene outros formatos no Artifact Registry

Saiba como configurar um repositório de formato genérico do Artifact Registry e carregar um ficheiro 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. Inicie 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 início rápido, vai usar a Cloud Shell para executar comandos gcloud.

    Crie um repositório genérico

    1. Para criar um repositório de formatos genérico denominado quickstart-generic-repo na localização 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 seguintes comandos para definir o repositório predefinido como quickstart-generic-repo e a localização predefinida como us-central1.

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

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

        gcloud config set artifacts/location us-central1
        

      Depois de definir os valores, não precisa de os especificar em gcloud comandos que requerem um repositório ou uma localização.

    Carregue um artefacto para o repositório

    1. No diretório inicial, crie um ficheiro para carregar para o repositório:

      echo "hello world" > hello.yaml
      
    2. Para carregar o ficheiro como um artefacto para o repositório, execute o seguinte comando:

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

      Onde:

      • hello.yaml é o caminho do ficheiro a carregar.
      • my-package é o pacote a carregar.
      • 1.0.0 é a versão do artefacto. Não pode substituir uma versão existente no repositório.

    Veja artefactos no repositório

    Para verificar se o artefacto foi adicionado ao repositório, pode listar todos os artefactos executando o seguinte comando:

    gcloud artifacts files list
    

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

    No exemplo seguinte, 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
    

    Transfira um artefacto genérico

    Para transferir um artefacto genérico do seu repositório, execute o seguinte comando:

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

    Onde:

    • hello.yaml é o nome do ficheiro a transferir.
    • my-package é o pacote a transferir.
    • 1.0.0 é a versão do artefacto.

    Substitua DESTINATION pelo diretório no seu sistema de ficheiros local onde quer guardar a transferência. A pasta de destino tem de existir ou o comando falha.

    Limpar

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

    Elimine 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.

    Elimine o repositório

    Antes de remover um repositório, certifique-se de que todos os pacotes que quer manter estão disponíveis noutra localização.

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

      gcloud artifacts repositories delete quickstart-generic-repo
      
    2. Se quiser remover as predefinições do repositório e da localização que configurou para a configuração gcloud ativa, execute os seguintes comandos:

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

    O que se segue?