Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
This site is not currently using Docker, but the file can still
serve as a useful example of how to do it.

If you have Docker installed, you can run:
```
docker build -t kobweb-site .
docker run -dp 8080:8080 kobweb-site
```
  • Loading branch information
bitspittle committed Apr 17, 2023
1 parent 3ef1413 commit 34a674e
Showing 1 changed file with 35 additions and 48 deletions.
83 changes: 35 additions & 48 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,68 +1,55 @@
FROM debian:stable-slim
USER root

# Copy the project code to app dir
COPY . /app
ARG KOBWEB_CLI_VERSION=0.9.12

# Install OpenJDK-11 (earliest JDK kobweb can run on)
RUN apt-get update \
&& apt-get install -y openjdk-11-jdk \
&& apt-get install -y ant \
&& apt-get clean
# Copy the project code to an arbitrary subdir so we can install stuff in the
# Docker container root without worrying about clobbering project files.
COPY . /project

# Fix certificate issues
# Prepare apt-get and get generally useful packages
RUN apt-get update \
&& apt-get install ca-certificates-java \
&& apt-get clean \
&& update-ca-certificates -f
&& apt-get install -y curl gnupg unzip wget

# Prepare npm and use it to initialize the browser we'll use for exporting
# (installed by playwright)
RUN curl -sL https://deb.nodesource.com/setup_19.x | bash - \
&& apt-get install -y nodejs \
&& npm init -y \
&& npx playwright install --with-deps chromium

# Install OpenJDK-11 (earliest JDK kobweb can run on)
RUN apt-get install -y openjdk-11-jdk

# Setup JAVA_HOME -- needed by kobweb / gradle
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/
RUN export JAVA_HOME
RUN java -version

# Add Chrome (for export)
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
--no-install-recommends \
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
fontconfig \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-symbola \
fonts-noto \
fonts-freefont-ttf \
--no-install-recommends

# Install kobweb
RUN apt-get update && apt-get install -y wget unzip

RUN wget https://github.com/varabyte/kobweb/releases/download/v0.7.7/kobweb-0.7.7.zip \
&& unzip kobweb-0.7.7.zip \
&& rm -r kobweb-0.7.7.zip
ENV PATH="/kobweb-0.7.7/bin:${PATH}"
RUN wget https://github.com/varabyte/kobweb-cli/releases/download/v${KOBWEB_CLI_VERSION}/kobweb-${KOBWEB_CLI_VERSION}.zip \
&& unzip kobweb-${KOBWEB_CLI_VERSION}.zip \
&& rm -r kobweb-${KOBWEB_CLI_VERSION}.zip
ENV PATH="/kobweb-${KOBWEB_CLI_VERSION}/bin:${PATH}"
RUN echo $PATH

WORKDIR /app
WORKDIR /project

RUN ./gradlew --stop && kobweb export --mode dumb
RUN kobweb export --notty

ENV PORT=8080
EXPOSE $PORT

# Purge all the things we don't need anymore

RUN apt-get purge --auto-remove -y curl gnupg wget unzip \
&& rm -rf /var/lib/apt/lists/*

# Keep container running because `kobweb run --mode dumb` doesn't block
CMD ./gradlew --stop && kobweb run --mode dumb --env prod && ./gradlew --stop && tail -f /dev/null
# Purge all the things we don't need anymore, saving space on web servers that
# may need all the spare MB they can get!
RUN apt-get clean && apt-get purge --auto-remove -y curl gnupg nodejs unzip wget \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf ~/.cache/ms-playwright

# Finally, run our web server! We stop the Gradle daemon at this point because
# its work is done. Finally, we keep the Docker container from closing (with
# `tail -f ...`) since `kobweb run --notty` doesn't block but is running in the
# background.
CMD kobweb run --notty --env prod \
&& ./gradlew --stop \
&& tail -f /dev/null

0 comments on commit 34a674e

Please sign in to comment.