Skip to content

Commit

Permalink
Bundle crane cli (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Sep 29, 2024
1 parent f01d51b commit 4766a7b
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 10 deletions.
52 changes: 42 additions & 10 deletions pkg/cmds/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,24 @@ func GenerateScripts(files []string, outdir string, nondistro, insecure bool) er

var buf bytes.Buffer
buf.WriteString(`#!/bin/bash
set -x
mkdir -p images
OS=$(uname -o)
if [ "${OS}" = "GNU/Linix" ]; then
OS=Linux
fi
ARCH=$(uname -m)
if [ "${ARCH}" = "aarch64" ]; then
ARCH=arm64
fi
curl -sL "https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_${OS}_${ARCH}.tar.gz" > /tmp/go-containerregistry.tar.gz
tar -zxvf /tmp/go-containerregistry.tar.gz -C /tmp/
mv /tmp/crane images
CMD="./images/crane"
`)
for _, img := range images {
// crane pull appscode/cluster-ui:0.4.16 images/cluster-ui.tar
Expand All @@ -127,7 +140,7 @@ mkdir -p images
return fmt.Errorf("image %s has no tag", img)
}

buf.WriteString("crane pull")
buf.WriteString("$CMD pull")
if nondistro {
buf.WriteString(" --allow-nondistributable-artifacts")
}
Expand All @@ -154,11 +167,16 @@ mkdir -p images
set -x
TARBALL=${1:-}
REGISTRY=${2:-}
if [ -z "${IMAGE_REGISTRY}" ]; then
echo "IMAGE_REGISTRY is not set"
exit 1
fi
TARBALL=${1:-}
tar -zxvf $TARBALL
CMD="./crane"
`)
for _, img := range images {
// crane push images/cluster-ui.tar $IMAGE_REGISTRY/cluster-ui:0.4.16
Expand All @@ -170,7 +188,7 @@ tar -zxvf $TARBALL
return fmt.Errorf("image %s has no tag", img)
}

buf.WriteString("crane push")
buf.WriteString("$CMD push")
if nondistro {
buf.WriteString(" --allow-nondistributable-artifacts")
}
Expand All @@ -193,10 +211,24 @@ tar -zxvf $TARBALL
set -x
TARBALL=${1:-}
REGISTRY=${2:-}
tar -zxvf $TARBALL
if [ -z "${IMAGE_REGISTRY}" ]; then
echo "IMAGE_REGISTRY is not set"
exit 1
fi
OS=$(uname -o)
if [ "${OS}" = "GNU/Linix" ]; then
OS=Linux
fi
ARCH=$(uname -m)
if [ "${ARCH}" = "aarch64" ]; then
ARCH=arm64
fi
curl -sL "https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_${OS}_${ARCH}.tar.gz" > /tmp/go-containerregistry.tar.gz
tar -zxvf /tmp/go-containerregistry.tar.gz -C /tmp/
mv /tmp/crane .
CMD="./crane"
`)
for _, img := range images {
Expand All @@ -209,7 +241,7 @@ tar -zxvf $TARBALL
return fmt.Errorf("image %s has no tag", img)
}

buf.WriteString("crane cp")
buf.WriteString("$CMD cp")
if nondistro {
buf.WriteString(" --allow-nondistributable-artifacts")
}
Expand Down
17 changes: 17 additions & 0 deletions testdata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Test scripts

```bash
docker network create registry
docker run -d --restart=unless-stopped --name registry --net registry \
-e "REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry" \
-e "REGISTRY_STORAGE_DELETE_ENABLED=true" \
-e "REGISTRY_VALIDATION_DISABLED=true" \
-v "registry-data:/var/lib/registry" \
-p "127.0.0.1:5000:5000" \
registry:2
```

```bash
image-packer generate-scripts --output-dir=catalog \
--src=catalog/imagelist.yaml
```
24 changes: 24 additions & 0 deletions testdata/catalog/copy-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -x

if [ -z "${IMAGE_REGISTRY}" ]; then
echo "IMAGE_REGISTRY is not set"
exit 1
fi

OS=$(uname -o)
if [ "${OS}" = "GNU/Linix" ]; then
OS=Linux
fi
ARCH=$(uname -m)
if [ "${ARCH}" = "aarch64" ]; then
ARCH=arm64
fi
curl -sL "https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_${OS}_${ARCH}.tar.gz" > /tmp/go-containerregistry.tar.gz
tar -zxvf /tmp/go-containerregistry.tar.gz -C /tmp/
mv /tmp/crane .

CMD="./crane"

$CMD cp ghcr.io/appscode/cluster-ui:0.9.7 $IMAGE_REGISTRY/appscode/cluster-ui:0.9.7
22 changes: 22 additions & 0 deletions testdata/catalog/export-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -x

mkdir -p images

OS=$(uname -o)
if [ "${OS}" = "GNU/Linix" ]; then
OS=Linux
fi
ARCH=$(uname -m)
if [ "${ARCH}" = "aarch64" ]; then
ARCH=arm64
fi
curl -sL "https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_${OS}_${ARCH}.tar.gz" > /tmp/go-containerregistry.tar.gz
tar -zxvf /tmp/go-containerregistry.tar.gz -C /tmp/
mv /tmp/crane images

CMD="./images/crane"

$CMD pull ghcr.io/appscode/cluster-ui:0.9.7 images/appscode-cluster-ui-0.9.7.tar

tar -czvf images.tar.gz images
1 change: 1 addition & 0 deletions testdata/catalog/imagelist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- ghcr.io/appscode/cluster-ui:0.9.7
15 changes: 15 additions & 0 deletions testdata/catalog/import-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -x

if [ -z "${IMAGE_REGISTRY}" ]; then
echo "IMAGE_REGISTRY is not set"
exit 1
fi

TARBALL=${1:-}
tar -zxvf $TARBALL

CMD="./crane"

$CMD push images/appscode-cluster-ui-0.9.7.tar $IMAGE_REGISTRY/appscode/cluster-ui:0.9.7

0 comments on commit 4766a7b

Please sign in to comment.