diff options
author | nicolargo <nicolas@nicolargo.com> | 2022-09-24 11:38:13 +0200 |
---|---|---|
committer | nicolargo <nicolas@nicolargo.com> | 2022-09-24 11:38:13 +0200 |
commit | e1a85a24f7736cdc732df699728ac4ba1914b177 (patch) | |
tree | d80d18154e778740864bbe0a3ebcf01580e83716 | |
parent | 265ed00129168cb3d7b6feb7a8b8de3c9c788ef3 (diff) |
Refactor Docker file CI
-rw-r--r-- | .dockerignore | 2 | ||||
-rw-r--r-- | docker-files/alpine.Dockerfile | 46 | ||||
-rw-r--r-- | docker-files/debian.Dockerfile | 41 |
3 files changed, 58 insertions, 31 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c2e5dbd2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +.git diff --git a/docker-files/alpine.Dockerfile b/docker-files/alpine.Dockerfile index 3a26c2de..364f1ed9 100644 --- a/docker-files/alpine.Dockerfile +++ b/docker-files/alpine.Dockerfile @@ -28,23 +28,27 @@ RUN apk add --no-cache \ wireless-tools \ iputils +############################################################################## +# Install the dependencies beforehand to make them cacheable -FROM build as remoteInstall +FROM build as buildRequirements ARG PYTHON_VERSION -# Install the dependencies beforehand to make them cacheable COPY requirements.txt . RUN pip3 install --no-cache-dir --user -r 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[all]" +RUN pip3 install --no-cache-dir --user glances +############################################################################## -FROM build as additional-packages +FROM build as buildOptionalRequirements ARG PYTHON_VERSION -COPY *requirements.txt ./ - +COPY requirements.txt . +COPY optional-requirements.txt . RUN CASS_DRIVER_NO_CYTHON=1 pip3 install --no-cache-dir --user -r optional-requirements.txt ############################################################################## @@ -54,9 +58,9 @@ RUN CASS_DRIVER_NO_CYTHON=1 pip3 install --no-cache-dir --user -r optional-requi FROM build as full ARG PYTHON_VERSION -COPY --from=remoteInstall /root/.local/bin /usr/local/bin/ -COPY --from=remoteInstall /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_VERSION}/site-packages/ -COPY --from=additional-packages /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_VERSION}/site-packages/ +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 --from=buildOptionalRequirements /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 / WebUI) @@ -82,19 +86,35 @@ RUN apk add --no-cache \ wireless-tools \ iputils -COPY --from=remoteInstall /root/.local/bin /usr/local/bin/ -COPY --from=remoteInstall /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_VERSION}/site-packages/ +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) +# EXPOSE PORT (XMLRPC only because WebUI is not available) EXPOSE 61209 # Define default command. CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT ############################################################################## -# dev image (=full) +# dev image ############################################################################## FROM full as dev +ARG PYTHON_VERSION + +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 --from=buildOptionalRequirements /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_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 + +WORKDIR /glances + +# Define default command. +CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT diff --git a/docker-files/debian.Dockerfile b/docker-files/debian.Dockerfile index 596e258d..34200bba 100644 --- a/docker-files/debian.Dockerfile +++ b/docker-files/debian.Dockerfile @@ -25,23 +25,27 @@ RUN apt-get update && \ iputils-ping && \ apt-get clean && rm -rf /var/lib/apt/lists/* +############################################################################## +# Install the dependencies beforehand to make them cacheable -FROM build as remoteInstall +FROM build as buildRequirements ARG PYTHON_VERSION -# Install the dependencies beforehand to make them cacheable COPY requirements.txt . RUN pip3 install --no-cache-dir --user -r 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[all]" +RUN pip3 install --no-cache-dir --user glances +############################################################################## -FROM build as additional-packages +FROM build as buildOptionalRequirements ARG PYTHON_VERSION -COPY *requirements.txt ./ - +COPY requirements.txt . +COPY optional-requirements.txt . RUN CASS_DRIVER_NO_CYTHON=1 pip3 install --no-cache-dir --user -r optional-requirements.txt ############################################################################## @@ -51,10 +55,9 @@ RUN CASS_DRIVER_NO_CYTHON=1 pip3 install --no-cache-dir --user -r optional-requi FROM build as full ARG PYTHON_VERSION -COPY --from=remoteInstall /root/.local/bin /usr/local/bin/ -COPY --from=remoteInstall /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages/ -COPY --from=additional-packages /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages/ -COPY . /glances +COPY --from=buildRequirements /root/.local/bin /usr/local/bin/ +COPY --from=buildRequirements /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages/ +COPY --from=buildOptionalRequirements /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages/ COPY ./docker-compose/glances.conf /etc/glances.conf # EXPOSE PORT (XMLRPC / WebUI) @@ -82,8 +85,8 @@ RUN apt-get update && \ iputils-ping && \ apt-get clean && rm -rf /var/lib/apt/lists/* -COPY --from=remoteInstall /root/.local/bin /usr/local/bin/ -COPY --from=remoteInstall /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages/ +COPY --from=buildRequirements /root/.local/bin /usr/local/bin/ +COPY --from=buildRequirements /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages/ COPY ./docker-compose/glances.conf /etc/glances.conf # EXPOSE PORT (XMLRPC) @@ -93,17 +96,20 @@ EXPOSE 61209 CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT ############################################################################## -# dev image (=full) +# dev image ############################################################################## -FROM build as dev +FROM full as dev ARG PYTHON_VERSION -COPY --from=remoteInstall /root/.local/bin /usr/local/bin/ -COPY --from=remoteInstall /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_VERSION}/site-packages/ -COPY --from=additional-packages /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_VERSION}/site-packages/ +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 --from=buildOptionalRequirements /root/.local/lib/python${PYTHON_VERSION}/site-packages /usr/lib/python${PYTHON_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 @@ -111,4 +117,3 @@ WORKDIR /glances # Define default command. CMD python3 -m glances -C /etc/glances.conf $GLANCES_OPT - |