-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from gman0/multiarch-builds
build: added multi-arch support
- Loading branch information
Showing
3 changed files
with
80 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,9 @@ | |
|
||
BINDIR := $(CURDIR)/bin | ||
DIST_DIRS := find * -type d -exec | ||
TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le windows/amd64 | ||
IMAGE_BUILD_TOOL ?= docker | ||
TARGETS ?= linux/amd64 linux/arm64 | ||
IMAGE_BUILD_TOOL ?= podman | ||
GOX_PARALLEL ?= 3 | ||
|
||
GOPATH = $(shell go env GOPATH) | ||
GOX = $(GOPATH)/bin/gox | ||
|
@@ -61,14 +62,26 @@ endif | |
LDFLAGS += -X ${BASE_PKG}/internal/version.commit=${GIT_COMMIT} | ||
LDFLAGS += -X ${BASE_PKG}/internal/version.treestate=${GIT_DIRTY} | ||
|
||
IMAGE_TAG := ${GIT_BRANCH} | ||
ifneq ($(GIT_TAG),) | ||
IMAGE_TAG = ${GIT_TAG} | ||
endif | ||
|
||
ARCH := $(shell uname -m) | ||
ifeq ($(ARCH),x86_64) | ||
LOCAL_TARGET=linux/amd64 | ||
else ifeq ($(ARCH),arm64) | ||
LOCAL_TARGET=linux/arm64 | ||
endif | ||
|
||
.PHONY: all | ||
all: build | ||
|
||
# ------------------------------------------------------------------------------ | ||
# build | ||
|
||
.PHONY: build | ||
build: $(BINDIR)/csi-cvmfsplugin $(BINDIR)/automount-runner $(BINDIR)/singlemount-runner | ||
build: TARGETS = $(LOCAL_TARGET) | ||
build: build-cross | ||
|
||
$(BINDIR)/csi-cvmfsplugin: $(SRC) | ||
go build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/csi-cvmfsplugin | ||
|
@@ -79,98 +92,34 @@ $(BINDIR)/automount-runner: $(SRC) | |
$(BINDIR)/singlemount-runner: $(SRC) | ||
go build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/singlemount-runner | ||
|
||
.PHONY: build-cross | ||
build-cross: LDFLAGS += -extldflags "-static" | ||
build-cross: $(GOX) $(SRC) | ||
CGO_ENABLED=0 $(GOX) -parallel=$(GOX_PARALLEL) -output="$(BINDIR)/{{.OS}}-{{.Arch}}/csi-cvmfsplugin" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/csi-cvmfsplugin | ||
CGO_ENABLED=0 $(GOX) -parallel=$(GOX_PARALLEL) -output="$(BINDIR)/{{.OS}}-{{.Arch}}/automount-runner" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/automount-runner | ||
CGO_ENABLED=0 $(GOX) -parallel=$(GOX_PARALLEL) -output="$(BINDIR)/{{.OS}}-{{.Arch}}/singlemount-runner" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/singlemount-runner | ||
|
||
# ------------------------------------------------------------------------------ | ||
# test | ||
|
||
.PHONY: test | ||
test: build | ||
test: TESTFLAGS += -race -v | ||
test: test-style | ||
test: test-unit | ||
|
||
.PHONY: test-unit | ||
test-unit: | ||
@echo | ||
@echo "==> Running unit tests <==" | ||
go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS) | ||
|
||
.PHONY: test-coverage | ||
test-coverage: | ||
@echo | ||
@echo "==> Running unit tests with coverage <==" | ||
@ ./scripts/coverage.sh | ||
|
||
.PHONY: test-style | ||
test-style: | ||
golangci-lint run | ||
@scripts/validate-license.sh | ||
|
||
.PHONY: coverage | ||
coverage: | ||
@scripts/coverage.sh | ||
|
||
.PHONY: format | ||
format: $(GOIMPORTS) | ||
go list -f '{{.Dir}}' ./... | xargs $(GOIMPORTS) -w | ||
# image | ||
|
||
image: build | ||
$(IMAGE_BUILD_TOOL) build \ | ||
--build-arg RELEASE=$(IMAGE_TAG) \ | ||
--build-arg GITREF=$(GIT_COMMIT) \ | ||
--build-arg CREATED=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \ | ||
-t registry.cern.ch/kubernetes/cvmfs-csi:$(IMAGE_TAG) \ | ||
-f ./deployments/docker/Dockerfile . | ||
|
||
# ------------------------------------------------------------------------------ | ||
# dependencies | ||
|
||
$(GOX): | ||
go install github.com/mitchellh/[email protected] | ||
|
||
$(GOIMPORTS): | ||
go install golang.org/x/tools/cmd/[email protected] | ||
|
||
# ------------------------------------------------------------------------------ | ||
# release | ||
|
||
.PHONY: build-cross | ||
build-cross: LDFLAGS += -extldflags "-static" | ||
build-cross: $(GOX) | ||
CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/csi-cvmfsplugin_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/csi-cvmfsplugin | ||
CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/automount-runner_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/automount-runner | ||
CGO_ENABLED=0 $(GOX) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/singlemount-runner_{{.OS}}_{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/singlemount-runner | ||
|
||
.PHONY: dist | ||
dist: | ||
( \ | ||
cd _dist && \ | ||
$(DIST_DIRS) cp ../LICENSE {} \; && \ | ||
$(DIST_DIRS) cp ../README.md {} \; && \ | ||
$(DIST_DIRS) tar -zcf cvmfs-csi-${VERSION}-{}.tar.gz {} \; && \ | ||
$(DIST_DIRS) zip -r cvmfs-csi-${VERSION}-{}.zip {} \; \ | ||
) | ||
|
||
.PHONY: checksum | ||
checksum: | ||
for f in _dist/*.{gz,zip} ; do \ | ||
shasum -a 256 "$${f}" | awk '{print $$1}' > "$${f}.sha256" ; \ | ||
done | ||
|
||
.PHONY: changelog | ||
changelog: | ||
@./scripts/changelog.sh | ||
|
||
# ------------------------------------------------------------------------------ | ||
# docker | ||
DOCKER_TAG=${GIT_BRANCH} | ||
ifneq ($(GIT_TAG),) | ||
DOCKER_TAG = ${GIT_TAG} | ||
endif | ||
|
||
.PHONY: image | ||
image: build-cross | ||
mkdir -p bin | ||
cp _dist/linux-amd64/csi-cvmfsplugin_linux_amd64 bin/csi-cvmfsplugin | ||
cp _dist/linux-amd64/automount-runner_linux_amd64 bin/automount-runner | ||
cp _dist/linux-amd64/singlemount-runner_linux_amd64 bin/singlemount-runner | ||
sudo $(IMAGE_BUILD_TOOL) build -t cvmfs-csi:${DOCKER_TAG} -f deployments/docker/Dockerfile . | ||
|
||
# ------------------------------------------------------------------------------ | ||
.PHONY: clean | ||
clean: | ||
@rm -rf $(BINDIR) ./_dist | ||
@rm -rf $(BINDIR) | ||
|
||
.PHONY: info | ||
info: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
FROM registry.access.redhat.com/ubi9/ubi:latest | ||
FROM registry.access.redhat.com/ubi9/ubi:9.2-489 | ||
|
||
LABEL description="CernVM-FS CSI Plugin" | ||
RUN dnf install -y \ | ||
# selinux-policy is a dependency of the cvmfs package. | ||
# When installing cvmfs on aarch64, an older version of selinux-policy | ||
# package is selected for installation which then results in 404. | ||
# As a temporary workaround we install it explicitly until this is fixed. | ||
selinux-policy \ | ||
http://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest.noarch.rpm \ | ||
&& dnf --setopt=install_weak_deps=False install -y cvmfs \ | ||
&& dnf --enablerepo=* clean all && rm -rf /var/cache/yum /var/cache/dnf | ||
|
||
RUN dnf install -y http://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest.noarch.rpm && \ | ||
dnf --setopt=install_weak_deps=False install -y cvmfs && dnf --enablerepo=* clean all && rm -rf /var/cache/yum /var/cache/dnf | ||
ARG TARGETARCH | ||
ARG RELEASE | ||
ARG GITREF | ||
ARG CREATED | ||
|
||
COPY bin/csi-cvmfsplugin /csi-cvmfsplugin | ||
COPY bin/automount-runner /automount-runner | ||
COPY bin/singlemount-runner /singlemount-runner | ||
LABEL org.opencontainers.image.title="cvmfs-csi" \ | ||
org.opencontainers.image.description="The CernVM-FS CSI image contains tools for exposing CVMFS repositories through Container Storage Interface." \ | ||
org.opencontainers.image.authors="CernVM-FS CSI authors" \ | ||
org.opencontainers.image.vendor="CernVM-FS CSI authors" \ | ||
org.opencontainers.image.licenses="Apache-2.0" \ | ||
org.opencontainers.image.documentation="https://github.com/cvmfs-contrib/cvmfs-csi" \ | ||
org.opencontainers.image.source="https://github.com/cvmfs-contrib/cvmfs-csi" \ | ||
org.opencontainers.image.url="https://github.com/cvmfs-contrib/cvmfs-csi" \ | ||
org.opencontainers.image.revision=${GITREF} \ | ||
org.opencontainers.image.version=${RELEASE} \ | ||
org.opencontainers.image.created=${CREATED} \ | ||
org.opencontainers.image.ref.name="" \ | ||
org.opencontainers.image.base.digest="" \ | ||
org.opencontainers.image.base.name="" | ||
|
||
RUN chmod +x /csi-cvmfsplugin /automount-runner /singlemount-runner | ||
COPY bin/linux-${TARGETARCH}/csi-cvmfsplugin /csi-cvmfsplugin | ||
COPY bin/linux-${TARGETARCH}/automount-runner /automount-runner | ||
COPY bin/linux-${TARGETARCH}/singlemount-runner /singlemount-runner |