Docker build fails for anvil server

Hey, what can I be doing wrong while trying to build the docker image for anvil server using the standard dockerfile from:
anvil-runtime/packaging/app-server/Dockerfile at master · anvil-works/anvil-runtime · GitHub

It fails with:
=> ERROR [4/9] RUN apt-get -yyy update && apt-get -yyy install java-1.8.0-amazon-corretto-jdk ghostscript

3.026 E: Unable to locate package java-1.8.0-amazon-corretto-jdk
3.026 E: Couldn’t find any package by glob ‘java-1.8.0-amazon-corretto-jdk’
3.026 E: Couldn’t find any package by regex ‘java-1.8.0-amazon-corretto-jdk’

Did the version changed for the java?

This is also occurring on amoni and I haven’t found a fix yet:

1 Like

I have the fix ready by manually fetching the jdk package.

FROM python:3

RUN apt-get -yyy update && apt-get -yyy install \
    software-properties-common \
    postgresql-client \
&&  wget -O- https://apt.corretto.aws/corretto.key | apt-key add - && \
    add-apt-repository 'deb https://apt.corretto.aws stable main'

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
    (dpkg -i google-chrome-stable_current_amd64.deb || apt install -y --fix-broken) && \
    rm google-chrome-stable_current_amd64.deb

# Download and install Amazon Corretto 8 (replace the URL with the correct version)
RUN wget -O /tmp/corretto-8.tar.gz https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.tar.gz \
    && tar -xzf /tmp/corretto-8.tar.gz -C /opt \
    && rm /tmp/corretto-8.tar.gz

# Set JAVA_HOME and add Java to the PATH
ENV JAVA_HOME=/opt/amazon-corretto-8-x64-linux-jdk
ENV PATH="$PATH:$JAVA_HOME/bin"

RUN apt-get -yyy update && apt-get -yyy install ghostscript

COPY anvil_app/requirements.txt ./
RUN pip install -r requirements.txt
RUN anvil-app-server || true

VOLUME /apps
WORKDIR /apps

RUN mkdir /anvil-data
2 Likes

@owen.campbell the real issue was in my case the base image.
I used in my original Dockerfile:
FROM python:3
That image somehow stopped supporting that java corretto package.
I changed first line in my Dockerfile to the base image that anvil repo is using:
FROM --platform=linux/amd64 python:3-buster

And that solved all, it’s again auto building.

Finally after some more testing I switched to different base image.
That one has a native package openjdk-17 and works fine so far.
Below sample dockerfile

FROM python:3.11-slim-bookworm

RUN apt-get -yyy update && apt-get -yyy install openjdk-17-jdk

RUN pip install --upgrade pip
RUN pip install anvil-app-server
RUN anvil-app-server || true

RUN mkdir /apps
WORKDIR /apps

RUN mkdir /anvil-data

RUN useradd anvil
RUN chown -R anvil:anvil /anvil-data
USER anvil

ENTRYPOINT ["anvil-app-server", "--data-dir", "/anvil-data"]

CMD ["--app", "MainApp"]
3 Likes

Nice! I’ll try that on amoni when I get a chance…

I don’t currently use Docker for my anvil-app-server installs, but I really appreciate having this info. Thank you!

Many thanks for this @gp2

After some wrangling with multi-architecture builds, I’ve managed to use your code to fix the problems on amoni. If you’re interested, the result is at:

Next step, can I use a builder stage to get the size of the final image down to something more reasonable…

Thanks for the info @owen.campbell

I was playing also with smaller image size by using Alpine as base image:
FROM python:3.11-alpine
But this one is based on Ubuntu and some things are slightly different.
Instead “useradd” command I had to use “adduser” with “-D” for skipping the password when creating the user.
Also the package name is different for java - “openjdk8”.

Had to add also “gcc”, “python-dev” and “linux-headers” to have the “psutil” package build.
I was testing that on raspberry pi :slight_smile:

Final base dockerfile is like that:

FROM python:3.11-alpine

RUN apk update && apk add --no-cache build-base linux-headers gcc python3-dev

RUN apk add --update openjdk8

RUN pip install --upgrade pip

RUN pip install --no-cache-dir psutil

RUN pip install anvil-app-server
RUN anvil-app-server || true

RUN mkdir /apps
WORKDIR /apps

RUN mkdir /anvil-data

RUN adduser anvil -D
RUN chown -R anvil:anvil /anvil-data
USER anvil

ENTRYPOINT ["anvil-app-server", "--data-dir", "/anvil-data"]

CMD ["--app", "MainApp"]

Alpine based image is almost half time smaller:

Here is also code for uplink script as docker container, might be useful to someone.
This is really small in size 160MB as its using “slim” version of the image.

# Use an official Python runtime as a parent image
FROM python:3.11-slim-bookworm

# Install Anvil Uplink
RUN pip install --upgrade pip
RUN pip install anvil-uplink

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy the current directory contents into the container at /usr/src/app
COPY ./uplink.py /usr/src/app

# Run the Python script when the container launches
CMD ["python", "./uplink.py"]

I added piwheels.org for psutil on the raspberry pi, but still had to install the build tools for arm/64

On another project (not open source, so can’t share), I’ve used a builder stage to construct the venv and then copied that into an alpine base for the final image. It worked a treat and I’d like to repeat the trick here.

Not a bad start. A few tweaks and this might be worth having!

https://chat.openai.com/share/cb2a410b-77f5-44cb-87e2-d667b4cd5e33

Yep, looks really interesting, thanks for sharing!

My WIP - but something isn’t right as the resulting venv has no content. I’m out of time on this for now.

I found and fixed the various silly mistakes and the resulting amoni app-server image is now roughly one third its previous size!!

Many thanks for the nudge, the hints, the code etc.

Here’s the working version:

5 Likes

Thanks for sharing the final version!