mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
build: add an option to compile in a container
This makes it possible to build on any platform that supports Linux containers. The container image used for building is created once, or on updating the `scripts/Dockerfile.build` and is cached afterwards. To build the executable in a container, use `make containerized-build` and everything will be done automatically. The executable will also be available on the usual location. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
ae4d269836
commit
7381253ee0
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,9 @@ _output
|
|||||||
# docker build
|
# docker build
|
||||||
deploy/cephcsi/image/cephcsi
|
deploy/cephcsi/image/cephcsi
|
||||||
|
|
||||||
|
# build container
|
||||||
|
.devel-container-id
|
||||||
|
|
||||||
# git merge files
|
# git merge files
|
||||||
*.orig
|
*.orig
|
||||||
*.patch
|
*.patch
|
||||||
|
17
Makefile
17
Makefile
@ -37,6 +37,11 @@ ifeq ($(origin GOARCH), undefined)
|
|||||||
GOARCH := $(shell go env GOARCH)
|
GOARCH := $(shell go env GOARCH)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
SELINUX := $(shell getenforce 2>/dev/null)
|
||||||
|
ifeq ($(SELINUX),Enforcing)
|
||||||
|
SELINUX_VOL_FLAG = :z
|
||||||
|
endif
|
||||||
|
|
||||||
all: cephcsi
|
all: cephcsi
|
||||||
|
|
||||||
test: go-test static-check mod-check
|
test: go-test static-check mod-check
|
||||||
@ -60,6 +65,16 @@ cephcsi:
|
|||||||
if [ ! -d ./vendor ]; then (go mod tidy && go mod vendor); fi
|
if [ ! -d ./vendor ]; then (go mod tidy && go mod vendor); fi
|
||||||
GOOS=linux GOARCH=$(GOARCH) go build -mod vendor -a -ldflags '$(LDFLAGS)' -o _output/cephcsi ./cmd/
|
GOOS=linux GOARCH=$(GOARCH) go build -mod vendor -a -ldflags '$(LDFLAGS)' -o _output/cephcsi ./cmd/
|
||||||
|
|
||||||
|
.PHONY: containerized-build
|
||||||
|
containerized-build: .devel-container-id
|
||||||
|
$(CONTAINER_CMD) run --rm -v $(PWD):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):devel make -C /go/src/github.com/ceph/ceph-csi cephcsi
|
||||||
|
|
||||||
|
# create a (cached) container image with dependencied for building cephcsi
|
||||||
|
.devel-container-id: scripts/Dockerfile.devel
|
||||||
|
[ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel
|
||||||
|
$(CONTAINER_CMD) build -t $(CSI_IMAGE_NAME):devel -f ./scripts/Dockerfile.devel .
|
||||||
|
$(CONTAINER_CMD) inspect -f '{{.Id}}' $(CSI_IMAGE_NAME):devel > .devel-container-id
|
||||||
|
|
||||||
image-cephcsi: cephcsi
|
image-cephcsi: cephcsi
|
||||||
cp _output/cephcsi deploy/cephcsi/image/cephcsi
|
cp _output/cephcsi deploy/cephcsi/image/cephcsi
|
||||||
chmod +x deploy/cephcsi/image/cephcsi
|
chmod +x deploy/cephcsi/image/cephcsi
|
||||||
@ -75,3 +90,5 @@ clean:
|
|||||||
go clean -r -x
|
go clean -r -x
|
||||||
rm -f deploy/cephcsi/image/cephcsi
|
rm -f deploy/cephcsi/image/cephcsi
|
||||||
rm -f _output/cephcsi
|
rm -f _output/cephcsi
|
||||||
|
[ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel
|
||||||
|
$(RM) .devel-container-id
|
||||||
|
@ -36,9 +36,12 @@ it is **highly** encouraged to:
|
|||||||
|
|
||||||
### Building Ceph-CSI
|
### Building Ceph-CSI
|
||||||
|
|
||||||
To build ceph-csi run:
|
To build ceph-csi locally run:
|
||||||
`$ make`
|
`$ make`
|
||||||
|
|
||||||
|
To build ceph-csi in a container:
|
||||||
|
`$ make containerized-build`
|
||||||
|
|
||||||
The built binary will be present under `_output/` directory.
|
The built binary will be present under `_output/` directory.
|
||||||
|
|
||||||
### Code contribution workflow
|
### Code contribution workflow
|
||||||
|
11
scripts/Dockerfile.devel
Normal file
11
scripts/Dockerfile.devel
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
FROM ceph/ceph:v14
|
||||||
|
|
||||||
|
ENV GOPATH=/go
|
||||||
|
|
||||||
|
RUN yum -y install \
|
||||||
|
golang \
|
||||||
|
make \
|
||||||
|
librados-devel \
|
||||||
|
librbd-devel \
|
||||||
|
&& yum -y update \
|
||||||
|
&& true
|
Loading…
Reference in New Issue
Block a user