-
Notifications
You must be signed in to change notification settings - Fork 83
/
Dockerfile
64 lines (49 loc) · 1.79 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
FROM alpine:latest as download
RUN apk --no-cache add curl && mkdir /downloads
# Download installation files
RUN curl https://github.com/craftbeerpi/craftbeerpi4-ui/archive/main.zip -L -o ./downloads/cbpi-ui.zip
FROM python:3.9 as base
# Install dependencies
RUN apt-get update \
&& apt-get upgrade -y
RUN apt-get install --no-install-recommends -y \
libatlas-base-dev \
libffi-dev \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
ENV VIRTUAL_ENV=/opt/venv
# Create non-root user working directory
RUN groupadd -g 1000 -r craftbeerpi \
&& useradd -u 1000 -r -s /bin/false -g craftbeerpi craftbeerpi \
&& mkdir /cbpi \
&& chown craftbeerpi:craftbeerpi /cbpi \
&& mkdir -p $VIRTUAL_ENV \
&& chown -R craftbeerpi:craftbeerpi ${VIRTUAL_ENV}
USER craftbeerpi
# create virtual environment
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
# Install craftbeerpi requirements for better caching
COPY --chown=craftbeerpi ./requirements.txt /cbpi-src/
RUN pip3 install --no-cache-dir -r /cbpi-src/requirements.txt
# Install RPi.GPIO separately because it's excluded in setup.py for non-raspberrys.
# This can enable GPIO support for the image when used on a raspberry pi and the
# /dev/gpiomem device.
RUN pip3 install --no-cache-dir RPi.GPIO==0.7.1
FROM base as deploy
# Install craftbeerpi from source
COPY --chown=craftbeerpi . /cbpi-src
RUN pip3 install --no-cache-dir /cbpi-src
# Install craftbeerpi-ui
COPY --from=download --chown=craftbeerpi /downloads /downloads
RUN pip3 install --no-cache-dir /downloads/cbpi-ui.zip
# Clean up installation files
USER root
RUN rm -rf /downloads /cbpi-src
USER craftbeerpi
WORKDIR /cbpi
RUN ["cbpi", "setup"]
EXPOSE 8000
# Start cbpi
CMD ["cbpi", "start"]