From eb8c0fd23c88abce2a9801c04a56fa9ac7e7b112 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Thu, 3 Nov 2022 15:05:57 +0100 Subject: [PATCH] Refactor Docker image factory: from now, only Alpine images will be provided --- .github/workflows/build.yml | 4 +- Makefile | 16 +-- README.rst | 17 +-- docker-compose/Dockerfile | 2 +- .../docker-compose-with-traefik.yml | 2 +- docker-files/alpine.Dockerfile | 21 +-- docker-files/debian.Dockerfile | 130 ------------------ 7 files changed, 23 insertions(+), 169 deletions(-) delete mode 100644 docker-files/debian.Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c6cc2ed..2d9d1376 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -96,7 +96,7 @@ jobs: strategy: fail-fast: false matrix: - os: ['debian', 'alpine'] + os: ['alpine'] tag: ${{ fromJson(needs.create_Docker_builds.outputs.tags) }} steps: - name: Checkout @@ -139,7 +139,7 @@ jobs: uses: docker/build-push-action@v3 with: push: ${{ env.PUSH_BRANCH == 'true' }} - tags: "${{ env.DEFAULT_DOCKER_IMAGE }}:${{ matrix.os != 'debian' && format('{0}-', matrix.os) || '' }}${{ matrix.tag.tag }}" + tags: "${{ env.DEFAULT_DOCKER_IMAGE }}:${{ matrix.os != 'alpine' && format('{0}-', matrix.os) || '' }}${{ matrix.tag.tag }}" build-args: | CHANGING_ARG=${{ github.sha }} context: . diff --git a/Makefile b/Makefile index 584543ca..993bda07 100644 --- a/Makefile +++ b/Makefile @@ -118,18 +118,13 @@ flatpak: venv-dev-upgrade ## Generate FlatPack JSON file # Docker # =================================================================== -docker: docker-alpine docker-debian +docker: docker-alpine docker-alpine: docker build --target full -f ./docker-files/alpine.Dockerfile -t glances:local-alpine-full . docker build --target minimal -f ./docker-files/alpine.Dockerfile -t glances:local-alpine-minimal . docker build --target dev -f ./docker-files/alpine.Dockerfile -t glances:local-alpine-dev . -docker-debian: - docker build --target full -f ./docker-files/debian.Dockerfile -t glances:local-debian-full . - docker build --target minimal -f ./docker-files/debian.Dockerfile -t glances:local-debian-minimal . - docker build --target dev -f ./docker-files/debian.Dockerfile -t glances:local-debian-dev . - # =================================================================== # Run # =================================================================== @@ -152,15 +147,6 @@ run-docker-alpine-full: ## Start Glances Alpine Docker full in console mode run-docker-alpine-dev: ## Start Glances Alpine Docker dev in console mode docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-alpine-dev -run-docker-debian-minimal: ## Start Glances Debian Docker minimal in console mode - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-debian-minimal - -run-docker-debian-full: ## Start Glances Debian Docker full in console mode - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-debian-full - -run-docker-debian-dev: ## Start Glances Debian Docker dev in console mode - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro --pid host --network host -it glances:local-debian-dev - run-webserver: ## Start Glances in Web server mode ./venv/bin/python -m glances -C ./conf/glances.conf -w diff --git a/README.rst b/README.rst index 222d4cf6..2cc9f924 100644 --- a/README.rst +++ b/README.rst @@ -193,25 +193,20 @@ If you want to support other distributions, please contribute to `glancesautoins Docker: the fun way ------------------- -Glances containers are availables. You can use it to monitor your -server and all your other containers! +Glances Docker images are availables. You can use it to monitor your +server and all your containers ! Get the Glances container: .. code-block:: console - docker pull nicolargo/glances:alpine-latest-full + docker pull nicolargo/glances:latest-full The following tags are availables: -- *alpine-latest-full* for a full Alpine Glances image (latest release) with all dependencies -- *latest-full* for a full Debian Glances image (latest release) with all dependencies -- *alpine-latest* for a basic Alpine Glances (latest release) version with minimal dependencies -- *latest* for a basic Debian Glances image (latest release) with minimal dependencies -- *alpine-dev* for a basic Alpine Glances image (development branch) with all dependencies -- *dev* for a basic Debian Glances image (development branch) with all dependencies - -You can also specify a version (example: *alpine-3.2.7-full*). +- *latest-full* for a full Alpine Glances image (latest release) with all dependencies +- *latest* for a basic Alpine Glances (latest release) version with minimal dependencies (Bottle and Docker) +- *dev* for a basic Alpine Glances image (based on development branch) with all dependencies (Warning: may be instable) Run last version of Glances container in *console mode*: diff --git a/docker-compose/Dockerfile b/docker-compose/Dockerfile index 9d2426a1..81caa69a 100644 --- a/docker-compose/Dockerfile +++ b/docker-compose/Dockerfile @@ -1,3 +1,3 @@ -FROM nicolargo/glances:alpine-dev +FROM nicolargo/glances:latest as glancesminimal COPY glances.conf /glances/conf/glances.conf CMD python -m glances -C /glances/conf/glances.conf $GLANCES_OPT diff --git a/docker-compose/docker-compose-with-traefik.yml b/docker-compose/docker-compose-with-traefik.yml index 91a1d551..db29890f 100644 --- a/docker-compose/docker-compose-with-traefik.yml +++ b/docker-compose/docker-compose-with-traefik.yml @@ -15,7 +15,7 @@ services: - "traefik.frontend.rule=Host:whoami.docker.localhost" monitoring: - image: nicolargo/glances:alpine-dev + image: nicolargo/glances:dev restart: unless-stopped pid: host privileged: true diff --git a/docker-files/alpine.Dockerfile b/docker-files/alpine.Dockerfile index 90fe159e..d8f3e09c 100644 --- a/docker-files/alpine.Dockerfile +++ b/docker-files/alpine.Dockerfile @@ -33,12 +33,15 @@ RUN apk add --no-cache \ FROM build as buildRequirements ARG PYTHON_VERSION + COPY requirements.txt . -COPY webui-requirements.txt . RUN pip3 install --no-cache-dir --user -r requirements.txt + # Minimal means no webui, but it break what is done previously (see #2155) # So install the webui requirements... +COPY webui-requirements.txt . RUN pip3 install --no-cache-dir --user -r webui-requirements.txt + # As minimal image we want to monitor others docker containers RUN pip3 install --no-cache-dir --user docker @@ -48,10 +51,9 @@ RUN pip3 install --no-cache-dir --user glances ############################################################################## -FROM build as buildOptionalRequirements +FROM buildRequirements as buildOptionalRequirements ARG PYTHON_VERSION -COPY requirements.txt . COPY optional-requirements.txt . RUN CASS_DRIVER_NO_CYTHON=1 pip3 install --no-cache-dir --user -r optional-requirements.txt @@ -70,9 +72,8 @@ COPY ./docker-compose/glances.conf /etc/glances.conf # EXPOSE PORT (XMLRPC / WebUI) EXPOSE 61209 61208 -WORKDIR /glances - # Define default command. +WORKDIR /glances CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT ############################################################################## @@ -85,6 +86,8 @@ ARG PYTHON_VERSION RUN apk add --no-cache \ python3 \ + py3-packaging \ + py3-dateutil \ curl \ lm-sensors \ wireless-tools \ @@ -94,10 +97,11 @@ COPY --from=buildRequirements /root/.local/bin /usr/local/bin/ COPY --from=buildRequirements /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_VERSION}/site-packages/ COPY ./docker-compose/glances.conf /etc/glances.conf -# EXPOSE PORT (XMLRPC only because WebUI is not available) -EXPOSE 61209 +# EXPOSE PORT (XMLRPC / WebUI) +EXPOSE 61209 61208 # Define default command. +WORKDIR /glances CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT ############################################################################## @@ -122,7 +126,6 @@ EXPOSE 61209 61208 RUN ln -sf /dev/stdout /tmp/glances-root.log \ && ln -sf /dev/stderr /var/log/error.log -WORKDIR /glances - # Define default command. +WORKDIR /glances CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT diff --git a/docker-files/debian.Dockerfile b/docker-files/debian.Dockerfile deleted file mode 100644 index 9087bcf7..00000000 --- a/docker-files/debian.Dockerfile +++ /dev/null @@ -1,130 +0,0 @@ -# -# Glances Dockerfile (based on Debian) -# -# https://github.com/nicolargo/glances -# - -# WARNING: the version should be set. -# Ex: Python 3.11 for 3.11-slim-buster -# Note: ENV is for future running containers. ARG for building your Docker image. - -ARG PYTHON_IMAGE_VERSION=3.11 -ARG IMAGE_VERSION=${PYTHON_IMAGE_VERSION}-slim-buster -FROM python:${IMAGE_VERSION} as build -ARG PYTHON_VERSION - -# Install package -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - python3-dev \ - curl \ - build-essential \ - lm-sensors \ - wireless-tools \ - smartmontools \ - iputils-ping && \ - apt-get clean && rm -rf /var/lib/apt/lists/* - -############################################################################## -# Install the dependencies beforehand to make them cacheable - -FROM build as buildRequirements -ARG PYTHON_VERSION -COPY requirements.txt . -COPY webui-requirements.txt . -RUN pip3 install --no-cache-dir --user -r requirements.txt -# Minimal means no webui, but it break what is done previously (see #2155) -# So install the webui requirements... -RUN pip3 install --no-cache-dir --user -r webui-requirements.txt -# As minimal image we want to monitor others docker containers -RUN pip3 install --no-cache-dir --user docker - -# Force install otherwise it could be cached without rerun -ARG CHANGING_ARG -RUN pip3 install --no-cache-dir --user glances - -############################################################################## - -FROM build as buildOptionalRequirements -ARG PYTHON_VERSION - -COPY requirements.txt . -COPY optional-requirements.txt . -RUN CASS_DRIVER_NO_CYTHON=1 pip3 install --no-cache-dir --user -r optional-requirements.txt - -############################################################################## -# full image -############################################################################## - -FROM build as full -ARG PYTHON_VERSION -ARG PYTHON_IMAGE_VERSION - -COPY --from=buildRequirements /root/.local/bin /usr/local/bin/ -COPY --from=buildRequirements /root/.local/lib/python${PYTHON_IMAGE_VERSION}/site-packages /usr/local/lib/python${PYTHON_IMAGE_VERSION}/site-packages/ -COPY --from=buildOptionalRequirements /root/.local/lib/python${PYTHON_IMAGE_VERSION}/site-packages /usr/local/lib/python${PYTHON_IMAGE_VERSION}/site-packages/ -COPY ./docker-compose/glances.conf /etc/glances.conf - -# EXPOSE PORT (XMLRPC / WebUI) -EXPOSE 61209 61208 - -WORKDIR /glances - -# Define default command. -CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT - -############################################################################## -# minimal image -############################################################################## - -# Create running images without any building dependency -FROM python:${IMAGE_VERSION} as minimal -ARG PYTHON_VERSION -ARG PYTHON_IMAGE_VERSION - -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - curl \ - lm-sensors \ - wireless-tools \ - smartmontools \ - iputils-ping && \ - apt-get clean && rm -rf /var/lib/apt/lists/* - -COPY --from=buildRequirements /root/.local/bin /usr/local/bin/ -COPY --from=buildRequirements /root/.local/lib/python${PYTHON_IMAGE_VERSION}/site-packages /usr/local/lib/python${PYTHON_IMAGE_VERSION}/site-packages/ -COPY ./docker-compose/glances.conf /etc/glances.conf - -# EXPOSE PORT (XMLRPC) -EXPOSE 61209 - -# Define default command. -CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT - -############################################################################## -# dev image -############################################################################## - -FROM full as dev -ARG PYTHON_VERSION -ARG PYTHON_IMAGE_VERSION - -COPY --from=buildRequirements /root/.local/bin /usr/local/bin/ -COPY --from=buildRequirements /root/.local/lib/python${PYTHON_IMAGE_VERSION}/site-packages /usr/lib/python${PYTHON_IMAGE_VERSION}/site-packages/ -COPY --from=buildOptionalRequirements /root/.local/lib/python${PYTHON_IMAGE_VERSION}/site-packages /usr/lib/python${PYTHON_IMAGE_VERSION}/site-packages/ -COPY ./docker-compose/glances.conf /etc/glances.conf - -# Copy the current Glances source code -COPY . /glances - -# EXPOSE PORT (XMLRPC / WebUI) -EXPOSE 61209 61208 - -# Forward access and error logs to Docker's log collector -RUN ln -sf /dev/stdout /tmp/glances-root.log \ - && ln -sf /dev/stderr /var/log/error.log - -WORKDIR /glances - -# Define default command. -CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT