Skip to content

Commit 2465207

Browse files
feat: add layer-cleanup.sh script
1 parent d694c4c commit 2465207

File tree

9 files changed

+126
-51
lines changed

9 files changed

+126
-51
lines changed

.github/actions/publish-docker/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ runs:
106106
commands=$(cat << "EOF"
107107
USER root
108108
COPY ./git_debug_image.sh ./git_debug_image.sh
109-
RUN set -e; chmod u+x ./git_debug_image.sh; ./git_debug_image.sh ${{ inputs.branch_name }}; \
110-
rm -f ./git_debug_image.sh
109+
RUN set -e; chmod u+x ./git_debug_image.sh; apt update && ./git_debug_image.sh ${{ inputs.branch_name }}; \
110+
rm -f ./git_debug_image.sh ; layer-cleanup.sh
111111
WORKDIR /home/user/rs-server
112112
EOF
113113
)

.github/scripts/layer-cleanup.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Copyright 2024 CS Group
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
apt-get autoclean --yes
17+
apt-get autoremove --yes
18+
19+
rm -rf /var/lib/apt/lists/*
20+
rm -rf /etc/apt/sources.list.d/*
21+
rm -rf /usr/local/src/*
22+
23+
rm -rf /var/cache/apt/*
24+
rm -rf /root/.cache/*
25+
# including /root/.cache/pip
26+
rm -rf /usr/local/share/.cache/*
27+
# including /usr/local/share/.cache/yarn
28+
29+
rm -rf /tmp/* /var/tmp/*
30+
rm -rf /opt/conda/pkgs/cache
31+
32+
rm -rf /tmp/whl
33+
34+
exit 0

.github/workflows/publish-binaries.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,17 @@ jobs:
268268
with:
269269
name: ${{ needs.services-common-whl.outputs.package_name }}
270270
path: ./build_context_path
271+
271272
- name: Download .whl dependencies
272273
uses: actions/download-artifact@v5
273274
with:
274275
name: ${{ needs.services-adgs-whl.outputs.package_name }}
275276
path: ./build_context_path
276277

278+
- name: Copy layer-cleanup.sh script
279+
run: cp -t ./build_context_path ./.github/scripts/layer-cleanup.sh
280+
shell: bash
281+
277282
- name: Copy debug mode dependencies
278283
if: ${{ needs.set-env.outputs.debug_mode }} == true
279284
run: cp -t ./build_context_path ./.github/scripts/git_debug_image.sh
@@ -310,12 +315,17 @@ jobs:
310315
with:
311316
name: ${{ needs.services-common-whl.outputs.package_name }}
312317
path: ./build_context_path
318+
313319
- name: Download .whl dependencies
314320
uses: actions/download-artifact@v5
315321
with:
316322
name: ${{ needs.services-cadip-whl.outputs.package_name }}
317323
path: ./build_context_path
318324

325+
- name: Copy layer-cleanup.sh script
326+
run: cp -t ./build_context_path ./.github/scripts/layer-cleanup.sh
327+
shell: bash
328+
319329
- name: Copy debug mode dependencies
320330
if: ${{ needs.set-env.outputs.debug_mode }} == true
321331
run: cp -t ./build_context_path ./.github/scripts/git_debug_image.sh
@@ -351,12 +361,17 @@ jobs:
351361
with:
352362
name: ${{ needs.services-common-whl.outputs.package_name }}
353363
path: ./build_context_path
364+
354365
- name: Download .whl dependencies
355366
uses: actions/download-artifact@v5
356367
with:
357368
name: ${{ needs.services-catalog-whl.outputs.package_name }}
358369
path: ./build_context_path
359370

371+
- name: Copy layer-cleanup.sh script
372+
run: cp -t ./build_context_path ./.github/scripts/layer-cleanup.sh
373+
shell: bash
374+
360375
- name: Copy debug mode dependencies
361376
if: ${{ needs.set-env.outputs.debug_mode }} == true
362377
run: cp -t ./build_context_path ./.github/scripts/git_debug_image.sh
@@ -399,6 +414,10 @@ jobs:
399414
run: cp ./services/frontend/.github/entrypoint_frontend.sh ./build_context_path
400415
shell: bash
401416

417+
- name: Copy layer-cleanup.sh script
418+
run: cp -t ./build_context_path ./.github/scripts/layer-cleanup.sh
419+
shell: bash
420+
402421
- name: Copy debug mode dependencies
403422
if: ${{ needs.set-env.outputs.debug_mode }} == true
404423
run: cp -t ./build_context_path ./.github/scripts/git_debug_image.sh
@@ -435,12 +454,17 @@ jobs:
435454
with:
436455
name: ${{ needs.services-common-whl.outputs.package_name }}
437456
path: ./build_context_path
457+
438458
- name: Download .whl dependencies
439459
uses: actions/download-artifact@v5
440460
with:
441461
name: ${{ needs.services-staging-whl.outputs.package_name }}
442462
path: ./build_context_path
443463

464+
- name: Copy layer-cleanup.sh script
465+
run: cp -t ./build_context_path ./.github/scripts/layer-cleanup.sh
466+
shell: bash
467+
444468
- name: Copy debug mode dependencies
445469
if: ${{ needs.set-env.outputs.debug_mode }} == true
446470
run: cp -t ./build_context_path ./.github/scripts/git_debug_image.sh
@@ -477,12 +501,17 @@ jobs:
477501
with:
478502
name: ${{ needs.services-common-whl.outputs.package_name }}
479503
path: ./build_context_path
504+
480505
- name: Download .whl dependencies
481506
uses: actions/download-artifact@v5
482507
with:
483508
name: ${{ needs.services-staging-whl.outputs.package_name }}
484509
path: ./build_context_path
485510

511+
- name: Copy layer-cleanup.sh script
512+
run: cp -t ./build_context_path ./.github/scripts/layer-cleanup.sh
513+
shell: bash
514+
486515
- id: publish-docker
487516
uses: ./.github/actions/publish-docker
488517
with:

services/adgs/.github/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
# Don't use alpine, it's too different from the build stage.
1616
FROM ghcr.io/rs-python/python:3.11.7-slim-bookworm
1717

18+
COPY ./layer-cleanup.sh /usr/local/bin/
19+
RUN chmod 755 /usr/local/bin/layer-cleanup.sh
20+
1821
# Install git to install dependencies from forked repositories
19-
RUN apt update && apt upgrade -y && apt install -y git
22+
RUN apt update && apt upgrade -y && apt install -y git && layer-cleanup.sh
2023

2124
# Update pip version
22-
RUN pip install --no-cache-dir --upgrade pip
25+
RUN pip install --no-cache-dir --upgrade pip && layer-cleanup.sh
2326

2427
# The CI builds the wheel packages, downloads them into ./whl/, then builds this Dockerfile from ./whl/,
2528
# so the .whl files are under ./*.whl
@@ -32,16 +35,14 @@ ADD ./*.whl /tmp/whl
3235
# https://home.rs-python.eu/local-pypi is used for additional dependencies, see: https://github.com/RS-PYTHON/local-pypi
3336
RUN cd /tmp/whl && pip install --no-cache-dir \
3437
--extra-index-url=https://home.rs-python.eu/local-pypi/ \
35-
rs_server_common-*.whl rs_server_adgs-*.whl
38+
rs_server_common-*.whl rs_server_adgs-*.whl && \
39+
layer-cleanup.sh
3640

3741
# Install opentelemetry instrumentation packages for dependencies
38-
RUN opentelemetry-bootstrap -a install
42+
RUN opentelemetry-bootstrap -a install && layer-cleanup.sh
3943

4044
# Remove dependencies that are need only for compilation, not execution
41-
RUN apt autoremove -y git
42-
43-
# Clean everything
44-
RUN rm -rf /tmp/whl /root/.cache/pip /var/cache/apt/archives /var/lib/apt/lists/*
45+
RUN apt autoremove -y git && layer-cleanup.sh
4546

4647
# Add a default user
4748
RUN useradd -m user

services/cadip/.github/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
# Don't use alpine, it's too different from the build stage.
1616
FROM ghcr.io/rs-python/python:3.11.7-slim-bookworm
1717

18+
COPY ./layer-cleanup.sh /usr/local/bin/
19+
RUN chmod 755 /usr/local/bin/layer-cleanup.sh
20+
1821
# Install git to install dependencies from forked repositories
19-
RUN apt update && apt upgrade -y && apt install -y git
22+
RUN apt update && apt upgrade -y && apt install -y git && layer-cleanup.sh
2023

2124
# Update pip version
22-
RUN pip install --no-cache-dir --upgrade pip
25+
RUN pip install --no-cache-dir --upgrade pip && layer-cleanup.sh
2326

2427
# The CI builds the wheel packages, downloads them into ./whl/, then builds this Dockerfile from ./whl/,
2528
# so the .whl files are under ./*.whl
@@ -32,16 +35,14 @@ ADD ./*.whl /tmp/whl
3235
# https://home.rs-python.eu/local-pypi is used for additional dependencies, see: https://github.com/RS-PYTHON/local-pypi
3336
RUN cd /tmp/whl && pip install --no-cache-dir \
3437
--extra-index-url=https://home.rs-python.eu/local-pypi/ \
35-
rs_server_common-*.whl rs_server_cadip-*.whl
38+
rs_server_common-*.whl rs_server_cadip-*.whl && \
39+
layer-cleanup.sh
3640

3741
# Install opentelemetry instrumentation packages for dependencies
38-
RUN opentelemetry-bootstrap -a install
42+
RUN opentelemetry-bootstrap -a install && layer-cleanup.sh
3943

4044
# Remove dependencies that are need only for compilation, not execution
41-
RUN apt autoremove -y git
42-
43-
# Clean everything
44-
RUN rm -rf /tmp/whl /root/.cache/pip /var/cache/apt/archives /var/lib/apt/lists/*
45+
RUN apt autoremove -y git && layer-cleanup.sh
4546

4647
# Add a default user
4748
RUN useradd -m user

services/catalog/.github/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
# Don't use alpine, it's too different from the build stage.
1616
FROM ghcr.io/rs-python/python:3.11.7-slim-bookworm
1717

18+
COPY ./layer-cleanup.sh /usr/local/bin/
19+
RUN chmod 755 /usr/local/bin/layer-cleanup.sh
20+
1821
# Install git to install dependencies from forked repositories
19-
RUN apt update && apt upgrade -y && apt install -y git
22+
RUN apt update && apt upgrade -y && apt install -y git && layer-cleanup.sh
2023

2124
# Update pip version
22-
RUN pip install --no-cache-dir --upgrade pip
25+
RUN pip install --no-cache-dir --upgrade pip && layer-cleanup.sh
2326

2427
# The CI builds the wheel packages, downloads them into ./whl/, then builds this Dockerfile from ./whl/,
2528
# so the .whl files are under ./*.whl
@@ -32,16 +35,14 @@ ADD ./*.whl /tmp/whl
3235
# https://home.rs-python.eu/local-pypi is used for additional dependencies, see: https://github.com/RS-PYTHON/local-pypi
3336
RUN cd /tmp/whl && pip install --no-cache-dir \
3437
--extra-index-url=https://home.rs-python.eu/local-pypi/ \
35-
rs_server_common-*.whl rs_server_catalog-*.whl
38+
rs_server_common-*.whl rs_server_catalog-*.whl && \
39+
layer-cleanup.sh
3640

3741
# Install opentelemetry instrumentation packages for dependencies
38-
RUN opentelemetry-bootstrap -a install
42+
RUN opentelemetry-bootstrap -a install && layer-cleanup.sh
3943

4044
# Remove dependencies that are need only for compilation, not execution
41-
RUN apt autoremove -y git
42-
43-
# Clean everything
44-
RUN rm -rf /tmp/whl /root/.cache/pip /var/cache/apt/archives /var/lib/apt/lists/*
45+
RUN apt autoremove -y git && layer-cleanup.sh
4546

4647
# Add a default user
4748
RUN useradd -m user

services/frontend/.github/Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
# Build stage for multi stage build.
1717
FROM ghcr.io/rs-python/python:3.11.7-slim-bookworm AS builder
1818

19+
COPY ./layer-cleanup.sh /usr/local/bin/
20+
RUN chmod 755 /usr/local/bin/layer-cleanup.sh
21+
1922
# Install dependencies
20-
RUN apt update && apt upgrade -y && apt install -y libpq-dev gcc
23+
RUN apt update && apt upgrade -y && apt install -y libpq-dev gcc && layer-cleanup.sh
2124

2225
# Update pip version
23-
RUN pip install --no-cache-dir --upgrade pip
26+
RUN pip install --no-cache-dir --upgrade pip && layer-cleanup.sh
2427

2528
# The CI builds the wheel packages, downloads them into ./whl/, then builds this Dockerfile from ./whl/,
2629
# so the .whl files are under ./*.whl
@@ -30,13 +33,16 @@ ADD ./*.whl /tmp/whl
3033

3134
# Install the wheel packages in the right order (dependencies first).
3235
# This also installs all the sub-dependencies e.g. fastapi etc ...
33-
RUN cd /tmp/whl && pip install --no-cache-dir rs_server_frontend-*.whl
36+
RUN cd /tmp/whl && pip install --no-cache-dir rs_server_frontend-*.whl && layer-cleanup.sh
3437

3538
# Final stage. Don't use alpine, it's too different from the build stage.
3639
FROM ghcr.io/rs-python/python:3.11.7-slim-bookworm
3740

41+
COPY ./layer-cleanup.sh /usr/local/bin/
42+
RUN chmod 755 /usr/local/bin/layer-cleanup.sh
43+
3844
# Update dependencies
39-
RUN apt update && apt upgrade -y
45+
RUN apt update && apt upgrade -y && layer-cleanup.sh
4046

4147
# Copy the python installation from the build stage
4248
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
@@ -53,9 +59,6 @@ RUN chmod ugo+x /scripts/entrypoint_frontend.sh
5359
# Give write permissions to the parent directory so sed can work.
5460
RUN chmod -R ugo+w $(dirname "${RSPY_OPENAPI_FILE}")
5561

56-
# Clean everything
57-
RUN rm -rf /tmp/whl /root/.cache/pip /var/cache/apt/archives /var/lib/apt/lists/*
58-
5962
# Add a default user
6063
RUN useradd -m user
6164
USER user

services/staging/.github/Dockerfile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
# Build stage for multi stage build.
1717
FROM ghcr.io/rs-python/python:3.11.7-slim-bookworm AS builder
1818

19+
COPY ./layer-cleanup.sh /usr/local/bin/
20+
RUN chmod 755 /usr/local/bin/layer-cleanup.sh
21+
1922
# Install dependencies for compilation
20-
RUN apt update && apt upgrade -y && apt install -y libpq-dev gcc git
23+
RUN apt update && apt upgrade -y && apt install -y libpq-dev gcc git && layer-cleanup.sh
2124

2225
# Update pip version
23-
RUN pip install --no-cache-dir --upgrade pip
26+
RUN pip install --no-cache-dir --upgrade pip && layer-cleanup.sh
2427

2528
# The CI builds the wheel packages, downloads them into ./whl/, then builds this Dockerfile from ./whl/,
2629
# so the .whl files are under ./*.whl
@@ -33,25 +36,25 @@ ADD ./*.whl /tmp/whl
3336
# https://home.rs-python.eu/local-pypi is used for additional dependencies, see: https://github.com/RS-PYTHON/local-pypi
3437
RUN cd /tmp/whl && pip install --no-cache-dir \
3538
--extra-index-url=https://home.rs-python.eu/local-pypi/ \
36-
rs_server_common-*.whl rs_server_staging-*.whl
39+
rs_server_common-*.whl rs_server_staging-*.whl && \
40+
layer-cleanup.sh
3741

3842
# Final stage. Don't use alpine, it's too different from the build stage.
3943
FROM ghcr.io/rs-python/python:3.11.7-slim-bookworm
4044

45+
COPY ./layer-cleanup.sh /usr/local/bin/
46+
RUN chmod 755 /usr/local/bin/layer-cleanup.sh
47+
4148
# Install dependencies necessary for execution (e.g. libpq) not compilation (gcc)
42-
RUN \
43-
apt update && apt upgrade -y && \
49+
RUN apt update && apt upgrade -y && \
4450
apt install -y libpq-dev libexpat1 && \
45-
rm -rf /var/cache/apt/archives /var/lib/apt/lists/*
51+
layer-cleanup.sh
4652

4753
# Copy the whole /usr/local dir (that contains the python installation) from the build stage
4854
COPY --from=builder /usr/local /usr/local
4955

5056
# Install opentelemetry instrumentation packages for dependencies
51-
RUN opentelemetry-bootstrap -a install
52-
53-
# Clean everything
54-
RUN rm -rf /tmp/whl /root/.cache/pip /var/cache/apt/archives /var/lib/apt/lists/*
57+
RUN opentelemetry-bootstrap -a install && layer-cleanup.sh
5558

5659
# Add a default user
5760
RUN useradd -m user

0 commit comments

Comments
 (0)