Skip to content

Packaging supports arm64 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
/docker/plugin.storage.qiniu.com
/docker/kodofs
/docker/rclone
/docker/*/kodofs
/docker/*/rclone
/k8s/kodo.yaml
/k8s/kodofs.yaml

Expand Down
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# 1. 第一阶段,编译二进制可执行文件
FROM golang:1.21-alpine3.18 as build-env

ARG TARGETOS
ARG TARGETARCH

COPY . /app
WORKDIR /app
# 安装依赖
RUN apk add --no-cache git make

# 编译二进制可执行文件
RUN make build
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build

# 2. 第二阶段,构建最终镜像
FROM alpine:3.18

ARG TARGETOS
ARG TARGETARCH
ARG PLUGIN_FILENAME=plugin.storage.qiniu.com
ARG CONNECTOR_FILENAME=connector.${PLUGIN_FILENAME}

Expand All @@ -20,9 +25,8 @@ COPY --from=build-env /app/plugin/${PLUGIN_FILENAME} /usr/local/bin/${PLUGIN_FIL
COPY --from=build-env /app/connector/${CONNECTOR_FILENAME} /usr/local/bin/${CONNECTOR_FILENAME}

# 这些文件直接由仓库提供
COPY docker/nsenter /usr/local/bin/nsenter
COPY docker/kodofs /usr/local/bin/kodofs
COPY docker/rclone /usr/local/bin/rclone
COPY docker/${TARGETARCH}/kodofs /usr/local/bin/kodofs
COPY docker/${TARGETARCH}/rclone /usr/local/bin/rclone
COPY docker/kodo-csi-connector.service /csiplugin-connector.service
COPY docker/entrypoint.sh /entrypoint.sh

Expand All @@ -33,6 +37,6 @@ RUN chmod +x /usr/local/bin/kodofs \
/usr/local/bin/${CONNECTOR_FILENAME} \
/entrypoint.sh

RUN apk add --no-cache ca-certificates bash
RUN apk add util-linux --no-cache ca-certificates bash

ENTRYPOINT ["/entrypoint.sh"]
52 changes: 36 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,56 @@ install_plugins: install_kodo_csi_driver install_kodofs_csi_driver
.PHONY: delete_plugins
delete_plugins: delete_kodo_csi_driver delete_kodofs_csi_driver

.PHONY: docker/rclone
docker/rclone:
.PHONY: download-rclone
download-rclone:
# 下载 amd64 版本
curl -LJO# https://github.com/rclone/rclone/releases/download/$(RCLONE_VERSION)/rclone-$(RCLONE_VERSION)-linux-amd64.zip
unzip rclone-$(RCLONE_VERSION)-linux-amd64.zip
mv rclone-$(RCLONE_VERSION)-linux-amd64/rclone docker/rclone
chmod +x docker/rclone
[ -f "docker/amd64/rclone" ] && rm docker/amd64/rclone || :
mv rclone-$(RCLONE_VERSION)-linux-amd64/rclone docker/amd64/rclone
chmod +x docker/amd64/rclone
rm rclone-$(RCLONE_VERSION)-linux-amd64.zip
rm -rf rclone-$(RCLONE_VERSION)-linux-amd64

# 下载 arm64 版本
curl -LJO# https://github.com/rclone/rclone/releases/download/$(RCLONE_VERSION)/rclone-$(RCLONE_VERSION)-linux-arm64.zip
unzip rclone-$(RCLONE_VERSION)-linux-arm64.zip
[ -f "docker/arm64/rclone" ] && rm docker/arm64/rclone || :
mv rclone-$(RCLONE_VERSION)-linux-arm64/rclone docker/arm64/rclone
chmod +x docker/arm64/rclone
rm rclone-$(RCLONE_VERSION)-linux-arm64.zip
rm -rf rclone-$(RCLONE_VERSION)-linux-arm64

# 下载kodofs二进制文件,由于kodofs是私有仓库,所以需要携带 Github API Token 才能下载
.PHONY: docker/kodofs
docker/kodofs:
.PHONY: download-kodofs
download-kodofs:
@if [ -z $$GITHUB_API_TOKEN ];\
then \
echo "Please configure environment GITHUB_API_TOKEN"; \
exit 1; \
fi
# 下载 arm64
[ -f "scripts/kodofs_linux_arm64" ] && rm scripts/kodofs_linux_arm64 || :
cd scripts && bash get_gh_asset.sh qbox kodofs $(KODOFS_VERSION) kodofs_linux_arm64
[ -f "docker/arm64/kodofs" ] && rm docker/arm64/kodofs || :
mv scripts/kodofs_linux_arm64 docker/arm64/kodofs
chmod +x docker/arm64/kodofs
# 下载 amd64
[ -f "scripts/kodofs" ] && rm scripts/kodofs || :
cd scripts && bash get_gh_asset.sh qbox kodofs $(KODOFS_VERSION) kodofs
mv scripts/kodofs docker/kodofs
chmod +x docker/kodofs

.PHONY: build_image
build_image: docker/rclone docker/kodofs
docker build --pull \
-t="$(DOCKERHUB_ORGANIZATION)/$(DOCKERHUB_IMAGE):$(VERSION)" \
-f Dockerfile .
[ -f "docker/amd64/kodofs" ] && rm docker/amd64/kodofs || :
mv scripts/kodofs docker/amd64/kodofs
chmod +x docker/amd64/kodofs

.PHONY: push_image
push_image: build_image
docker push "$(DOCKERHUB_ORGANIZATION)/$(DOCKERHUB_IMAGE):$(VERSION)"
push_image: docker/rclone docker/kodofs
docker buildx create --name=CSIBuilder --driver docker-container --platform linux/amd64,linux/arm64
docker buildx build --push \
--builder CSIBuilder \
--platform linux/amd64,linux/arm64 \
-t "$(DOCKERHUB_ORGANIZATION)/$(DOCKERHUB_IMAGE):$(VERSION)" \
-f Dockerfile \
.

.PHONY: install_kodo_static_example
install_kodo_static_example: k8s/kodo.yaml
Expand Down
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

HOST_CMD="/usr/local/bin/nsenter --all --target 1 --"
HOST_CMD="nsenter --all --target 1 --"

rm -f /host/usr/local/bin/kodofs /host/usr/local/bin/connector.plugin.storage.qiniu.com /host/usr/local/bin/rclone
cp /usr/local/bin/kodofs /host/usr/local/bin/kodofs
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_gh_asset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or
# Read asset tags.
response=$(curl -sH "$AUTH" $GH_TAGS)
# Get ID of the asset based on given name.
eval $(echo "$response" | grep -C3 "name.:.\+$name" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
eval $(echo "$response" | grep -C3 "name.:.\+$name\"" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
# id=$(echo "$response" | jq --arg name "$name" '.assets[] | select(.name == $name).id') # If jq is installed, this can be used instead.
[ "$id" ] || { echo "Error: Failed to get asset id, response: $response" | awk 'length($0)<100' >&2; exit 1; }
GH_ASSET="$GH_REPO/releases/assets/$id"
Expand Down