Skip to content

Commit

Permalink
Merge pull request #16 from formio/FIO-8733
Browse files Browse the repository at this point in the history
FIO-8733: Update Docker build process
  • Loading branch information
travist authored Jul 25, 2024
2 parents 0f81a32 + 375aae5 commit cce6072
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cpp/extract-formfields/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)

set (CMAKE_CXX_STANDARD 17)

option(STATIC "Build static binary" ON)
project(extract-formfields)

find_library(poppler poppler)
Expand Down
96 changes: 55 additions & 41 deletions deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:24.04
FROM ubuntu:24.04 AS builder
LABEL maintainer="Form.io <support@form.io>"

# Set initial environment variables
Expand All @@ -7,51 +7,75 @@ ENV PDF2HTMLEX_URL=https://github.com/pdf2htmlEX/pdf2htmlEX/releases/download/v0
DEBIAN_FRONTEND=noninteractive \
NODE_MAJOR=20

# Install dependencies, fonts, chromium, and pdf2htmlEX
# install pdf2htmlEX and NodeJS
RUN apt-get update && \
apt-get upgrade -y && \
# Dependencies
apt-get install -y \
gnupg \
wget \
curl \
ca-certificates \
git \
gpg \
curl && \
# pdf2htmlEX
wget "$PDF2HTMLEX_URL" && \
apt-get install -y --no-install-recommends ./$PDF2HTMLEX && \
# Node.js and Yarn v1.x
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y nodejs && \
npm install -g yarn

WORKDIR /usr/src/pdf-libs
# Install node.js packages
COPY package.json ./
COPY yarn.lock ./
RUN yarn install --production --frozen-lockfile

# Add sources
COPY src ./src
COPY *.js ./

# Add docs
COPY docs ./docs

FROM node:20-bookworm-slim
LABEL maintainer="Form.io <support@form.io>"

# Update sources, install dependencies, and install fonts
RUN echo "deb http://deb.debian.org/debian/ bookworm main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://deb.debian.org/debian/ bookworm main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://deb.debian.org/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://deb.debian.org/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
apt-get update && \
apt-get upgrade && \
# Disable EULA agreement for msttcorefonts
echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections && \
# Dependencies
apt-get install -y --no-install-recommends \
wget \
g++ \
cmake \
make \
openssh-client \
git \
libcap2-bin \
ca-certificates \
libpoppler-dev \
libpoppler-qt5-dev \
qtbase5-dev \
poppler-utils \
ghostscript && \
# pdf2htmlEX
wget "$PDF2HTMLEX_URL" && \
apt-get install -y --no-install-recommends ./$PDF2HTMLEX && \
# Disable EULA agreement for msttcorefonts
echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections && \
# libjpeg8 dependency for pdf2htmlEX (libjpeg62-turbo is not available in bookworm)
wget https://archive.debian.org/debian/pool/main/libj/libjpeg8/libjpeg8_8b-1_amd64.deb && \
apt-get install -y ./libjpeg8_8b-1_amd64.deb && \
# Fonts
apt-get install -y ttf-mscorefonts-installer && \
wget https://github.com/google/fonts/archive/main.tar.gz -O gf.tar.gz && \
tar -xf gf.tar.gz && \
mkdir -p /usr/share/fonts/truetype/google-fonts && \
find ./fonts-main/ -name "*.ttf" -exec install -m644 {} /usr/share/fonts/truetype/google-fonts/ \; || return 1 && \
# Chromium
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update && \
apt-get install google-chrome-stable -y --no-install-recommends && \
rm -rf /var/lib/apt/lists/* && \
# Node.js and Yarn v1.x
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y nodejs && \
npm install -g yarn && \
rm -f /etc/apt/sources.list && \
# Cleanup
apt-get clean && \
rm -f gf.tar.gz && \
Expand All @@ -65,25 +89,15 @@ COPY cpp ./cpp
ARG EXTRACT_FORMFIELDS_ROOT=$APP_ROOT/cpp/extract-formfields
WORKDIR $EXTRACT_FORMFIELDS_ROOT
RUN ${EXTRACT_FORMFIELDS_ROOT}/build.sh
WORKDIR $APP_ROOT

# Set runtime environment variables
ENV EXTRACT_FORMFIELDS=$EXTRACT_FORMFIELDS_ROOT/bin/extract-formfields \
PDF2HTMLEX_PATH="/usr/local/bin/pdf2htmlEX" \
PSTOPDF_PATH="/usr/bin/ps2pdf"

WORKDIR $APP_ROOT

# Installing node.js packages
COPY package.json ./
COPY yarn.lock ./
RUN yarn install --production

# Adding sources
COPY src ./src
COPY *.js ./

# Adding docs
COPY docs ./docs
COPY --from=builder ${PDF2HTMLEX_PATH} ${PDF2HTMLEX_PATH}
COPY --from=builder /usr/src/pdf-libs /usr/src/pdf-libs

EXPOSE ${PORT}

Expand Down

0 comments on commit cce6072

Please sign in to comment.