Skip to content

Instantly share code, notes, and snippets.

@phosae
Last active June 28, 2024 10:30
Show Gist options
  • Save phosae/fb50a89c19b52709d09906db1a30b53d to your computer and use it in GitHub Desktop.
Save phosae/fb50a89c19b52709d09906db1a30b53d to your computer and use it in GitHub Desktop.
Dockerless image

ko for Golang

# simple main
KO_DOCKER_REPO=zengxu ko build --platform linux/amd64,linux/arm64 -B -t `<tag>`
# cmd style
KOCACHE=/tmp/ko KO_DOCKER_REPO=zengxu ko build --platform linux/amd64 qiniu.com/dora-cloud/next/app/application-controller

change base image --> KO_DEFAULTBASEIMAGE

kyverno examples of ko

Jib CLI for Java

jib build --target=my-registry.example.com/built-by-jib

jib jar --target=my-registry.example.com/jar-app myapp.jar

jib war --target path/to/myapp.war

nixpacks, alternative image package tool for many languages (poor ARM support?

nixpacks build ./qappctl-shim-rs --name car-rust-up:v3

no for NodeJS

https://github.com/thesayyn/no

### install

brew install railwayapp/tap/nixpacks
---
curl -sSL https://nixpacks.com/install.sh | bash
---
# Replace {VERSION} with the version that you want to install
curl -LO https://github.com/railwayapp/nixpacks/releases/download/v{VERSION}/nixpacks-v{VERSION}-amd64.deb
sudo dpkg -i nixpacks-v{VERSION}-amd64.deb

skopeo

wget -O skopeo https://github.com/phosae/bin/releases/download/skopeo/skopeo-linux-amd64-v1.11.1

skopeo inspect docker://zengxu/debug-k8stream:latest
# from registry A to registry B
skopeo copy --multi-arch all --dest-creds <user>:<token> docker://registry.k8s.io/pause:3.3 docker://zengxu/pause:3.3
# local daemon to registry
skopeo copy --multi-arch all --dest-creds <user>:<token> --src-daemon-host unix:///Users/<user>/.docker/run/docker.sock docker-daemon:http://registry.k8s.io/pause:3.3  docker://zengxu/pause:3.3
# copy image to localdir, if command exit with error, copy https://github.com/containers/skopeo/blob/main/default-policy.json to /etc/containers/policy.json
skopeo copy docker://zengxu/debug-k8stream:latest dir:/root/zenx/bin
# download image as docker-archive
skopeo copy docker://nicolaka/netshoot:v0.13 docker-archive://root/netshoot.v0.13

policy

skopeo copy --insecure-policy docker://zengxu/debug-k8stream:latest dir:/root/zenx/bin

cat << EOF | tee /etc/containers/policy.json
{
    "default": [
        {
            "type": "insecureAcceptAnything"
        }
    ],
    "transports":
        {
            "docker-daemon":
                {
                    "": [{"type":"insecureAcceptAnything"}]
                }
        }
}
EOF

crane

go install github.com/google/go-containerregistry/cmd/crane@latest

copy across registries

crane copy quay.io/slok/kube-code-generator:v1.26.0 zengxu/kube-code-generator:v1.26.0

show/alter images

crane pull zengxu/qapictl ./img.tar

tar -tvf img.tar
-rw-r--r-- 0/0            2024 1970-01-01 00:00 sha256:98909ff9df60f4f6d10be7af1b1844a48bc4be2f0ff1efc4e61e83c6eff50f63
-rw-r--r-- 0/0        31411810 1970-01-01 00:00 bb263680fed18eecdc67f885094df6f589bafc19004839d7fdf141df236a61aa.tar.gz
-rw-r--r-- 0/0         3733190 1970-01-01 00:00 8774644606f9f4b3950fc9bc630fca68b27618a0cdca93613327003903696618.tar.gz
-rw-r--r-- 0/0         2314419 1970-01-01 00:00 01934e1d24d3ad27a0f78261183e6d46459ea75ec0f5d59553a4ccf652277d6b.tar.gz
-rw-r--r-- 0/0             356 1970-01-01 00:00 manifest.json

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

# Bundle directory contents into an image
crane append -f <(tar -f - -c some-dir/) -t ${IMAGE}

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

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

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)

crane ls List the tags in a repo

crane ls zengxu/cni-copier
221215-ec76e3c
221218-ec76e3c
221226-ec76e3c
7e9ada5
ac86731

docker registry

https://github.com/distribution/distribution

./registry serve c.yml

version: 0.1
log:
  level: info
  fields:
    service: registry
    environment: "dev"
storage: # 支持 S3, OSS, Azure 等,跨区域一般可以存一个 S3 Bucket 再用 S3 的跨区同步功能
  filesystem:
    maxthreads: 8
    rootdirectory: /disk1/container-registy

http:
    addr: 0.0.0.0:5010
    secret: "mytokensecret"

notifications:
  endpoints:
    - name: boots
      url: http://localhost:7002/v1/images/notifications
      timeout: 2s
      threshold: 5
      backoff: 1s

todo

harbor...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment