From 47b39339a75ef110bc6563c0a608c894e22350fd Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Tue, 5 Nov 2024 16:13:33 +0000 Subject: [PATCH 1/4] Move to Ubuntu 24.04 --- .github/workflows/tox.yaml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tox.yaml b/.github/workflows/tox.yaml index 82bd824..ca9ec8c 100644 --- a/.github/workflows/tox.yaml +++ b/.github/workflows/tox.yaml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + python-version: ['3.12'] steps: - uses: actions/checkout@v4 diff --git a/Dockerfile b/Dockerfile index f556b44..addf46e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM ubuntu:24.04 RUN apt-get update && apt-get upgrade -y && apt-get install python3-pip tini -y && apt-get clean From a080adaa5d9f02ec4dc799c1edf4ec6d01b4f9c1 Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Tue, 5 Nov 2024 16:23:50 +0000 Subject: [PATCH 2/4] Refactor the docker file for build/run stage --- Dockerfile | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index addf46e..ef0267a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,49 @@ -FROM ubuntu:24.04 +FROM ubuntu:24.04 AS build-image -RUN apt-get update && apt-get upgrade -y && apt-get install python3-pip tini -y && apt-get clean +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install python3-venv python3-dev gcc git -y && \ + rm -rf /var/lib/apt/lists/* -COPY ./requirements.txt /opt/os-capacity/requirements.txt -RUN pip install -U -r /opt/os-capacity/requirements.txt +# build into a venv we can copy across +RUN python3 -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" -COPY ./os_capacity/prometheus.py /opt/os-capacity/prometheus.py +COPY ./requirements.txt /os-capacity/requirements.txt +RUN pip install -U pip setuptools +RUN pip install --requirement /os-capacity/requirements.txt + +COPY . /os-capacity +RUN pip install -U /os-capacity + +# +# Now the image we run with +# +FROM ubuntu:24.04 AS run-image + +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install --no-install-recommends python3 tini ca-certificates -y && \ + rm -rf /var/lib/apt/lists/* + +# Copy accross the venv +COPY --from=build-image /opt/venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" + +# Create the user that will be used to run the app +ENV APP_UID=1001 +ENV APP_GID=1001 +ENV APP_USER=app +ENV APP_GROUP=app +RUN groupadd --gid $APP_GID $APP_GROUP && \ + useradd \ + --no-create-home \ + --no-user-group \ + --gid $APP_GID \ + --shell /sbin/nologin \ + --uid $APP_UID \ + $APP_USER + +USER $APP_UID ENTRYPOINT ["tini", "--"] -CMD ["python3", "-u", "/opt/os-capacity/prometheus.py"] +CMD ["os_capacity"] From 49c25989b7904c09ffd0a494d1169ded6ea81f87 Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Tue, 5 Nov 2024 16:48:47 +0000 Subject: [PATCH 3/4] Skip arm for now --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 34fcf65..c4a6818 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -38,7 +38,7 @@ jobs: with: cache-key: os-capacity context: . - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 push: true tags: ${{ steps.image-meta.outputs.tags }} labels: ${{ steps.image-meta.outputs.labels }} From 520c2c6a927d2fb3fb01bb0e3e91747d4d2d6453 Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Tue, 5 Nov 2024 17:11:40 +0000 Subject: [PATCH 4/4] Fix up logging in the docker image --- Dockerfile | 3 +++ README.rst | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ef0267a..c0f7d9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,9 @@ RUN groupadd --gid $APP_GID $APP_GROUP && \ --uid $APP_UID \ $APP_USER +# Don't buffer stdout and stderr as it breaks realtime logging +ENV PYTHONUNBUFFERED=1 + USER $APP_UID ENTRYPOINT ["tini", "--"] CMD ["os_capacity"] diff --git a/README.rst b/README.rst index 48a56d6..632b4ed 100644 --- a/README.rst +++ b/README.rst @@ -46,7 +46,7 @@ Or just run via docker or similar::: docker run -d --name os_capacity \ --mount type=bind,source=/etc/kolla/os-capacity/,target=/etc/openstack \ --env OS_CLOUD=openstack --env OS_CLIENT_CONFIG_FILE=/etc/openstack/clouds.yaml \ - -p 9000:9000 ghcr.io/stackhpc/os-capacity:e08ecb8 + -p 9000:9000 ghcr.io/stackhpc/os-capacity:master curl localhost:9000