Skip to content

Commit d4ccc4a

Browse files
committed
add python base image
1 parent 8ad53ff commit d4ccc4a

File tree

6 files changed

+162
-2
lines changed

6 files changed

+162
-2
lines changed

.github/workflows/build_lean.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
name: Build and Push Docker Image
2525
runs-on: ubuntu-latest
2626
concurrency:
27-
group: ${{ github.ref }}-lean-${{ matrix.lean_version}}
27+
group: ${{ github.ref }}-lean-${{ matrix.lean_version }}
2828
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.ref_name != github.event.repository.default_branch }}
2929
strategy:
3030
matrix:

.github/workflows/build_python.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build Scratch Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "python/**"
9+
pull_request:
10+
paths:
11+
- "python/**"
12+
workflow_dispatch:
13+
inputs:
14+
no-cache:
15+
description: "Disable cache for build"
16+
required: false
17+
default: false
18+
type: boolean
19+
repository_dispatch:
20+
types: [trigger-build]
21+
22+
jobs:
23+
build:
24+
name: Build and Push Docker Image
25+
runs-on: ubuntu-latest
26+
concurrency:
27+
group: ${{ github.ref }}-python-${{ matrix.python_version }}
28+
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.ref_name != github.event.repository.default_branch }}
29+
strategy:
30+
matrix:
31+
python_version: [3.9, 3.10, 3.11, 3.12]
32+
permissions:
33+
contents: read
34+
packages: write
35+
id-token: write
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Set up QEMU
43+
if: github.ref_name == github.event.repository.default_branch
44+
uses: docker/setup-qemu-action@v3
45+
46+
- name: Set up Docker Buildx (QEMU)
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Login to Github Packages
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ghcr.io
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Extract metadata for Docker
57+
id: meta
58+
uses: docker/metadata-action@v5
59+
with:
60+
flavor: |
61+
suffix=-${{ matrix.python_version }}
62+
tags: |
63+
type=schedule
64+
type=ref,event=branch
65+
type=ref,event=tag
66+
type=ref,event=pr
67+
type=raw,value=${{ matrix.python_version }},suffix=,enable={{is_default_branch}}
68+
type=raw,value=latest,suffix=,enable=${{ github.ref_name == github.event.repository.default_branch && matrix.python_version == '3.12' }}
69+
type=edge,branch=main
70+
images: |
71+
ghcr.io/${{ github.repository }}/python
72+
73+
- name: Build and push
74+
uses: docker/build-push-action@v4
75+
with:
76+
context: python
77+
pull: true
78+
push: ${{ !(github.event_name == 'push' && github.ref_name != github.event.repository.default_branch) }}
79+
platforms: ${{ (github.ref_type == 'tag' || github.ref_name == github.event.repository.default_branch) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
80+
provenance: false
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}
83+
no-cache: ${{ inputs.no-cache || false }}
84+
cache-from: type=gha
85+
cache-to: type=gha,mode=max,ignore-error=true
86+
build-args: |
87+
PYTHON_VERSION=${{ matrix.python_version }}

python/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
ARG DEBIAN_VERSION=bookworm
2+
ARG SHIMMY_VERSION=latest
3+
ARG PYTHON_VERSION=3.11
4+
5+
FROM ghcr.io/lambda-feedback/shimmy:${SHIMMY_VERSION} as shimmy
6+
7+
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} as base
8+
9+
# set common workdir
10+
WORKDIR /app
11+
12+
FROM base as lambda-rie
13+
14+
# Install curl
15+
RUN apt-get update && apt-get install -y \
16+
curl \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# Install the AWS Lambda Runtime Interface Emulator
20+
RUN case $(uname -m) in \
21+
"aarch64") export RIE_BINARY_NAME="aws-lambda-rie-arm64" ;; \
22+
*) export RIE_BINARY_NAME="aws-lambda-rie" ;; \
23+
esac && \
24+
curl -Lo /usr/local/bin/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/${RIE_BINARY_NAME} && \
25+
chmod +x /usr/local/bin/aws-lambda-rie
26+
27+
FROM base
28+
29+
ENV LOG_FORMAT="production"
30+
31+
# add shimmy
32+
COPY --from=shimmy /shimmy /usr/local/bin/shimmy
33+
34+
# add aws-lambda-rie
35+
COPY --from=lambda-rie /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
36+
37+
# Copy the entrypoint script
38+
COPY ./entrypoint.sh /entrypoint.sh
39+
40+
ENTRYPOINT [ "/entrypoint.sh" ]
41+
42+
CMD [ "shimmy" ]

python/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Python Evaluation Function Base Image
2+
3+
This is a minimal base image which can be used by evaluation functions written in [Python](https://www.python.org/). It is based on the [`python:3.10-slim`](https://hub.docker.com/_/python) image and adds the necessary components to run evaluation functions written in Python.
4+
5+
## Usage
6+
7+
This image is not meant to be run directly. Instead, it ought to be used as a base image for evaluation functions written in Python. The evaluation function should be placed in the `/app` directory.
8+
9+
Here is an example of a `Dockerfile` that uses this image as a base:
10+
11+
```Dockerfile
12+
FROM ghcr.io/lambda-feedback/evaluation-function-base/python:latest
13+
14+
COPY evaluation_function.py /app/evaluation_function.py
15+
16+
CMD ["shimmy", "-c", "python", "-a", "-m", "evaluation_function"]
17+
```

python/entrypoint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status.
4+
set -e
5+
6+
# Prevent errors in a pipeline from being masked.
7+
set -o pipefail
8+
9+
# start the aws lambda RIE if AWS_LAMBDA_RIE is set, and AWS_LAMBDA_RUNTIME_API is not
10+
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ] && [ -n "${AWS_LAMBDA_RIE}" ]; then
11+
exec aws-lambda-rie "$@"
12+
else
13+
exec "$@"
14+
fi

scratch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a minimal base image which can be used with arbitrary evaluation functio
44

55
## Usage
66

7-
This image is not meant to be run directly. Instead, it ought to be used as a base image for evaluation functions written in Wolfram Language. The evaluation function should be placed in the `/app` directory.
7+
This image is not meant to be run directly. Instead, it ought to be used as a base image for arbitrary evaluation functions. The evaluation function should be placed in the `/app` directory.
88

99
Here is an example of a `Dockerfile` that uses this image as a base:
1010

0 commit comments

Comments
 (0)