yegle / fava-docker

A Dockerfile for beancount-fava
MIT License
91 stars 45 forks source link

My hooks are failing because git binary can't be located #8

Closed ngoonee closed 4 years ago

ngoonee commented 4 years ago

I'm looking through the DockerFile and it seems git IS installed, but my hooks fail because git can't be located. Is this expected behaviour or am I somehow doing something wrong? Do I need to base the DockerFile off a different image? The current one seems to be 'only' a node image, so it doesn't have apt-get/apk or whatever.

To be clear, I'm trying to add git to the existing (distroless?) image.

yegle commented 4 years ago

To minimize the image size, git is not part of the image anymore.

I would suggest to create your own image based on this image. You can use Debian 10 image as base, install git, then copy files in this image to the result image.

I'm not sure how familiar you are with Dockerfile, but I assume this is relatively straightforward. Let me know if you want an example.

ngoonee commented 4 years ago

Not very familiar, but from what I understand I would use two FROM (just like you do in your Dockerfile), and the 'real' FROM would be Debian or Alpine or something like that (where I'd install git), and from your image I'd just:-

  1. Copy /app
  2. Basically do all the env/entrypoint stuff which your Dockerfile does after copying /app

That sound about right?

yegle commented 4 years ago

Yes that would be all.

ngoonee commented 4 years ago

So I tried a simple Dockerfile which looks like this:-

FROM yegle/fava:latest as built

FROM alpine:latest

COPY --from=built /app /app

RUN apk add --no-cache git python3 py3-setuptools py3-virtualenv

EXPOSE 5000

ENV BEANCOUNT_FILE ""
# Required by Click library.
# See https://click.palletsprojects.com/en/7.x/python3/
ENV LC_ALL "C.UTF-8"
ENV LANG "C.UTF-8"
ENV FAVA_HOST "0.0.0.0"
ENV PATH "/app/bin:$PATH"

ENTRYPOINT ["fava"]

It builds successfully (since it does almost nothing) but fava can't start with this error:-

Traceback (most recent call last):
  File "/app/bin/fava", line5, in <module>
    from fava.cli import main
ModuleNotFoundError: No module named 'fava'

Is there some venv stuff I'm missing?

yegle commented 4 years ago

Alpine probably won't work: it uses musl libc, which is not compatible with glibc. My image is built using glibc (beancount have some binary Python module)

I would suggest to use Debian slim as base image, install python3 and git, then copy /app from my image.

yegle commented 4 years ago

Also, you probably don't want to use the official Python image even if it's based on Debian. The code in my image is installed under a Python version specific directory (something like /app/lib/python-3.x, AFK so I might be wrong). If you install Python 3 in Debian 10, the version would match.

ngoonee commented 4 years ago

Ah, didn't think about glibc. This works then! For posterity:-

FROM yegle/fava:latest as built

FROM debian:buster-slim

COPY --from=built /app /app

RUN apt-get update && apt-get install -y \
  git \
  python3

EXPOSE 5000

ENV BEANCOUNT_FILE ""
# Required by Click library.
# See https://click.palletsprojects.com/en/7.x/python3/
ENV LC_ALL "C.UTF-8"
ENV LANG "C.UTF-8"
ENV FAVA_HOST "0.0.0.0"
ENV PATH "/app/bin:$PATH"

ENTRYPOINT ["fava"]

Thanks so much for your time and image!