forked from BraneFramework/brane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.rls
253 lines (166 loc) · 6.53 KB
/
Dockerfile.rls
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# DOCKERFILE.rls for BRANE
# by Tim Müller and Onno Valkering
#
# Contains the Dockerfile for the various Brane instance images.
#
# This version builds the release images. For images build in development mode,
# check Dockerfile.dev.
#
##### BUILD STAGE #####
### This file will act as the bottom for both builder images
FROM rust:1 AS build-common
LABEL org.opencontainers.image.source https://github.com/epi-project/brane
# Install build dependencies (that are not in the rust image already)
RUN apt-get update && apt-get install -y \
cmake \
curl \
unzip \
&& rm -rf /var/lib/apt/lists/*
# Copy over relevant crates & other files
RUN mkdir /build
COPY . /build
### This file does the Brane services
FROM build-common AS build-brane
LABEL org.opencontainers.image.source https://github.com/epi-project/brane
# Build optimized binaries
WORKDIR /build
RUN --mount=type=cache,id=cargoidx,target=/usr/local/cargo/registry \
--mount=type=cache,id=branecache,target=/build/target \
cargo build \
--release \
--package brane-api \
--package brane-drv \
--package brane-job \
--package brane-prx \
--package brane-plr \
--package brane-reg \
&& cp ./target/release/brane-api /brane-api \
&& cp ./target/release/brane-drv /brane-drv \
&& cp ./target/release/brane-job /brane-job \
&& cp ./target/release/brane-prx /brane-prx \
&& cp ./target/release/brane-plr /brane-plr \
&& cp ./target/release/brane-reg /brane-reg
# If ever run, run a shell
WORKDIR /
ENTRYPOINT [ "/bin/bash" ]
### This file does the policy reasoner service
FROM build-common AS build-policy-reasoner
LABEL org.opencontainers.image.source https://github.com/epi-project/brane
# Fetch the reasoner code next
WORKDIR /
ARG REASONER=eflint
ARG REASONER_BRANCH=main
ADD "http://github.com/epi-project/policy-reasoner/zipball/${REASONER_BRANCH}/" /policy-reasoner.zip
RUN unzip /policy-reasoner.zip && mv /epi-project-policy-reasoner* /policy-reasoner
# Touch a `policy.db` into action to avoid the policy reasoner's `build.rs` building it for us (unnecessary)
RUN mkdir -p /policy-reasoner/data && touch /policy-reasoner/data/policy.db
# Compile it!
WORKDIR /policy-reasoner
RUN --mount=type=cache,id=cargoidx,target=/usr/local/cargo/registry \
--mount=type=cache,id=reasonercache,target=/policy-reasoner/target \
cargo build --release --bin $REASONER --features brane-api-resolver \
&& cp ./target/release/$REASONER /brane-chk
# If ever run, run a shell
WORKDIR /
ENTRYPOINT [ "/bin/bash" ]
### This target does the eflint-server binary
FROM ubuntu:22.04 AS build-eflint-server
# Define build args
ARG ARCH=amd64
# Install deps
RUN apt-get update && apt-get install -y \
git wget \
&& rm -rf /var/lib/apt/lists/*
# Install go
RUN wget https://go.dev/dl/go1.22.1.linux-$ARCH.tar.gz -O - | tar -xvz
# Fetch the repo & compile it
RUN PATH="$PATH:/go/bin" \
&& git clone https://github.com/epi-project/eflint-server-go /eflint-server-go \
&& cd /eflint-server-go/cmd/eflint-server \
&& go build . \
&& mv ./eflint-server /eflint-server
##### BASE IMAGE #####
# This image defines the base image for all Brane service images.
FROM ubuntu:22.04 AS brane-base
LABEL org.opencontainers.image.source https://github.com/epi-project/brane
# Add the log directory
RUN mkdir -p /logs/profile
# Add an ubuntu 21.10 source for libssl1.1 (insecure, but it's the dev image anyway)
# Can't get around that, even in release, since libssl1.1 is only available in old repos
RUN echo "deb http://old-releases.ubuntu.com/ubuntu impish-security main" >> /etc/apt/sources.list
# Install libssl (the Rust crate depends on it)
RUN apt-get update && apt-get install -y \
libssl1.1 \
&& rm -rf /var/lib/apt/lists/*
# If ever run, run a shell
ENTRYPOINT [ "/bin/bash" ]
##### BRANE-PRX #####
# This image contains the Brane proxy service.
FROM brane-base AS brane-prx
# Copy `brane-prx` from build stage
COPY --from=build-brane /brane-prx /brane-prx
# Run the compiled executable as base
ENTRYPOINT [ "./brane-prx" ]
##### BRANE-API #####
# This image contains the Brane API service.
FROM brane-base AS brane-api
# Install additional runtime dependencies specific for brane-api
RUN apt-get update && apt-get install -y \
gnupg2 \
wget \
&& rm -rf /var/lib/apt/lists/*
# Copy `brane-api` from build stage
COPY --from=build-brane /brane-api /brane-api
# Run the compiled executable as base
ENTRYPOINT [ "/brane-api" ]
##### BRANE-DRV #####
# This image contains the Brane driver service.
FROM brane-base AS brane-drv
# Copy `brane-drv` from build stage
COPY --from=build-brane /brane-drv /brane-drv
# Run the compiled executable as base
ENTRYPOINT [ "./brane-drv" ]
##### BRANE-PLR #####
# This image contains the Brane planner service.
FROM brane-base AS brane-plr
# Copy `brane-plr` from build stage
COPY --from=build-brane /brane-plr /brane-plr
# Run the compiled executable as base
ENTRYPOINT [ "./brane-plr" ]
##### BRANE-JOB #####
# This image contains the Brane job service.
FROM brane-base AS brane-job
# Copy `brane-job` from build stage
COPY --from=build-brane /brane-job /brane-job
# Run the compiled executable as base
ENTRYPOINT [ "./brane-job" ]
##### BRANE-REG #####
# This image contains the Brane registry service.
FROM brane-base AS brane-reg
# Copy `brane-reg` from build stage
COPY --from=build-brane /brane-reg /brane-reg
# Run the compiled executable as base
ENTRYPOINT [ "./brane-reg" ]
##### BRANE-CHK #####
# This image contains the policy reasoner / checker!
FROM ubuntu:22.04 AS brane-chk
# Install deps
RUN apt-get update && apt-get install -y \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*
# Generate a start script
RUN printf '#!/bin/bash\n# Startup script for the policy reasoner container\n\n# Spawn the eFLINT reasoner itself\n/eflint-server 2>&1 &\n\n# Launch the policy reasoner binary\n/brane-chk $@\n\n' > /startup.sh \
&& chmod +x /startup.sh
# Install the eFLINT JSON server
# ADD https://github.com/Olaf-Erkemeij/eflint-server/raw/bd3997df89441f13cbc82bd114223646df41540d/eflint-server /eflint-server
# RUN chmod +x /eflint-server
# Copy some config from the build stage
COPY --from=build-policy-reasoner /policy-reasoner/examples/config/jwt_resolver.yaml /examples/config/jwt_resolver.yaml
# Copy `policy-reasoner` from build stage
COPY --from=build-policy-reasoner /brane-chk /brane-chk
RUN chmod +x /brane-chk
# Copy `eflint-server` from build stage
COPY --from=build-eflint-server /eflint-server /eflint-server
# Run the compiler executable as base
WORKDIR /
ENTRYPOINT [ "/startup.sh" ]