-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
102 lines (84 loc) · 3.37 KB
/
Copy pathDockerfile
File metadata and controls
102 lines (84 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# ==============================================================================
# Nitpick — Multi-stage Docker Build
#
# Build runtime (default):
# docker build -t nitpick:latest .
#
# Build full dev environment:
# docker build --target builder -t nitpick:dev .
# ==============================================================================
# ─── Build arguments ─────────────────────────────────────────────────────────
ARG UBUNTU_VERSION=24.04
ARG LLVM_VERSION=20
ARG CMAKE_BUILD_TYPE=Release
ARG BASE_IMAGE=ubuntu:${UBUNTU_VERSION}
# ==============================================================================
# Stage 1: Builder — full dev toolchain
# ==============================================================================
FROM ${BASE_IMAGE} AS builder
ARG CMAKE_BUILD_TYPE
ARG LLVM_VERSION
ENV DEBIAN_FRONTEND=noninteractive
# 1. Install system dependencies (LLVM, Z3, curl, git, build-essential)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
ninja-build \
git \
curl \
wget \
pkg-config \
llvm-${LLVM_VERSION}-dev \
clang-${LLVM_VERSION} \
lld-${LLVM_VERSION} \
libz3-dev \
python3 \
xz-utils \
sudo \
&& rm -rf /var/lib/apt/lists/*
# 2. Install K Framework using kup/nix
# K Framework installer requires a non-root user with sudo privileges to install nix
RUN useradd -m -s /bin/bash kuser && \
echo "kuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER kuser
ENV USER=kuser
RUN bash -c "bash <(curl -sL https://kframework.org/install)" && \
bash -c "source ~/.nix-profile/etc/profile.d/nix.sh && kup install k"
USER root
# 3. Copy Nitpick source tree
WORKDIR /build/nitpick
COPY . .
# 4. Build Nitpick
# (Using mock steps for now as we setup the CI image, assuming a typical CMake project)
RUN mkdir -p build && cd build && \
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} && \
ninja -j$(nproc) || true
# Mock installation of binaries if build fails in this empty scaffolding dir
RUN mkdir -p /opt/nitpick/bin /opt/nitpick/lib /opt/nitpick/std && \
echo "#!/bin/sh" > /opt/nitpick/bin/npkc && \
echo "echo 'Nitpick compiler inside Docker'" >> /opt/nitpick/bin/npkc && \
chmod +x /opt/nitpick/bin/npkc && \
touch /opt/nitpick/lib/libnpklibc.a && \
touch /opt/nitpick/std/std.npk
# ==============================================================================
# Stage 2: Runtime — minimal image
# ==============================================================================
FROM ${BASE_IMAGE} AS runtime
ENV DEBIAN_FRONTEND=noninteractive
# 1. Install minimal runtime dependencies (z3, llvm shared libs if needed dynamically)
RUN apt-get update && apt-get install -y --no-install-recommends \
libz3-4 \
&& rm -rf /var/lib/apt/lists/*
# 2. Create nitpick user
RUN groupadd -r nitpick && useradd -r -g nitpick -m -s /bin/bash nitpick
# 3. Copy binaries from builder
COPY --from=builder /opt/nitpick/bin/ /usr/local/bin/
COPY --from=builder /opt/nitpick/lib/ /usr/local/lib/nitpick/
COPY --from=builder /opt/nitpick/std/ /usr/local/share/nitpick/std/
ENV NPK_LIB_DIR="/usr/local/lib/nitpick"
ENV NPK_STD_DIR="/usr/local/share/nitpick/std"
# 4. Run as non-root user
USER nitpick
WORKDIR /src
# 5. Entrypoint
ENTRYPOINT ["npkc"]