Skip to content

Commit

Permalink
Implemented Multi-stage build to further reduce image size.
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltrick committed Aug 29, 2024
1 parent 898c1d9 commit 6fc8d35
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## r4 - 2024-08-29

### Changed
- Implemented Multi-stage build to further reduce image size.

## r3 - 2024-08-29

### Changed
Expand Down
53 changes: 47 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
# Docker file for SWTPM
FROM alpine:3.20.2
# Alpine Version
ARG ALPINE_VERS=3.20.2

# Versions
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Stage #1
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FROM alpine:$ALPINE_VERS AS build

# SWTPM Versions
ARG LTPMS_COMMIT=2dc1af12e5b09a7f9eaf2dee47737b63ddfd7cb7
ARG SWTPM_COMMIT=54583a87b53623dbb04f9318c68e3d85246a6f9d

# Install required dependencies
# 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
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 --disable-tests \
&& ./autogen.sh --prefix=/usr --libdir=/usr/lib --with-tpm2 --with-openssl \
&& make -j$(nproc) \
&& make -j$(nproc) install \
&& cd - \
Expand All @@ -41,6 +57,31 @@ RUN mkdir -p /tmp/swtpm-src \
&& cd - \
&& rm -vfr /tmp/swtpm-src

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Stage #2
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FROM alpine:$ALPINE_VERS

# Install runtime dependencies
RUN apk add --no-cache \
json-glib \
libseccomp

# Copy libtpms library
COPY --from=build \
/usr/lib/libtpms.so.0 \
/usr/lib/

# Copy SWTPM libraries
COPY --from=build \
/usr/lib/swtpm/libswtpm_libtpms.so.0 \
/usr/lib/swtpm/

# Copy SWTPM executable
COPY --from=build \
/usr/bin/swtpm \
/usr/bin/

# Start SWTPM Server
ENTRYPOINT ["/usr/bin/swtpm"]
CMD ["socket", "--tpm2", "--server", "port=2321,bindaddr=0.0.0.0", "--ctrl", "type=tcp,port=2322,bindaddr=0.0.0.0"]

0 comments on commit 6fc8d35

Please sign in to comment.