Skip to content

Instantly share code, notes, and snippets.

@haampie
Last active January 4, 2023 17:11
Show Gist options
  • Save haampie/6ede63bc25ecede74d4ec5488be00df9 to your computer and use it in GitHub Desktop.
Save haampie/6ede63bc25ecede74d4ec5488be00df9 to your computer and use it in GitHub Desktop.
Docker build with cache
FROM alpine
WORKDIR /root
ENV PATH="/root/spack/bin:$PATH" SPACK_COLOR=always
# Setup spack and its deps
RUN apk add gcc g++ gfortran make file tar curl python3 patch unzip gnupg git xz python3-dev py3-pip linux-headers && \
pip install clingo
# make version 4.4 please
RUN curl -Lfs https://github.com/JuliaBinaryWrappers/GNUMake_jll.jl/releases/download/GNUMake-v4.4.0%2B0/GNUMake.v4.4.0.x86_64-linux-musl.tar.gz | tar -xzf - -C /usr
RUN mkdir spack && \
cd spack && \
curl -Lfs https://github.com/spack/spack/archive/refs/heads/develop.tar.gz | tar -xzf - --strip-components=1 -C . && \
curl -Lfs https://github.com/spack/spack/pull/34678.patch | git apply # not yet merged
ADD spack.yaml Makefile /root/
RUN --mount=type=cache,target=/buildcache \
--mount=type=cache,target=/root/.spack/cache \
spack compiler find && \
spack mirror add cache file:///buildcache && \
make -j$(nproc) push MY_BUILDCACHE=/buildcache
SPACK ?= spack
export SPACK_COLOR = always
MAKEFLAGS += -Orecurse
SPACK_INSTALL_FLAGS += --no-check-signature
MY_BUILDCACHE := $(CURDIR)/cache
.PHONY: all clean
all: push
ifeq (,$(filter clean,$(MAKECMDGOALS)))
include env.mk
endif
push: $(addprefix example/push/,$(SPACK_PACKAGE_IDS))
$(SPACK) -e . buildcache update-index --directory $(MY_BUILDCACHE)
$(info Pushed everything, yay!)
example/push/%: example/install/%
@mkdir -p $(dir $@)
$(SPACK) -e . buildcache create --allow-root --only=package --unsigned --directory $(MY_BUILDCACHE) /$(HASH) 2> /dev/null # push $(SPEC)
@touch $@
spack.lock: spack.yaml
$(SPACK) -e . concretize -f
env.mk: spack.lock
$(SPACK) -e . env depfile -o $@ --make-target-prefix example
clean:
rm -rf spack.lock env.mk example/
spack:
view: false
specs:
- cmake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment