From 3ab59b833a4f74cad5bcf0a28b5ae0fe1b04f1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20P=C3=B6schl?= Date: Sat, 15 May 2021 12:05:56 +0200 Subject: [PATCH] Add alpine multi-staged build --- .github/workflows/build.yml | 2 +- docker-files/alpine.Dockerfile | 72 ++++++++++++++++++++++++++++ docker-files/devel-alpine/Dockerfile | 24 ---------- 3 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 docker-files/alpine.Dockerfile delete mode 100644 docker-files/devel-alpine/Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 790debe7..3ba7fe62 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,7 +95,7 @@ jobs: strategy: fail-fast: false matrix: - os: ['debian'] + os: ['debian', 'alpine'] tag: ${{ fromJson(needs.create_Docker_builds.outputs.tags) }} steps: - name: Checkout diff --git a/docker-files/alpine.Dockerfile b/docker-files/alpine.Dockerfile new file mode 100644 index 00000000..311d04de --- /dev/null +++ b/docker-files/alpine.Dockerfile @@ -0,0 +1,72 @@ +# +# Glances Dockerfile (based on Alpine) +# +# https://github.com/nicolargo/glances +# + +FROM python:3.9-alpine as build + +RUN apk add --no-cache \ + python3-dev \ + musl-dev \ + linux-headers \ + build-base \ + curl \ + lm-sensors \ + wireless-tools \ + iputils + + +FROM build as remoteInstall +# Install the dependencies beforehand to make them cacheable +COPY requirements.txt . +RUN pip3 install --no-cache-dir --user -r requirements.txt + +# Force install otherwise it could be cached without rerun +ARG CHANGING_ARG +RUN pip3 install --no-cache-dir --user glances[all] + + +FROM build as additional-packages + +COPY *requirements.txt . + +RUN CASS_DRIVER_NO_CYTHON=1 pip3 install --no-cache-dir --user -r optional-requirements.txt + + +FROM build as dev + +COPY --from=additional-packages /root/.local/lib/python3.9/site-packages /usr/lib/python3.9/site-packages/ +COPY . /glances + +# EXPOSE PORT (XMLRPC / WebUI) +EXPOSE 61209 61208 + +WORKDIR /glances + +# Define default command. +CMD python3 -m glances -C /glances/conf/glances.conf $GLANCES_OPT + + +#Create running images without any building dependency +FROM python:3.9-alpine as minimal + +RUN apk add --no-cache \ + curl \ + lm-sensors \ + wireless-tools \ + iputils + +COPY --from=remoteInstall /root/.local/bin /usr/local/bin/ +COPY --from=remoteInstall /root/.local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages/ + +# EXPOSE PORT (XMLRPC / WebUI) +EXPOSE 61209 61208 + +# Define default command. +CMD python3 -m glances -C /glances/conf/glances.conf $GLANCES_OPT + + +FROM minimal as full + +COPY --from=additional-packages /root/.local/lib/python3.9/site-packages /usr/lib/python3.9/site-packages/ diff --git a/docker-files/devel-alpine/Dockerfile b/docker-files/devel-alpine/Dockerfile deleted file mode 100644 index 512b9e8f..00000000 --- a/docker-files/devel-alpine/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# -# Glances Dockerfile based on Alpine OS -# -# https://github.com/nicolargo/glances -# - -# Pull base image. -FROM alpine - -# Install Glances (develop branch) -RUN apk add python3 py3-psutil py3-bottle docker-py git -RUN git clone -b develop https://github.com/nicolargo/glances.git - -# Define working directory. -WORKDIR /glances - -# EXPOSE PORT (For XMLRPC) -EXPOSE 61209 - -# EXPOSE PORT (For Web UI) -EXPOSE 61208 - -# Define default command. -CMD /usr/bin/python3 -m glances -C /glances/conf/glances.conf $GLANCES_OPT