Skip to content

Commit c38b560

Browse files
authored
Merge pull request #97 from gman0/cherrypick-96
build: added multi-arch support Cherry-pick 86a74df (#96).
2 parents 9ce6c3d + 84a8b55 commit c38b560

File tree

3 files changed

+80
-103
lines changed

3 files changed

+80
-103
lines changed

.gitlab-ci.yml

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
include:
22
- project: 'ci-tools/container-image-ci-templates'
3-
file: 'kaniko-image.gitlab-ci.yml'
3+
file: 'docker-image.gitlab-ci.yml'
44
ref: master
55
- project: 'ci-tools/container-image-ci-templates'
66
file: 'helm.gitlab-ci.yml'
77
ref: master
88

99
stages:
10-
- build-bin
11-
- build-image
12-
- build-chart
10+
- build-bin
11+
- build-image
12+
- build-chart
1313

1414
build-bin:
1515
stage: build-bin
1616
rules:
17-
- if: $CI_COMMIT_BRANCH || $CI_COMMIT_TAG
17+
- if: $CI_COMMIT_BRANCH || $CI_COMMIT_TAG
1818
image: registry.cern.ch/docker.io/library/golang:1.20
1919
artifacts:
20-
expire_in: '10 minutes'
20+
expire_in: '10 min'
2121
paths:
22-
- bin/
22+
- bin/
2323
script:
24-
- make
24+
- make build-cross
2525

2626
build-image:
2727
rules:
2828
- if: $CI_COMMIT_TAG
2929
variables:
3030
PUSH_IMAGE: "true"
31+
IMAGE_TAG: $CI_COMMIT_TAG
3132
- if: $CI_COMMIT_BRANCH
33+
variables:
34+
IMAGE_TAG: $CI_COMMIT_BRANCH
3235
stage: build-image
33-
extends: .build_kaniko
36+
extends: .build_docker
3437
variables:
35-
REGISTRY_IMAGE_PATH: "registry.cern.ch/magnum/cvmfs-csi:$CI_COMMIT_TAG"
38+
REGISTRY_IMAGE_PATH: "registry.cern.ch/kubernetes/cvmfs-csi:$IMAGE_TAG"
3639
CONTEXT_DIR: "."
3740
DOCKER_FILE_NAME: "deployments/docker/Dockerfile"
41+
PLATFORMS: "linux/amd64,linux/arm64"
42+
BUILD_ARGS: "RELEASE=$IMAGE_TAG GITREF=$CI_COMMIT_SHA CREATED=$CI_PIPELINE_CREATED_AT"
3843

3944
build-chart:
4045
rules:

Makefile

+34-85
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
BINDIR := $(CURDIR)/bin
2020
DIST_DIRS := find * -type d -exec
21-
TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le windows/amd64
22-
IMAGE_BUILD_TOOL ?= docker
21+
TARGETS ?= linux/amd64 linux/arm64
22+
IMAGE_BUILD_TOOL ?= podman
23+
GOX_PARALLEL ?= 3
2324

2425
GOPATH = $(shell go env GOPATH)
2526
GOX = $(GOPATH)/bin/gox
@@ -61,14 +62,26 @@ endif
6162
LDFLAGS += -X ${BASE_PKG}/internal/version.commit=${GIT_COMMIT}
6263
LDFLAGS += -X ${BASE_PKG}/internal/version.treestate=${GIT_DIRTY}
6364

65+
IMAGE_TAG := ${GIT_BRANCH}
66+
ifneq ($(GIT_TAG),)
67+
IMAGE_TAG = ${GIT_TAG}
68+
endif
69+
70+
ARCH := $(shell uname -m)
71+
ifeq ($(ARCH),x86_64)
72+
LOCAL_TARGET=linux/amd64
73+
else ifeq ($(ARCH),arm64)
74+
LOCAL_TARGET=linux/arm64
75+
endif
76+
6477
.PHONY: all
6578
all: build
6679

6780
# ------------------------------------------------------------------------------
6881
# build
6982

70-
.PHONY: build
71-
build: $(BINDIR)/csi-cvmfsplugin $(BINDIR)/automount-runner $(BINDIR)/singlemount-runner
83+
build: TARGETS = $(LOCAL_TARGET)
84+
build: build-cross
7285

7386
$(BINDIR)/csi-cvmfsplugin: $(SRC)
7487
go build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/csi-cvmfsplugin
@@ -79,98 +92,34 @@ $(BINDIR)/automount-runner: $(SRC)
7992
$(BINDIR)/singlemount-runner: $(SRC)
8093
go build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/singlemount-runner
8194

95+
.PHONY: build-cross
96+
build-cross: LDFLAGS += -extldflags "-static"
97+
build-cross: $(GOX) $(SRC)
98+
CGO_ENABLED=0 $(GOX) -parallel=$(GOX_PARALLEL) -output="$(BINDIR)/{{.OS}}-{{.Arch}}/csi-cvmfsplugin" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/csi-cvmfsplugin
99+
CGO_ENABLED=0 $(GOX) -parallel=$(GOX_PARALLEL) -output="$(BINDIR)/{{.OS}}-{{.Arch}}/automount-runner" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/automount-runner
100+
CGO_ENABLED=0 $(GOX) -parallel=$(GOX_PARALLEL) -output="$(BINDIR)/{{.OS}}-{{.Arch}}/singlemount-runner" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/singlemount-runner
101+
82102
# ------------------------------------------------------------------------------
83-
# test
84-
85-
.PHONY: test
86-
test: build
87-
test: TESTFLAGS += -race -v
88-
test: test-style
89-
test: test-unit
90-
91-
.PHONY: test-unit
92-
test-unit:
93-
@echo
94-
@echo "==> Running unit tests <=="
95-
go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS)
96-
97-
.PHONY: test-coverage
98-
test-coverage:
99-
@echo
100-
@echo "==> Running unit tests with coverage <=="
101-
@ ./scripts/coverage.sh
102-
103-
.PHONY: test-style
104-
test-style:
105-
golangci-lint run
106-
@scripts/validate-license.sh
107-
108-
.PHONY: coverage
109-
coverage:
110-
@scripts/coverage.sh
111-
112-
.PHONY: format
113-
format: $(GOIMPORTS)
114-
go list -f '{{.Dir}}' ./... | xargs $(GOIMPORTS) -w
103+
# image
104+
105+
image: build
106+
$(IMAGE_BUILD_TOOL) build \
107+
--build-arg RELEASE=$(IMAGE_TAG) \
108+
--build-arg GITREF=$(GIT_COMMIT) \
109+
--build-arg CREATED=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
110+
-t registry.cern.ch/kubernetes/cvmfs-csi:$(IMAGE_TAG) \
111+
-f ./deployments/docker/Dockerfile .
115112

116113
# ------------------------------------------------------------------------------
117114
# dependencies
118115

119116
$(GOX):
120117
go install github.com/mitchellh/[email protected]
121118

122-
$(GOIMPORTS):
123-
go install golang.org/x/tools/cmd/[email protected]
124-
125-
# ------------------------------------------------------------------------------
126-
# release
127-
128-
.PHONY: build-cross
129-
build-cross: LDFLAGS += -extldflags "-static"
130-
build-cross: $(GOX)
131-
CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/csi-cvmfsplugin_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/csi-cvmfsplugin
132-
CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/automount-runner_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/automount-runner
133-
CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/singlemount-runner_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/singlemount-runner
134-
135-
.PHONY: dist
136-
dist:
137-
( \
138-
cd _dist && \
139-
$(DIST_DIRS) cp ../LICENSE {} \; && \
140-
$(DIST_DIRS) cp ../README.md {} \; && \
141-
$(DIST_DIRS) tar -zcf cvmfs-csi-${VERSION}-{}.tar.gz {} \; && \
142-
$(DIST_DIRS) zip -r cvmfs-csi-${VERSION}-{}.zip {} \; \
143-
)
144-
145-
.PHONY: checksum
146-
checksum:
147-
for f in _dist/*.{gz,zip} ; do \
148-
shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256" ; \
149-
done
150-
151-
.PHONY: changelog
152-
changelog:
153-
@./scripts/changelog.sh
154-
155-
# ------------------------------------------------------------------------------
156-
# docker
157-
DOCKER_TAG=${GIT_BRANCH}
158-
ifneq ($(GIT_TAG),)
159-
DOCKER_TAG = ${GIT_TAG}
160-
endif
161-
162-
.PHONY: image
163-
image: build-cross
164-
mkdir -p bin
165-
cp _dist/linux-amd64/csi-cvmfsplugin_linux_amd64 bin/csi-cvmfsplugin
166-
cp _dist/linux-amd64/automount-runner_linux_amd64 bin/automount-runner
167-
cp _dist/linux-amd64/singlemount-runner_linux_amd64 bin/singlemount-runner
168-
sudo $(IMAGE_BUILD_TOOL) build -t cvmfs-csi:${DOCKER_TAG} -f deployments/docker/Dockerfile .
169-
170119
# ------------------------------------------------------------------------------
171120
.PHONY: clean
172121
clean:
173-
@rm -rf $(BINDIR) ./_dist
122+
@rm -rf $(BINDIR)
174123

175124
.PHONY: info
176125
info:

deployments/docker/Dockerfile

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1-
FROM registry.access.redhat.com/ubi9/ubi:latest
1+
FROM registry.access.redhat.com/ubi9/ubi:9.2-489
22

3-
LABEL description="CernVM-FS CSI Plugin"
3+
RUN dnf install -y \
4+
# selinux-policy is a dependency of the cvmfs package.
5+
# When installing cvmfs on aarch64, an older version of selinux-policy
6+
# package is selected for installation which then results in 404.
7+
# As a temporary workaround we install it explicitly until this is fixed.
8+
selinux-policy \
9+
http://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest.noarch.rpm \
10+
&& dnf --setopt=install_weak_deps=False install -y cvmfs \
11+
&& dnf --enablerepo=* clean all && rm -rf /var/cache/yum /var/cache/dnf
412

5-
RUN dnf install -y http://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest.noarch.rpm && \
6-
dnf --setopt=install_weak_deps=False install -y cvmfs && dnf --enablerepo=* clean all && rm -rf /var/cache/yum /var/cache/dnf
13+
ARG TARGETARCH
14+
ARG RELEASE
15+
ARG GITREF
16+
ARG CREATED
717

8-
COPY bin/csi-cvmfsplugin /csi-cvmfsplugin
9-
COPY bin/automount-runner /automount-runner
10-
COPY bin/singlemount-runner /singlemount-runner
18+
LABEL org.opencontainers.image.title="cvmfs-csi" \
19+
org.opencontainers.image.description="The CernVM-FS CSI image contains tools for exposing CVMFS repositories through Container Storage Interface." \
20+
org.opencontainers.image.authors="CernVM-FS CSI authors" \
21+
org.opencontainers.image.vendor="CernVM-FS CSI authors" \
22+
org.opencontainers.image.licenses="Apache-2.0" \
23+
org.opencontainers.image.documentation="https://github.com/cvmfs-contrib/cvmfs-csi" \
24+
org.opencontainers.image.source="https://github.com/cvmfs-contrib/cvmfs-csi" \
25+
org.opencontainers.image.url="https://github.com/cvmfs-contrib/cvmfs-csi" \
26+
org.opencontainers.image.revision=${GITREF} \
27+
org.opencontainers.image.version=${RELEASE} \
28+
org.opencontainers.image.created=${CREATED} \
29+
org.opencontainers.image.ref.name="" \
30+
org.opencontainers.image.base.digest="" \
31+
org.opencontainers.image.base.name=""
1132

12-
RUN chmod +x /csi-cvmfsplugin /automount-runner /singlemount-runner
33+
COPY bin/linux-${TARGETARCH}/csi-cvmfsplugin /csi-cvmfsplugin
34+
COPY bin/linux-${TARGETARCH}/automount-runner /automount-runner
35+
COPY bin/linux-${TARGETARCH}/singlemount-runner /singlemount-runner

0 commit comments

Comments
 (0)