-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
101 lines (88 loc) · 2.63 KB
/
Dockerfile
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
# Alpine Version
ARG ALPINE_VERS=3.21.2@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Stage #1
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FROM alpine:$ALPINE_VERS AS build
# SWTPM Versions
ARG SWTPM_COMMIT=0528ac733b76e88682dce6853a82054834b458e1
ARG LTPMS_COMMIT=ecb769cdb8ddbef6e3d91c062d9d2105acff5802
# Install build dependencies
RUN apk add --no-cache \
autoconf \
automake \
bash \
build-base \
curl \
expect \
gawk \
gmp-dev \
gnutls \
gnutls-dev \
gnutls-utils \
json-glib-dev \
libseccomp-dev \
libtasn1-dev \
libtool \
make \
openssl-dev \
py3-cryptography \
py3-pip \
py3-setuptools \
py3-twisted \
python3 \
socat \
softhsm
# Build libtpms
RUN mkdir -p /tmp/libtpms-src \
&& curl --tlsv1.2 -sSfL https://github.com/stefanberger/libtpms/archive/${LTPMS_COMMIT}.tar.gz | tar -C /tmp/libtpms-src --strip-components=1 -xzv \
&& cd /tmp/libtpms-src \
&& ./autogen.sh --prefix=/usr --libdir=/usr/lib --with-tpm2 --with-openssl \
&& make -j$(nproc) \
&& make -j$(nproc) install \
&& cd - \
&& rm -vfr /tmp/libtpms-src
# Build SWTPM
RUN mkdir -p /tmp/swtpm-src \
&& curl --tlsv1.2 -sSfL https://github.com/stefanberger/swtpm/archive/${SWTPM_COMMIT}.tar.gz | tar -C /tmp/swtpm-src --strip-components=1 -xzv \
&& cd /tmp/swtpm-src \
&& ./autogen.sh --prefix=/usr --libdir=/usr/lib --with-openssl --disable-tests \
&& make -j$(nproc) \
&& make -j$(nproc) install \
&& cd - \
&& rm -vfr /tmp/swtpm-src
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Stage #2
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FROM alpine:$ALPINE_VERS
# Install runtime dependencies
RUN apk add --no-cache \
json-glib \
gmp \
gnutls-utils \
libseccomp
# Copy libtpms library
COPY --from=build \
/usr/lib/libtpms.so* \
/usr/lib/
# Copy SWTPM libraries
COPY --from=build \
/usr/lib/swtpm/libswtpm_libtpms.so* \
/usr/lib/swtpm/
# Copy configuration files
COPY --from=build \
/etc/swtpm* \
/etc/
# Copy SWTPM executable
COPY --from=build \
/usr/bin/swtpm* \
/usr/bin/
# Create 'tpmstate' directory
RUN mkdir -p /var/lib/swtpm/tpmstate
# Start SWTPM Server
ENTRYPOINT ["/usr/bin/swtpm"]
CMD ["socket", "--tpm2", \
"--server", "type=tcp,port=2321,bindaddr=0.0.0.0", \
"--ctrl", "type=tcp,port=2322,bindaddr=0.0.0.0", \
"--flags", "not-need-init", \
"--tpmstate", "dir=/var/lib/swtpm/tpmstate"]