lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.datapage.app
MIT License
1.29k stars 69 forks source link

[Docker] Preinstall tzdata or use rust:<version>-alpine as base image for sqlpage #123

Closed nanawel closed 9 months ago

nanawel commented 10 months ago

Hi, I was attempting to upgrade a local project to sqlpage 0.15.x but my build failed with the following error:

1.793 /bin/sh: apk: not found

This is because the base Rust image is slim and it does not provide apk in order to install additional dependencies. My Dockerfile is as follows:

FROM lovasoa/sqlpage:${sqlpage_version:-latest}

USER root
RUN apk add --no-cache tzdata

WORKDIR /var/www

USER sqlpage
COPY ./src /var/www

The RUN used to work with previous versions (at least 0.11.x I guess) but not anymore.

This is an important issue IMHO because it means that all date-related processings will be performed in the UTC timezone, and something as simple as "displaying the current date/time" for the user will be wrong most of the time.

Do you think you could provide two flavors of each build, one using rust:<version>-slim with focus on extra-low weight, and one using rust:<version>-alpine which could hence be more customizable?

lovasoa commented 10 months ago

The base image is not rust, but busybox, which is indeed almost empty, and provides very lightweight images.

The best way to make new image variants is to add a new target in our Dockerfile, and update our release GitHub actions. Could you open a pull request for that? Alpine is probably not the best option given that or binaries depend on glibc, but making an image based on debian slim should be as simple as copying the binary into the image.

nanawel commented 10 months ago

The base image is not rust, but busybox,

Right! I didn't read to the end of the file.

The best way to make new image variants is to add a new target in our Dockerfile, and update our release GitHub actions. Could you open a pull request for that?

I'm not familiar with GA but I'll see what I can do, sure. :+1:

lovasoa commented 10 months ago

Don't hesitate to ask for help here if you need :) I'll be happy to collaborate.

lovasoa commented 9 months ago

@nanawel I updated the README to recommend against using the default image as a base, and instead using something like

FROM debian:stable-slim
COPY --from=lovasoa/sqlpage:latest /usr/local/bin/sqlpage /usr/local/bin/sqlpage

It works because SQLPage is a single static binary without dependencies.

nanawel commented 9 months ago

Thanks a lot! I could not find the time to work on this, unfortunately :confused: Your proposal seems perfect to me, I'll try it.

nanawel commented 9 months ago

To anyone interested, a working Debian-based Dockerfile similar to what the default image provides would be:

ARG sqlpage_version
FROM lovasoa/sqlpage:${sqlpage_version:-latest} as sqlpage_base_image

FROM debian:bookworm-slim

COPY --from=sqlpage_base_image /usr/local/bin/sqlpage /usr/local/bin/sqlpage

ARG sqlpage_version
ENV SQLPAGE_VERSION=${sqlpage_version:-unknown}

RUN addgroup --system sqlpage \
 && adduser --system --no-create-home --ingroup sqlpage sqlpage

USER sqlpage
WORKDIR /var/www

EXPOSE 8080
CMD ["/usr/local/bin/sqlpage"]

FYI I tried to use alpine:3 first but the binary won't run. I suppose it's because it's dynamically linked to the glibc. If you need it anyway, you should take a look at this documentation: https://wiki.alpinelinux.org/wiki/Running_glibc_programs

lovasoa commented 9 months ago

I think you don't need the first FROM. You can directly COPY --from=lovasoa/sqlpage:latest

nanawel commented 9 months ago

Not if you want to be able to customize the version using build args.