Skip to content

Commit 7019e6d

Browse files
committed
[docker] consolidate dockerfiles
This allows us to parameterise later layers on earlier ones. In practice, I want to use this to avoid rebuilding the `base` layer in PR and merge queue runs, building it only on `main` and release branches and tags. As a drive-by bonus, this means we can cache the `base` and `build` layers for reuse when building the `test` layer. I've also added a hook to allow building from a local working copy. (By providing an EC_REPO argument when building the `test` target.) This should allow us to pre-build the test image once and for all for all post-build checks. (Using `.` as EC_REPO, perhaps—haven't really thought that far.)
1 parent b09b7ae commit 7019e6d

5 files changed

Lines changed: 55 additions & 59 deletions

File tree

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
1-
# syntax = devthefuture/dockerfile-x
1+
ARG BASE_LAYER=base
2+
ARG BASE_BUILD_LAYER=base-build
3+
ARG BUILD_LAYER=build
24

3-
FROM ./Dockerfile.base as base-build
5+
# Base environment
6+
FROM debian:stable AS base
7+
8+
LABEL org.opencontainers.image.maintainer="Pierre-Yves Strub <pierre-yves@strub.nu>"
9+
10+
ARG user=charlie
11+
12+
ENV DEBIAN_FRONTEND=noninteractive
13+
14+
RUN \
15+
apt-get -q -y update && \
16+
apt-get -q -y upgrade && \
17+
apt-get -q -y install sudo && \
18+
apt-get -q -y clean
19+
20+
COPY --chown=root:root --chmod=0400 docker-parts/sudoers /etc/sudoers.d/
21+
22+
RUN \
23+
useradd -ms /bin/bash -d /home/$user -g root -G sudo -u 1001 $user
24+
25+
RUN \
26+
apt-get -q -y install opam && \
27+
apt-get -q -y clean
28+
29+
USER $user
30+
WORKDIR /home/$user
31+
32+
ENV OPAMYES=true OPAMVERBOSE=0 OPAMJOBS=4
33+
34+
ARG OCAML_VERSION=4.14.2
35+
36+
RUN \
37+
opam init --disable-sandboxing --compiler=ocaml-base-compiler.${OCAML_VERSION}
38+
39+
# Build environment
40+
FROM ${BASE_LAYER} AS base-build
441

542
RUN \
643
sudo apt-get -q -y install wget curl python3 python3-pip python3-yaml && \
@@ -13,6 +50,8 @@ RUN \
1350

1451
ENV PATH="/home/charlie/bin:$PATH"
1552

53+
FROM ${BASE_BUILD_LAYER} AS build
54+
1655
RUN \
1756
version=2.6.3 && \
1857
wget -O alt-ergo https://github.com/OCamlPro/alt-ergo/releases/download/v${version}/alt-ergo-v${version}-x86_64-linux-musl && \
@@ -25,8 +64,6 @@ RUN \
2564
sudo install -m 0755 alt-ergo /usr/local/bin/alt-ergo-${version} && \
2665
rm -f alt-ergo
2766

28-
FROM base-build as main-linux-amd64
29-
3067
RUN \
3168
version=1.8 && \
3269
wget -O cvc4 https://github.com/CVC4/CVC4-archived/releases/download/${version}/cvc4-${version}-x86_64-linux-opt && \
@@ -102,7 +139,16 @@ RUN \
102139
sudo install -m 0755 z3 /usr/local/bin/z3-${version} && \
103140
rm -f z3 z3.zip
104141

105-
FROM main-linux-amd64
106-
107142
RUN \
108143
opam exec -- why3 config detect
144+
145+
# Test environment
146+
FROM ${BUILD_LAYER} AS test
147+
148+
ARG EC_VERSION=main
149+
ARG EC_REPO=https://github.com/EasyCrypt/easycrypt.git#${EC_VERSION}
150+
151+
RUN \
152+
opam pin add -n easycrypt ${EC_REPO} && \
153+
opam install -v easycrypt && \
154+
rm -rf .opam/packages.dev/*

scripts/docker/Dockerfile.base

Lines changed: 0 additions & 34 deletions
This file was deleted.

scripts/docker/Dockerfile.formosa

Lines changed: 0 additions & 7 deletions
This file was deleted.

scripts/docker/Dockerfile.test

Lines changed: 0 additions & 10 deletions
This file was deleted.

scripts/docker/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
# --------------------------------------------------------------------
44
VARIANT ?= build
55
TAG ?= main
6-
BARGS += --build-arg EC_VERSION=$(TAG)
6+
VERSION ?= $(TAG)
7+
BARGS += --build-arg EC_VERSION=$(VERSION)
78

89
# --------------------------------------------------------------------
910
.PHONY: default build publish
1011

1112
default: build
1213

1314
build:
14-
docker build -f Dockerfile.$(VARIANT) \
15+
docker build --target $(VARIANT) \
1516
--platform linux/amd64 \
1617
$(BARGS) \
1718
-t ghcr.io/easycrypt/ec-$(VARIANT)-box:$(TAG) \

0 commit comments

Comments
 (0)