Skip to main content

Command Palette

Search for a command to run...

Mais Uma Ferramenta para Containers - CRANE

Updated
2 min read
Mais Uma Ferramenta para Containers - CRANE
M

Welcome to my corner of the digital universe!

I'm Marcelo, a seasoned DevOps professional with a passion for orchestrating seamless experiences in the cloud-native ecosystem. With expertise in containers, Kubernetes, and cloud technologies, I thrive on architecting robust, scalable, and automated solutions that empower businesses to soar to new heights.

My journey in the realm of DevOps has been nothing short of exhilarating. From streamlining deployment pipelines to optimizing infrastructure performance, I've honed my craft to deliver tangible results that drive innovation and efficiency.

As a fervent advocate for containerization and Kubernetes, I believe in harnessing the power of these transformative technologies to unlock unparalleled agility and scalability. Whether it's orchestrating microservices architectures or implementing resilient CI/CD pipelines, I'm dedicated to leveraging cutting-edge tools and best practices to propel organizations towards their goals.

Beyond the code and configurations, I'm committed to fostering a culture of collaboration and continuous improvement. By championing DevOps principles and fostering cross-functional teamwork, I strive to cultivate environments where innovation flourishes and challenges are met with resilience.

So, whether you're embarking on your cloud journey or seeking to optimize your existing infrastructure, I'm here to be your trusted ally in navigating the ever-evolving landscape of modern IT.

Let's embark on this transformative journey together and unlock the boundless potential of DevOps in the digital age!

Introdução

Estava fazendo alguns estudos sobre as ferramentas do Sigstore e acabei me deparando com uma menção a uma ferramenta para manipulação de imagens e registries que eu não conhecia, de nome Crane. Identifiquei logo de cara que havia alguns recursos interessantes que poderiam auxiliar na inspeção e manipulação de imagens. Baixei a ferramenta e comecei os testes. Para o meu caso, que uso o Manjaro, bastou rodar um comando para completar a instalação.

pacman -S crane

Segue abaixo a lista de comandos que achei mais interessante para o meu uso. Para ver todos os subcomandos, basta rodar crane -h.

Exemplos de aplicação

Referência para a lista de comandos:

  • https://github.com/google/go-containerregistry/blob/main/cmd/crane/recipes.md

Listar todas as tags de um repositório

crane ls docker.io/library/nginx

Logar em um registry

crane auth login reg.example.com -u AzureDiamond -p hunter2

Inspecionar o config de uma imagem

crane config ubuntu:22.04 | jq

Inspecionar o manifesto de uma imagem

crane manifest ubuntu:22.04 | jq

Exportar o sistema de arquivo do container como um tarball

crane export ubuntu ubuntu.tar

Baixar uma imagem e salvá-la localmente em um tarball

crane pull ubuntu:22.10 ubuntu2210.tar

Listar arquivos de uma imagem

crane export ubuntu - | tar -tvf - | less

Extrair um arquivo de uma imagem

crane export ubuntu - | tar -Oxf - etc/passwd

Observação: certifique de remover a "/" do início do caminho do arquivo.

Crie uma image a partir de um diretório

crane append -f <(tar -f - -c some-dir/) -t ${IMAGE}

Por padrão, isso produz uma imagem com uma camada contendo o conteúdo o diretório. Adicione -b ${BASE_IMAGE} para anexar a camada a uma imagem base.

Esse exemplo carece de validação. Pelos testes que fiz localmente, ele tenta fazer a modificação remotamente no registry.

Verificar a diferença de configs de duas imagens

diff <(crane config busybox:1.32 | jq) <(crane config busybox:1.33 | jq)

Verificar a diferença de manifestos de duas imagens

diff <(crane manifest busybox:1.32 | jq) <(crane manifest busybox:1.33 | jq)

Verificar a diferença do sistema de arquivo

diff \
    <(crane export gcr.io/kaniko-project/executor:v1.6.0-debug - | tar -tvf - | sort) \
    <(crane export gcr.io/kaniko-project/executor:v1.7.0-debug - | tar -tvf - | sort)

Identificar o tamanho da imagem

crane manifest gcr.io/buildpacks/builder:v1 | jq '.config.size + ([.layers[].size] | add)' | numfmt --to=iec