Skip to content

Commit

Permalink
making more like the csi-nfs make file pass one
Browse files Browse the repository at this point in the history
  • Loading branch information
vamage committed Oct 31, 2024
1 parent bccce0d commit 7003b9b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ RUN apt update && apt upgrade -y && apt-mark unhold libcap2
RUN clean-install util-linux e2fsprogs mount ca-certificates udev xfsprogs btrfs-progs open-iscsi

CMD service iscsid start
COPY ./bin/iscsiplugin /iscsiplugin
ARG ARCH
ARG binary=./bin/${ARCH}/iscsiplugin
COPY ${binary} /iscsiplugin

ENTRYPOINT ["/iscsiplugin"]
73 changes: 68 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@
# limitations under the License.

CMDS=iscsiplugin
all: build
all: iscsi

include release-tools/build.make

GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(GOPATH)/bin
export GOPATH GOBIN

CURRENT_ARCH ?= $(shell go env GOARCH)
REGISTRY ?= test
IMAGENAME ?= iscsi-csi
# Output type of docker buildx build
OUTPUT_TYPE ?= docker
ARCH ?= amd64
IMAGE_VERSION ?= v0.0.0
IMAGE_TAG = $(REGISTRY)/$(IMAGENAME):$(IMAGE_VERSION)
IMAGE_TAG_LATEST = $(REGISTRY)/$(IMAGENAME):latest

ALL_ARCH.linux = arm64 amd64 ppc64le
ALL_OS_ARCH = linux-arm64 linux-arm-v7 linux-amd64 linux-ppc64le

.EXPORT_ALL_VARIABLES:

.PHONY: test-container
test-container:
make
docker buildx build --pull --output=type=$(OUTPUT_TYPE) --platform="linux/$(ARCH)" \
-t $(IMAGE_TAG) --build-arg ARCH=$(ARCH) .
ARCH=${CURRENT_ARCH} make
docker buildx build --pull --output=type=$(OUTPUT_TYPE) --platform="linux/$(CURRENT_ARCH)" \
-t $(IMAGE_TAG) --build-arg ARCH=$(CURRENT_ARCH) .

.PHONY: sanity-test
sanity-test:
Expand All @@ -46,3 +53,59 @@ mod-check:
clean:
go clean -mod=vendor -r -x
rm -f bin/iscsiplugin
rm -rf bin/*
.PHONY: iscsi
iscsi:
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -a -ldflags "${LDFLAGS} ${EXT_LDFLAGS}" -mod vendor -o bin/${ARCH}/iscsiplugin ./cmd/iscsiplugin

.PHONY: iscsi-armv7
iscsi-armv7:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -ldflags "${LDFLAGS} ${EXT_LDFLAGS}" -mod vendor -o bin/arm/v7/iscsiplugin ./cmd/iscsiplugin

.PHONY: container-build
container-build:
docker buildx build --pull --output=type=$(OUTPUT_TYPE) --platform="linux/$(ARCH)" \
--provenance=false --sbom=false \
-t $(IMAGE_TAG)-linux-$(ARCH) --build-arg ARCH=$(ARCH) .

.PHONY: container-linux-iscsiv7
container-linux-iscsiv7:
docker buildx build --pull --output=type=$(OUTPUT_TYPE) --platform="linux/arm/v7" \
--provenance=false --sbom=false \
-t $(IMAGE_TAG)-linux-arm-v7 --build-arg ARCH=arm/v7 .

.PHONY: container
container:
docker buildx rm container-builder || true
docker buildx create --use --name=container-builder
# enable qemu for arm64 build
# https://github.com/docker/buildx/issues/464#issuecomment-741507760
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64
docker run --rm --privileged tonistiigi/binfmt --install all
for arch in $(ALL_ARCH.linux); do \
ARCH=$${arch} $(MAKE) iscsi; \
ARCH=$${arch} $(MAKE) container-build; \
done
$(MAKE) iscsi-armv7
$(MAKE) container-linux-iscsiv7

.PHONY: push
push:
ifdef CI
docker manifest create --amend $(IMAGE_TAG) $(foreach osarch, $(ALL_OS_ARCH), $(IMAGE_TAG)-${osarch})
docker manifest push --purge $(IMAGE_TAG)
docker manifest inspect $(IMAGE_TAG)
else
docker push $(IMAGE_TAG)
endif

.PHONY: push-latest
push-latest:
ifdef CI
docker manifest create --amend $(IMAGE_TAG_LATEST) $(foreach osarch, $(ALL_OS_ARCH), $(IMAGE_TAG)-${osarch})
docker manifest push --purge $(IMAGE_TAG_LATEST)
docker manifest inspect $(IMAGE_TAG_LATEST)
else
docker tag $(IMAGE_TAG) $(IMAGE_TAG_LATEST)
docker push $(IMAGE_TAG_LATEST)
endif

0 comments on commit 7003b9b

Please sign in to comment.