swtpm/Dockerfile
Boris Glimcher 7d6aac0434 Adding alpine based dockerfile
Fixed #869

Used multi-stage build here to reduce final image size.
Builder should have packages for dev and compile.
Final image should only have dependencies for runtime.

Building is simple using `docker build .` command.

Or `docker build --build-arg="LIBTPMS_BRANCH=v0.9.6" .`
if you want another branch/tag of libtpms.

Next patch will add:
- linter
- build
- tpm2 tools testing

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
2024-07-18 16:48:21 -04:00

43 lines
1.8 KiB
Docker

FROM python:3.9-alpine3.19 as builder
LABEL org.opencontainers.image.authors="Stefan Berger"
ENV PACKAGES="curl openssl-dev automake autoconf bash build-base libtool make socat gawk libtasn1-dev gnutls gnutls-utils gnutls-dev expect libseccomp-dev softhsm py3-cryptography py3-twisted py3-setuptools json-glib-dev gmp-dev"
RUN apk add --no-cache --no-check-certificate $PACKAGES && rm -rf /var/cache/apk/*
ARG LIBTPMS_BRANCH=master
WORKDIR /src/build-prep/libtpms
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -kL "https://github.com/stefanberger/libtpms/archive/${LIBTPMS_BRANCH}.tar.gz" \
| tar --strip=1 -zxvf - -C /src/build-prep/libtpms \
&& ./autogen.sh --prefix=/usr --libdir=/usr/lib --with-tpm2 --with-openssl \
&& make -j"$(nproc)" V=1 \
&& make -j"$(nproc)" V=1 check \
&& make -j"$(nproc)" install \
&& make DESTDIR=/app -j"$(nproc)" install
COPY . /src/build-prep/swtpm
WORKDIR /src/build-prep/swtpm
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN ./autogen.sh --prefix=/usr --libdir=/usr/lib --with-openssl --with-tss-user=root --with-tss-group=root \
&& make -j"$(nproc)" V=1 \
&& echo "softhsm or certtool are crashing pkcs11 test case" \
&& { for f in test_tpm2_swtpm_localca_pkcs11.test test_tpm2_samples_swtpm_localca_pkcs11; do echo -en '#!/usr/bin/env bash'"\nexit 77\n" > tests/${f}; done; } \
&& make -j"$(nproc)" V=1 VERBOSE=1 check \
&& make DESTDIR=/app -j"$(nproc)" install
FROM alpine:3.19
LABEL org.opencontainers.image.authors="Stefan Berger"
ENV PACKAGES="openssl socat gawk libtasn1 expect libseccomp softhsm py3-cryptography py3-twisted py3-setuptools json-glib gmp"
RUN apk add --no-cache --no-check-certificate $PACKAGES && rm -rf /var/cache/apk/*
COPY --from=builder /app /
WORKDIR /app
ENTRYPOINT ["/usr/bin/swtpm"]