Skip to content

Commit

Permalink
Add Slim Image
Browse files Browse the repository at this point in the history
Adds an image with only one python version installed. This can be useful
in development environments for other projects where the multi-version
features are less useful than a more efficient container.

Signed-off-by: Hassan Abouelela <[email protected]>
  • Loading branch information
HassanAbouelela committed Mar 18, 2023
1 parent fe865e1 commit 3d9eff4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ jobs:
with:
name: ${{ inputs.artifact }}

- name: Set up Python
id: python
uses: actions/setup-python@v4
with:
python-version: "3.11"

# Load the image to make use of common layers during the final build.
- name: Load image from archive
run: docker load -i ${{ inputs.artifact }}.tar
Expand Down Expand Up @@ -106,3 +112,24 @@ jobs:
tags: |
ghcr.io/python-discord/snekbox-venv:latest
ghcr.io/python-discord/snekbox-venv:${{ inputs.version }}
# Build a lightweight image with a singular python version
- name: Regenerate dockerfile
run: python scripts/set_versions.py
env:
VERSIONS_CONFIG: config/versions-light.json

- name: Build & push slim image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: true
cache-from: |
ghcr.io/python-discord/snekbox-base:latest
ghcr.io/python-discord/snekbox-venv:latest
ghcr.io/python-discord/snekbox:latest
cache-to: type=inline
tags: |
ghcr.io/python-discord/snekbox:latest-slim
ghcr.io/python-discord/snekbox:${{ inputs.version }}-slim
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ RUN make
# ------------------------------------------------------------------------------
FROM python:3.11-slim-buster as base-first

FROM python:3.10-slim-buster as base-3-10
FROM python:3.7-slim-buster as base-3-7
COPY --from=base-first / /

FROM python:3.9-slim-buster as base-3-9
COPY --from=base-3-7 / /

# ------------------------------------------------------------------------------
FROM python:3.11-slim-buster as base

COPY --from=base-3-10 / /
COPY --from=base-3-9 / /

# Everything will be a user install to allow snekbox's dependencies to be kept
# separate from the packages exposed during eval.
Expand Down
8 changes: 8 additions & 0 deletions config/versions-light.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"image_tag": "3.11-slim-buster",
"version_name": "3.11",
"display_name": "CPython 3.11",
"is_main": true
}
]
12 changes: 9 additions & 3 deletions config/versions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[
{
"image_tag": "3.10-slim-buster",
"version_name": "3.10",
"display_name": "CPython 3.10",
"image_tag": "3.7-slim-buster",
"version_name": "3.7",
"display_name": "CPython 3.7",
"is_main": false
},
{
"image_tag": "3.9-slim-buster",
"version_name": "3.9",
"display_name": "CPython 3.9",
"is_main": false
},
{
Expand Down

0 comments on commit 3d9eff4

Please sign in to comment.