Skip to content

Commit

Permalink
build an additional init image
Browse files Browse the repository at this point in the history
so that we are able to remove shell from main image eventually
  • Loading branch information
huww98 committed Mar 21, 2024
1 parent 002002b commit ebbe6dd
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 42 deletions.
28 changes: 14 additions & 14 deletions build/build-all-multi.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash
set -ex
REPO_NAME=$2

if [ "$REPO_NAME" == "" ]; then
REPO_NAME="kubernetes-sigs"
fi
BUILD_ARGS=( \
--frontend dockerfile.v0 \
--local context=. \
--local dockerfile=build/multi \
--opt filename=Dockerfile.multi \
--opt platform=linux/amd64,linux/arm64 \
--opt build-arg:CSI_VERSION=$(git describe --tags --always --dirty)
)
BUILD_ARGS+=("$@")

cd ${GOPATH}/src/github.com/$REPO_NAME/alibaba-cloud-csi-driver/
GIT_SHA=`git rev-parse --short HEAD || echo "HEAD"`


VERSION="v1.16.9"
# GIT_HASH=`git rev-parse --short HEAD || echo "HEAD"`
# GIT_BRANCH=`git symbolic-ref --short -q HEAD`
# BUILD_TIME=`date +%FT%T%z`

docker buildx build --platform linux/amd64,linux/arm64 . -f ./build/multi/Dockerfile.multi
buildctl build "${BUILD_ARGS[@]}" \
--output type=image,name=alibaba-cloud-csi-driver:latest
buildctl build "${BUILD_ARGS[@]}" \
--opt target=init \
--output type=image,name=alibaba-cloud-csi-driver:latest-init
7 changes: 1 addition & 6 deletions build/lib/amd64-entrypoint.sh → build/lib/amd64-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

# skip all the setup if running in provisioner mode
if [ "$SERVICE_TYPE" = "provisioner" ]; then
echo "Starting provisioner..."
/bin/plugin.csi.alibabacloud.com $@
exit $?
exit 0
fi

run_oss="false"
Expand Down Expand Up @@ -296,6 +294,3 @@ fi

# place it here to remove leftover from previous version
rm -rf /host/etc/csi-tool/*.rpm

# start daemon
/bin/plugin.csi.alibabacloud.com $@
8 changes: 1 addition & 7 deletions build/lib/arm64-entrypoint.sh → build/lib/arm64-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

# skip all the setup if running in provisioner mode
if [ "$SERVICE_TYPE" = "provisioner" ]; then
echo "Starting provisioner..."
/bin/plugin.csi.alibabacloud.com $@
exit $?
exit 0
fi

run_oss="false"
Expand Down Expand Up @@ -217,7 +215,3 @@ if ([ "$DISK_BDF_ENABLE" = "true" ] && [ "$run_disk" = "true" ]) || [ "$run_pov"
fi
fi
fi


# start daemon
/bin/plugin.csi.alibabacloud.com $@
22 changes: 14 additions & 8 deletions build/multi/Dockerfile.multi
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,35 @@ RUN --mount=type=bind,target=. \
go build -o /out/csiplugin-connector ./build/lib/csiplugin-connector.go


FROM registry.eu-west-1.aliyuncs.com/acs/alinux:3-update
FROM registry.eu-west-1.aliyuncs.com/acs/alinux:3-update as base
LABEL maintainers="Alibaba Cloud Authors" description="Alibaba Cloud CSI Plugin"

RUN yum install -y ca-certificates file tzdata nfs-utils xfsprogs e4fsprogs pciutils iputils strace cloud-utils-growpart gdisk nc telnet tar cpio && \
yum clean all
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone

ARG TARGETARCH
RUN --mount=type=bind,source=build/lib,target=/csi-lib \
cp /csi-lib/$TARGETARCH-nsenter /usr/bin/nsenter && \
ln -s /usr/bin/nsenter /nsenter

FROM base as init

ARG TARGETARCH
WORKDIR /root
RUN if [[ $TARGETARCH == "amd64" ]]; then \
curl -O https://aliyun-alinas-eac.oss-cn-beijing.aliyuncs.com/alinas-efc-1.2-3.x86_64.rpm && \
curl -O https://aliyun-encryption.oss-cn-beijing.aliyuncs.com/aliyun-alinas-utils-1.1-8.al7.noarch.rpm; \
fi
RUN --mount=type=bind,source=build/lib,target=/csi-lib \
cp /csi-lib/$TARGETARCH-nsenter /usr/bin/nsenter && \
ln -s /usr/bin/nsenter /nsenter && \
cp /csi-lib/$TARGETARCH-entrypoint.sh /entrypoint.sh && \
chmod +x /entrypoint.sh && \
cp /csi-lib/$TARGETARCH-init.sh /init.sh && \
chmod +x /init.sh && \
cp /csi-lib/freezefs.sh /freezefs.sh && \
mkdir /csi && \
cp /csi-lib/csiplugin-connector.service /csi/csiplugin-connector.service
COPY --link --from=build /out/csiplugin-connector /csi/csiplugin-connector
COPY --link --from=build /out/plugin.csi.alibabacloud.com /usr/bin/plugin.csi.alibabacloud.com

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/init.sh"]

FROM base
COPY --link --from=build /out/plugin.csi.alibabacloud.com /usr/bin/plugin.csi.alibabacloud.com
ENTRYPOINT ["/usr/bin/plugin.csi.alibabacloud.com"]
26 changes: 24 additions & 2 deletions deploy/ecs/csi-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ spec:
hostIPC: true
hostPID: true
dnsPolicy: ClusterFirst
initContainers:
- name: init
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-plugin:v1.26.4-e7e52e9-init
args:
- --driver=oss,nas,disk
securityContext:
privileged: true
allowPrivilegeEscalation: true
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 1024Mi
volumeMounts:
- name: etc
mountPath: /host/etc
- name: csi-plugin-cm
mountPath: /etc/csi-plugin/config
- name: host-log
mountPath: /var/log/
- name: ossconnectordir
mountPath: /host/usr/
containers:
- name: disk-driver-registrar
image: registry-cn-hangzhou.ack.aliyuncs.com/acs/csi-node-driver-registrar:v2.3.1-038aeb6-aliyun
Expand Down Expand Up @@ -150,8 +174,6 @@ spec:
mountPath: /host/etc
- name: host-log
mountPath: /var/log/
- name: ossconnectordir
mountPath: /host/usr/
- name: container-dir
mountPath: /var/lib/container
mountPropagation: "Bidirectional"
Expand Down
26 changes: 24 additions & 2 deletions deploy/nonecs/csi-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ spec:
hostIPC: true
hostPID: true
dnsPolicy: ClusterFirst
initContainers:
- name: init
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-plugin:v1.26.4-e7e52e9-init
args:
- --driver=oss,nas,disk
securityContext:
privileged: true
allowPrivilegeEscalation: true
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 1024Mi
volumeMounts:
- name: etc
mountPath: /host/etc
- name: csi-plugin-cm
mountPath: /etc/csi-plugin/config
- name: host-log
mountPath: /var/log/
- name: ossconnectordir
mountPath: /host/usr/
containers:
- name: nas-driver-registrar
image: registry-cn-hangzhou.ack.aliyuncs.com/acs/csi-node-driver-registrar:v2.3.1-038aeb6-aliyun
Expand Down Expand Up @@ -134,8 +158,6 @@ spec:
mountPath: /host/etc
- name: host-log
mountPath: /var/log/
- name: ossconnectordir
mountPath: /host/usr/
- name: container-dir
mountPath: /var/lib/container
mountPropagation: "Bidirectional"
Expand Down
27 changes: 24 additions & 3 deletions test/csi-sanity/csi-sanity-disk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,33 @@ spec:
- name: csi-test-config
configMap:
name: csi-test-config
initContainers:
- name: init
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-plugin:v1.26.4-e7e52e9-init
args:
- --driver=disk
securityContext:
privileged: true
allowPrivilegeEscalation: true
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "1Gi"
cpu: "500m"
volumeMounts:
- mountPath: /host/etc
name: etc
- mountPath: /host/usr/
name: ossconnectordir
containers:
- name: csi-testing
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-plugin:v1.26.4-e7e52e9-aliyun
args: [--endpoint=unix://var/lib/kubelet/csi-sanity/csi.sock --v=2 --driver=disk]
args:
- --endpoint=unix://var/lib/kubelet/csi-sanity/csi.sock
- --v=2
- --driver=disk
resources:
requests:
memory: "128Mi"
Expand Down Expand Up @@ -156,8 +179,6 @@ spec:
volumeMounts:
- mountPath: /host/etc
name: etc
- mountPath: /host/usr/
name: ossconnectordir
- mountPath: /host/run/csi-tool
name: run-csi
- mountPath: /dev
Expand Down

0 comments on commit ebbe6dd

Please sign in to comment.