mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
refactors docker build
fixes issue when upgrading dependency versions makes container workspace configurable
This commit is contained in:
parent
740b247250
commit
6d7f38baa0
104
Makefile
104
Makefile
@ -3,48 +3,65 @@ default: all
|
||||
|
||||
# Overridable defaults
|
||||
|
||||
$(VERBOSE)SILENT ?= @
|
||||
VERBOSE ?=
|
||||
PROJECT_NAME ?= webfs
|
||||
PROJECT_ROOT ?= .
|
||||
OUT ?= $(PROJECT_ROOT)/.build
|
||||
VERSION ?= $(shell cat $(PROJECT_ROOT)/VERSION)
|
||||
PARALLELMFLAGS ?= -j$(shell nproc)
|
||||
UID ?= $(shell id -u)
|
||||
DOCKER ?= docker
|
||||
DOCKER_RUNUSER ?= $(UID)
|
||||
DOCKER_RUNGROUP ?= $(shell id -g)
|
||||
CONTAINER_USER ?= $(UID)
|
||||
CONTAINER_GROUP ?= $(shell id -g)
|
||||
CONTAINER_WORKSPACE ?= /workspace
|
||||
|
||||
UBUNTU_CODENAME ?= bionic
|
||||
|
||||
QEMU_VERSION ?= v3.1.0-2
|
||||
|
||||
GTEST_VERSION ?= 1.8.1
|
||||
DOCKER_BUILDARGS += GTEST_VERSION=$(GTEST_VERSION)
|
||||
|
||||
FUSE_VERSION ?= 3.1.1
|
||||
DOCKER_BUILDARGS += FUSE_VERSION=$(FUSE_VERSION)
|
||||
|
||||
WEBSOCKETS_VERSION ?= 3.1.0
|
||||
DOCKER_BUILDARGS += WEBSOCKETS_VERSION=$(WEBSOCKETS_VERSION)
|
||||
|
||||
JANSSON_VERSION ?= 2.12
|
||||
DOCKER_BUILDARGS += JANSSON_VERSION=$(JANSSON_VERSION)
|
||||
|
||||
# Target configuration
|
||||
|
||||
MARCH_AMD64 := $(filter-out amd64,$(MARCH))
|
||||
$(MARCH_AMD64)MARCHS += amd64
|
||||
$(MARCH_AMD64)TARGETS += amd64-ubuntu-builder
|
||||
|
||||
MARCH_ARM32V7 := $(filter-out arm32v7,$(MARCH))
|
||||
$(MARCH_ARM32V7)MARCHS += arm32v7
|
||||
$(MARCH_ARM32V7)TARGETS += arm32v7-ubuntu-builder
|
||||
|
||||
ARM_TARGETS = $(filter arm%,$(TARGETS))
|
||||
UBUNTU_TARGETS = $(filter $(addsuffix -ubuntu%,$(MARCHS)),$(TARGETS))
|
||||
|
||||
MAKEFLAGS += $(PARALLELMFLAGS) --no-builtin-rules
|
||||
|
||||
$(MARCH_AMD64)TARGETS += wsfs-builder-amd64-ubuntu
|
||||
$(MARCH_ARM32V7)TARGETS += wsfs-builder-arm32v7-ubuntu
|
||||
CMAKEFLAGS += -GNinja
|
||||
|
||||
DOCKER_RUNFLAGS += --interactive
|
||||
DOCKER_RUNFLAGS += --rm
|
||||
DOCKER_RUNFLAGS += --tty
|
||||
DOCKER_RUNFLAGS += --init
|
||||
DOCKER_RUNFLAGS += --user $(DOCKER_RUNUSER):$(DOCKER_RUNGROUP)
|
||||
DOCKER_RUNFLAGS += --user $(CONTAINER_USER):$(CONTAINER_GROUP)
|
||||
DOCKER_RUNFLAGS += --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined
|
||||
DOCKER_RUNFLAGS += --env SOURCE_DATE_EPOCH
|
||||
|
||||
DOCKER_BUILDARGS += CODENAME=$(CODENAME)
|
||||
DOCKER_BUILDARGS += PARALLELMFLAGS=$(PARALLELMFLAGS)
|
||||
DOCKER_BUILDARGS += USERID=$(UID)
|
||||
DOCKER_BUILDARGS += SRC=$(realpath $(PROJECT_ROOT))
|
||||
DOCKER_BUILDARGS += OUT=$(realpath $(OUT))
|
||||
DOCKER_BUILDARGS += WORKSPACE=$(CONTAINER_WORKSPACE)
|
||||
|
||||
DOCKER_BUILDFLAGS += --rm
|
||||
DOCKER_BUILDFLAGS += $(addprefix --build-arg ,$(DOCKER_BUILDARGS))
|
||||
|
||||
OUT_DIRS += $(OUT)
|
||||
@ -52,9 +69,8 @@ OUT_DIRS += $(OUT)/docker
|
||||
OUT_DIRS += $(OUT)/src
|
||||
OUT_DIRS += $(addprefix $(OUT)/,$(TARGETS))
|
||||
|
||||
ALL_TARGETS += $(addprefix compile-,$(TARGETS))
|
||||
BUILD_TARGETS += $(addprefix build-,$(TARGETS))
|
||||
CHECK_TARGETS += $(addprefix check-,$(TARGETS))
|
||||
CONFIGURE_TARGETS += $(addsuffix /CMakeCache.txt,$(addprefix $(OUT)/,$(TARGETS)))
|
||||
|
||||
FETCH_TARGETS += $(OUT)/docker/qemu-arm-static-$(QEMU_VERSION)
|
||||
FETCH_TARGETS += $(OUT)/googletest-release-$(GTEST_VERSION).tar.gz
|
||||
@ -64,7 +80,11 @@ FETCH_TARGETS += $(OUT)/jansson-$(JANSSON_VERSION).tar.gz
|
||||
|
||||
EXTRACT_TARGETS += $(patsubst $(OUT)/%.tar.gz,$(OUT)/src/%,$(FETCH_TARGETS))
|
||||
|
||||
DOCKER_RUNGROUP := $(DOCKER_RUNGROUP)
|
||||
echo_if_silent = VERBOSE=1
|
||||
$(VERBOSE)echo_if_silent = echo $1
|
||||
$(VERBOSE)SILENT := @
|
||||
|
||||
CONTAINER_GROUP := $(CONTAINER_GROUP)
|
||||
VERSION := $(VERSION)
|
||||
PROJECT_ROOT := $(PROJECT_ROOT)
|
||||
OUT := $(OUT)
|
||||
@ -77,8 +97,12 @@ $(OUT)/libfuse-fuse-$(FUSE_VERSION).tar.gz: URL := https://github.com/libfuse/li
|
||||
$(OUT)/libwebsockets-$(WEBSOCKETS_VERSION).tar.gz: URL := https://github.com/warmcat/libwebsockets/archive/v$(WEBSOCKETS_VERSION).tar.gz
|
||||
$(OUT)/jansson-$(JANSSON_VERSION).tar.gz: URL := https://github.com/akheron/jansson/archive/v$(JANSSON_VERSION).tar.gz
|
||||
|
||||
$(addprefix $(OUT)/docker/,$(ARM_TARGETS)): $(OUT)/docker/qemu-arm-static-$(QEMU_VERSION)
|
||||
|
||||
$(addprefix $(OUT)/docker/,$(UBUNTU_TARGETS)): CODENAME := $(UBUNTU_CODENAME)
|
||||
|
||||
.PHONY: all
|
||||
all: $(ALL_TARGETS)
|
||||
all: $(BUILD_TARGETS)
|
||||
|
||||
.PHONY: check
|
||||
check: $(CHECK_TARGETS)
|
||||
@ -87,6 +111,20 @@ check: $(CHECK_TARGETS)
|
||||
clean: $(CLEAN_TARGETS)
|
||||
$(SILENT)-rm -rf $(OUT_DIRS)
|
||||
|
||||
.PHONY: check-%
|
||||
check-%: build-%;
|
||||
|
||||
.PHONY: build-%
|
||||
build-%: $(OUT)/%/CMakeCache.txt
|
||||
$(SILENT) \
|
||||
$(call echo_if_silent,ninja $(PARALLELMFLAGS) $(GLOAS)) \
|
||||
&& $(DOCKER) run $(DOCKER_RUNFLAGS) \
|
||||
--volume '$(realpath $(PROJECT_ROOT)):$(CONTAINER_WORKSPACE)' \
|
||||
--volume '$(realpath $(dir $<)):$(CONTAINER_WORKSPACE)/$(notdir $(OUT))' \
|
||||
--workdir '$(CONTAINER_WORKSPACE)/$(notdir $(OUT))' \
|
||||
$(PROJECT_NAME)-$*:$(VERSION) \
|
||||
ninja $(PARALLELMFLAGS) $(GLOAS)
|
||||
|
||||
.PHONY: get-deps
|
||||
get-deps: $(EXTRACT_TARGETS)
|
||||
|
||||
@ -94,51 +132,43 @@ get-deps: $(EXTRACT_TARGETS)
|
||||
debug-print-%:
|
||||
@printf '%s\n' '$*:' $($*)
|
||||
|
||||
.PHONY: check-%
|
||||
check-%: compile-%;
|
||||
|
||||
.PHONY: compile-%
|
||||
compile-%: $(OUT)/%/CMakeCache.txt
|
||||
$(SILENT)$(DOCKER) run $(DOCKER_RUNFLAGS) \
|
||||
--volume '$(realpath $(PROJECT_ROOT)):/tmp' \
|
||||
--volume '$(realpath $(dir $<)):/tmp/$(notdir $(OUT))' \
|
||||
--workdir '/tmp/$(notdir $(OUT))' \
|
||||
$*:$(VERSION) \
|
||||
ninja $(PARALLELMFLAGS) $(GLOAS)
|
||||
$(BUILD_TARGETS):
|
||||
|
||||
$(CHECK_TARGETS): GLOAS := test
|
||||
$(CHECK_TARGETS): DOCKER_RUNUSER := user
|
||||
$(CHECK_TARGETS): CONTAINER_USER := user
|
||||
|
||||
$(OUT)/docker/qemu-arm-static-$(QEMU_VERSION):
|
||||
$(SILENT) \
|
||||
curl -fsSL -o $@ $(URL) \
|
||||
$(call echo_if_silent,curl -fsSL -o $@ $(URL)) \
|
||||
&& curl -fsSL -o $@ $(URL) \
|
||||
&& chmod +x $@
|
||||
|
||||
$(OUT)/docker/wsfs-builder-arm32v7-ubuntu: $(OUT)/docker/qemu-arm-static-$(QEMU_VERSION)
|
||||
|
||||
$(OUT)/% : $(PROJECT_ROOT)/% | $(OUT_DIRS)
|
||||
cp $< $@
|
||||
|
||||
%-ubuntu: CODENAME := $(UBUNTU_CODENAME)
|
||||
|
||||
$(OUT)/docker/%: $(OUT)/docker/%.dockerfile $(EXTRACT_TARGETS) $(PROJECT_ROOT)/Makefile | $(OUT_DIRS)
|
||||
$(SILENT)$(DOCKER) build --rm $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $*:$(VERSION) $(OUT)
|
||||
$(SILENT) \
|
||||
$(call echo_if_silent,docker build $(PROJECT_NAME)-$*:$(VERSION) $(OUT)) \
|
||||
&& $(DOCKER) build $(DOCKER_BUILDFLAGS) --iidfile $@ --file $< --tag $(PROJECT_NAME)-$*:$(VERSION) $(OUT)
|
||||
|
||||
$(OUT)/%.tar.gz: | $(OUT_DIRS)
|
||||
curl -fsSL -o $@ $(URL)
|
||||
|
||||
$(OUT)/src/%: $(OUT)/%.tar.gz | $(OUT_DIRS)
|
||||
$(SILENT) \
|
||||
tar -C $(dir $@) -xf $< \
|
||||
$(call echo_if_silent,tar -C $(dir $@) -xf $<) \
|
||||
&& tar -C $(dir $@) -xf $< \
|
||||
&& touch $@
|
||||
|
||||
$(OUT)/%/CMakeCache.txt: $(PROJECT_ROOT)/CMakeLists.txt $(OUT)/docker/% | $(OUT_DIRS)
|
||||
$(SILENT)$(DOCKER) run $(DOCKER_RUNFLAGS) \
|
||||
--volume '$(realpath $(PROJECT_ROOT)):/tmp' \
|
||||
--volume '$(realpath $(dir $@)):/tmp/$(notdir $(OUT))' \
|
||||
--workdir '/tmp/$(notdir $(OUT))' \
|
||||
$*:$(VERSION) \
|
||||
cmake -GNinja $(CMAKEFLAGS) .. && touch $@
|
||||
$(SILENT) \
|
||||
$(call echo_if_silent,cmake $(CMAKEFLAGS) ..) \
|
||||
&& $(DOCKER) run $(DOCKER_RUNFLAGS) \
|
||||
--volume '$(realpath $(PROJECT_ROOT)):$(CONTAINER_WORKSPACE)' \
|
||||
--volume '$(realpath $(dir $@)):$(CONTAINER_WORKSPACE)/$(notdir $(OUT))' \
|
||||
--workdir '$(CONTAINER_WORKSPACE)/$(notdir $(OUT))' \
|
||||
$(PROJECT_NAME)-$*:$(VERSION) \
|
||||
cmake $(CMAKEFLAGS) .. && touch $@
|
||||
|
||||
$(OUT_DIRS):
|
||||
$(SILENT)mkdir -p $@
|
||||
|
@ -16,28 +16,34 @@ COPY src /usr/local/src
|
||||
|
||||
ARG PARALLELMFLAGS=-j2
|
||||
|
||||
ARG GTEST_VERSION=1.8.1
|
||||
|
||||
RUN set -x \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& cmake /usr/local/src/googletest-release-* \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& cmake "/usr/local/src/googletest-release-$GTEST_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out
|
||||
|
||||
ARG FUSE_VERSION=3.1.1
|
||||
|
||||
RUN set -x \
|
||||
&& apt update \
|
||||
&& apt install --yes --no-install-recommends \
|
||||
libtool \
|
||||
automake \
|
||||
gettext \
|
||||
&& cd /usr/local/src/libfuse-fuse-* \
|
||||
&& cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \
|
||||
&& ./makeconf.sh \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& /usr/local/src/libfuse-fuse-*/configure \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG WEBSOCKETS_VERSION=3.1.0
|
||||
|
||||
RUN set -x \
|
||||
&& apt update \
|
||||
&& apt install --yes --no-install-recommends \
|
||||
@ -45,22 +51,30 @@ RUN set -x \
|
||||
libssl-dev \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& cmake /usr/local/src/libwebsockets-* \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& cmake "/usr/local/src/libwebsockets-$WEBSOCKETS_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG JANSSON_VERSION=2.12
|
||||
|
||||
RUN set -x \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& cmake -DJANSSON_BUILD_DOCS=OFF /usr/local/src/jansson-* \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& cmake -DJANSSON_BUILD_DOCS=OFF "/usr/local/src/jansson-$JANSSON_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out
|
||||
|
||||
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
|
||||
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
|
||||
ARG USERID=1000
|
||||
|
||||
RUN useradd -u $USERID -ms /bin/bash user
|
||||
ARG WORKSPACE=/workspace
|
||||
|
||||
RUN set -x \
|
||||
&& useradd -u "$USERID" -ms /bin/bash user \
|
||||
&& mkdir -p "$WORKSPACE" \
|
||||
&& chown user:user "$WORKSPACE"
|
||||
|
||||
WORKDIR "$WORKSPACE"
|
||||
|
@ -18,28 +18,34 @@ COPY src /usr/local/src
|
||||
|
||||
ARG PARALLELMFLAGS=-j2
|
||||
|
||||
ARG GTEST_VERSION=1.8.1
|
||||
|
||||
RUN set -x \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& cmake /usr/local/src/googletest-release-* \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& cmake "/usr/local/src/googletest-release-$GTEST_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out
|
||||
|
||||
ARG FUSE_VERSION=3.1.1
|
||||
|
||||
RUN set -x \
|
||||
&& apt update \
|
||||
&& apt install --yes --no-install-recommends \
|
||||
libtool \
|
||||
automake \
|
||||
gettext \
|
||||
&& cd /usr/local/src/libfuse-fuse-* \
|
||||
&& cd "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \
|
||||
&& ./makeconf.sh \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& /usr/local/src/libfuse-fuse-*/configure \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& "/usr/local/src/libfuse-fuse-$FUSE_VERSION/configure" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG WEBSOCKETS_VERSION=3.1.0
|
||||
|
||||
RUN set -x \
|
||||
&& apt update \
|
||||
&& apt install --yes --no-install-recommends \
|
||||
@ -47,22 +53,30 @@ RUN set -x \
|
||||
libssl-dev \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& cmake /usr/local/src/libwebsockets-* \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& cmake "/usr/local/src/libwebsockets-$WEBSOCKETS_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG JANSSON_VERSION=2.12
|
||||
|
||||
RUN set -x \
|
||||
&& mkdir -p /tmp/out \
|
||||
&& cd /tmp/out \
|
||||
&& cmake -DJANSSON_BUILD_DOCS=OFF /usr/local/src/jansson-* \
|
||||
&& make $PARALLELMFLAGS install \
|
||||
&& cmake -DJANSSON_BUILD_DOCS=OFF "/usr/local/src/jansson-$JANSSON_VERSION" \
|
||||
&& make "$PARALLELMFLAGS" install \
|
||||
&& rm -rf /tmp/out
|
||||
|
||||
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
|
||||
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
|
||||
ARG USERID=1000
|
||||
|
||||
RUN useradd -u $USERID -ms /bin/bash user
|
||||
ARG WORKSPACE=/workspace
|
||||
|
||||
RUN set -x \
|
||||
&& useradd -u "$USERID" -ms /bin/bash user \
|
||||
&& mkdir -p "$WORKSPACE" \
|
||||
&& chown user:user "$WORKSPACE"
|
||||
|
||||
WORKDIR "$WORKSPACE"
|
||||
|
Loading…
Reference in New Issue
Block a user