Skip to content

Commit

Permalink
Merge pull request #4 from twz123/bump-to-1.3.0
Browse files Browse the repository at this point in the history
Bump cni-plugins to v1.3.0 and use Alpine 3.18.4
  • Loading branch information
twz123 authored Oct 4, 2023
2 parents 7a1fc12 + b8e9928 commit 595df9c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
*
!src/
51 changes: 40 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
FROM alpine:3.17
ARG \
ALPINE_IMAGE=docker.io/library/alpine:3.18.4 \
GOLANG_IMAGE=docker.io/library/golang:1.20.8-alpine \
VERSION=1.3.0 \
HASH=f9871b9f6ccb51d2b264532e96521e44f926928f91434b56ce135c95becf2901

FROM --platform=$BUILDPLATFORM $GOLANG_IMAGE as bins
ARG VERSION HASH

RUN wget https://github.com/containernetworking/plugins/archive/refs/tags/v${VERSION}.tar.gz \
&& { echo "${HASH} *v${VERSION}.tar.gz" | sha256sum -c -; } \
&& tar xf "v${VERSION}.tar.gz" -C /go \
&& rm -- "v${VERSION}.tar.gz"

WORKDIR /go/plugins-$VERSION
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG CNI_PLUGINS_VERSION=v1.1.1
RUN set -x \
&& apk add bash \
&& mkdir -p /opt/stage/usr/local/bin \
&& case "${TARGETPLATFORM-~}" in \
linux/amd64) export GOARCH=amd64 ;; \
linux/arm64) export GOARCH=arm64 ;; \
linux/arm/v7) export GOARCH=arm ;; \
linux/riscv64) export GOARCH=riscv64 ;; \
~);; \
*) echo Unsupported target platform: "$TARGETPLATFORM" >&2; exit 1;; \
esac \
&& CGO_ENABLED=0 ./build_linux.sh -trimpath -buildvcs=false \
-ldflags "-s -w -extldflags -static -X github.com/containernetworking/plugins/pkg/utils/buildversion.BuildVersion=v$VERSION"


FROM $ALPINE_IMAGE as busybox
RUN apk add busybox-static

RUN apk upgrade --no-cache --update && \
apk add --no-cache gettext curl

RUN mkdir -p /opt/cni/bin
FROM $ALPINE_IMAGE as baselayout
COPY --from=busybox /bin/busybox.static /bin/busybox
RUN /bin/busybox --install
COPY src/cni-node /bin/cni-node

RUN case $(uname -m) in amd64|x86_64) TARGET="amd64" ;; arm64|aarch64) TARGET="arm64" ;; armv7l) TARGET="arm" ;; esac && \
curl -o cni.tgz -sSLf "https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${TARGET}-${CNI_PLUGINS_VERSION}.tgz" && \
tar zxvf cni.tgz -C /opt/cni/bin && \
rm -rf cni.tgz

COPY src /bin
FROM scratch
COPY --from=baselayout / /
ARG VERSION
COPY --from=bins /go/plugins-$VERSION/bin/ /opt/cni/bin/
ENTRYPOINT ["/bin/cni-node"]
CMD ["install"]
52 changes: 25 additions & 27 deletions src/cni-node
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
#!/bin/sh
#!/usr/bin/env sh

set -ex

function main {
local action="$1"

case "${action}" in
install)
installBins
;;
list)
ls -1 /opt/cni/bin
;;
*)
usage
;;
esac
main() {
case "$1" in
install)
installBins
;;
list)
ls -1 /opt/cni/bin
;;
*)
usage
;;
esac
}

function usage {
set +x
echo "/bin/cni-node <action>"
echo "Actions:"
echo " install - install cni bin plugins"
echo " list - lists current cni bin plugins"
usage() {
set +x
echo "/bin/cni-node <action>"
echo "Actions:"
echo " install - install cni bin plugins"
echo " list - lists current cni bin plugins"
}

# installs ALL baked-in cni bins into /host/opt/cni/bin directory
function installBins {
echo "Installing CNI plugins..."
mkdir -p "/host/opt/cni/bin"
install /opt/cni/bin/* /host/opt/cni/bin/
echo "...done"
installBins() {
echo "Installing CNI plugins..."
mkdir -p "/host/opt/cni/bin"
install /opt/cni/bin/* /host/opt/cni/bin/
echo "...done"
}

main "$@"
main "$@"

0 comments on commit 595df9c

Please sign in to comment.