Skip to content

Commit

Permalink
Build multi-arch OCI image (#113)
Browse files Browse the repository at this point in the history
* Build multiplatform docker image

* Add multiarch support in install config and scripts

* Address review feedback

* Ignore __pycache__

* Fix tests

Co-authored-by: Plamen Kokanov <[email protected]>

---------

Co-authored-by: Plamen Kokanov <[email protected]>
  • Loading branch information
vpnachev and plkokanov authored Apr 2, 2024
1 parent db926a0 commit ce45abb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .ci/pipeline_definitions
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ops-toolbelt:
ocm_repository_mappings:
- repository: europe-docker.pkg.dev/gardener-project/releases
publish:
oci-builder: docker-buildx
platforms:
- linux/amd64
- linux/arm64
dockerimages:
ops-toolbelt:
image: europe-docker.pkg.dev/gardener-project/snapshots/gardener/ops-toolbelt
Expand Down Expand Up @@ -51,6 +55,10 @@ ops-toolbelt:
channel_name: 'C9CEBQPGE' #internal gardener channel
slack_cfg_name: 'scp_workspace'
publish:
oci-builder: docker-buildx
platforms:
- linux/amd64
- linux/arm64
dockerimages:
ops-toolbelt:
image: europe-docker.pkg.dev/gardener-project/releases/gardener/ops-toolbelt
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.vscode
.idea
.DS_Store
generated_dockerfiles
generated_dockerfiles

**/__pycache__/
6 changes: 3 additions & 3 deletions dockerfile-configs/common-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
- name: yaml2json
# renovate: datasource=github-releases depName=bronze1man/yaml2json
version: v1.3
from: https://github.com/bronze1man/yaml2json/releases/download/{version}/yaml2json_linux_amd64
from: https://github.com/bronze1man/yaml2json/releases/download/{version}/yaml2json_linux_$(echo ${{TARGETARCH}} |sed 's/x86_64/amd64/;s/arm64/arm/')
info: transform yaml string to json string without the type infomation.
- name: kubetail
from: https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail
info: Bash script that enables you to aggregate (tail/follow) logs from multiple pods into one stream
- name: nerdctl
# renovate: datasource=github-releases depName=containerd/nerdctl
version: 1.7.5
from: https://github.com/containerd/nerdctl/releases/download/v{version}/nerdctl-{version}-linux-amd64.tar.gz
from: https://github.com/containerd/nerdctl/releases/download/v{version}/nerdctl-{version}-linux-${{TARGETARCH}}.tar.gz
to: /nerdctl.tar.gz
command: |
tar Cxzvvf /usr/local/bin nerdctl.tar.gz &&\
Expand All @@ -66,7 +66,7 @@
- name: kubectl
# renovate: datasource=github-releases depName=kubernetes/kubernetes
version: v1.28.8
from: https://dl.k8s.io/release/{version}/bin/linux/amd64/kubectl
from: https://dl.k8s.io/release/{version}/bin/linux/${{TARGETARCH}}/kubectl
info: command line tool for controlling Kubernetes clusters.

- bash:
Expand Down
1 change: 1 addition & 0 deletions generator/lib/dockerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def create(self):

def to_string(self):
output = self.from_image
output += "ARG TARGETARCH\n"
for layer in self.layers:
output += layer.get_layer_as_string()
return output
Expand Down
6 changes: 5 additions & 1 deletion generator/validate-tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
import subprocess
import shlex
import re

from lib import dockerfile, commands, config_parser

Expand All @@ -15,9 +16,12 @@ def validate_tools(commands_list):
for command in commands_list:
if isinstance(command, commands.Curl):
for tool in command.get_tools():
cmd_line = tool.get_from()
cmd_line = re.sub(r"\$\(echo \${TARGETARCH}.*\)", "amd64", cmd_line)
cmd_line = re.sub(r"\${TARGETARCH}", "amd64", cmd_line)
try:
subprocess.run(
["curl", "-sLf", shlex.quote(tool.get_from())],
["curl", "-sLf", shlex.quote(cmd_line)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True)
Expand Down
6 changes: 4 additions & 2 deletions hacks/install_etcdctl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ function install () {
fi
fi

arch=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')

echo "installing etcdctl version ${version}"
download_url="https://github.com/coreos/etcd/releases/download/${version}/etcd-${version}-linux-amd64.tar.gz"
download_url="https://github.com/coreos/etcd/releases/download/${version}/etcd-${version}-linux-${arch}.tar.gz"

curl -sL ${download_url} -o etcd-${version}-linux-amd64.tar.gz && tar -zxvf etcd-${version}-linux-amd64.tar.gz && mv etcd-${version}-linux-amd64/etcdctl . && rm etcd-${version}-linux-amd64.tar.gz && rm -r etcd-${version}-linux-amd64
curl -sL ${download_url} -o etcd-${version}-linux-${arch}.tar.gz && tar -zxvf etcd-${version}-linux-${arch}.tar.gz && mv etcd-${version}-linux-${arch}/etcdctl . && rm etcd-${version}-linux-${arch}.tar.gz && rm -r etcd-${version}-linux-${arch}


echo "You can now start using etcdctl. Just execute \"etcdctl\" to use it. See https://etcd.io/docs/v3.4/dev-guide/interacting_v3/ for more details."
Expand Down
5 changes: 3 additions & 2 deletions hacks/install_k9s
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ function show_help () {
function install () {
local version=$1
local download_url
local arch=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')

if [ -z "$version" ]
then # fetch latest
local latest_release=$(curl -sL https://api.github.com/repos/derailed/k9s/releases/latest)
version=$(echo "${latest_release}" | jq -r '.tag_name')
echo "installing latest version ${version}"
download_url=$(echo "${latest_release}" | jq -r '.assets[] | select(.name == "k9s_Linux_amd64.tar.gz") | .browser_download_url')
download_url=$(echo "${latest_release}" | jq -r --arg filename "k9s_Linux_${arch}.tar.gz" '.assets[] | select(.name == $filename) | .browser_download_url')
else
if [[ ! $version == v* ]]
then
version="v${version}"
fi
echo "installing k9s version ${version}"
download_url="https://github.com/derailed/k9s/releases/download/${version}/k9s_Linux_amd64.tar.gz"
download_url="https://github.com/derailed/k9s/releases/download/${version}/k9s_Linux_${arch}.tar.gz"
fi

curl -sL ${download_url} -o k9s.tar.gz && tar -zxvf k9s.tar.gz k9s && mv k9s /usr/local/bin/k9s && chmod 755 /usr/local/bin/k9s && rm k9s.tar.gz
Expand Down

0 comments on commit ce45abb

Please sign in to comment.