Skip to content

Commit

Permalink
Merge pull request #1 from MelonSmasher/docker-slimdown
Browse files Browse the repository at this point in the history
Reduced docker image size from 883 MB to 32MB!
  • Loading branch information
MelonSmasher authored Apr 19, 2019
2 parents c5ae1b1 + 6c58da9 commit 8d91317
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ config.example.json
config.json
piProbe.service
.git
.gitignore
.gitignore
requirements.txt
36 changes: 27 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
FROM balenalib/raspberrypi3-python:3-build
###
# Build image
###
FROM balenalib/raspberrypi3-alpine-python:3-latest as build

WORKDIR /usr/src/app
ENV LIBRARY_PATH=/lib:/usr/lib
ENV ADAFRUIT_DHT_PY_VERSION=1.4.0
ENV INFLUXDB_PY_VERSION=5.2.2
ENV CX_FREEZE_PY_VERSION=6.0b1

WORKDIR /usr/src/build

COPY piProbe.py piProbe.py

COPY requirements.txt requirements.txt
RUN apk add --no-cache build-base python3 python3-dev py3-openssl
RUN python3 -m pip install --no-cache-dir --trusted-host pypi.python.org cx_Freeze==${CX_FREEZE_PY_VERSION}
RUN python3 -m pip install --no-cache-dir --trusted-host pypi.python.org influxdb==${INFLUXDB_PY_VERSION}
RUN python3 -m pip install --no-cache-dir --trusted-host pypi.python.org Adafruit_DHT==${ADAFRUIT_DHT_PY_VERSION} --install-option="--force-pi2"
RUN cxfreeze piProbe.py --target-dir dist --include-modules=multiprocessing,os,sys,influxdb,Adafruit_DHT,requests,idna.idnadata,urllib3

###
# Deployed image
###
FROM arm32v7/alpine:3.9

RUN apt-get update \
&& apt-get upgrade --yes \
&& apt-get install build-essential python-dev python-openssl python-pip -y \
&& pip3 install --no-cache-dir --trusted-host pypi.python.org -r requirements.txt
ENV AM_I_IN_A_DOCKER_CONTAINER=Yes
ENV LIBRARY_PATH=/lib:/usr/lib

WORKDIR /usr/src/app

ENV AM_I_IN_A_DOCKER_CONTAINER Yes
# Copy precompiled binary
COPY --from=build /usr/src/build/dist/ ./

CMD modprobe w1-gpio && modprobe w1-therm modprobe i2c-dev && python3 piProbe.py
CMD modprobe w1-gpio && modprobe w1-therm && modprobe i2c-dev && ./piProbe

0 comments on commit 8d91317

Please sign in to comment.