Skip to content

Commit 35d1e7b

Browse files
committed
initial setup
0 parents  commit 35d1e7b

12 files changed

Lines changed: 430 additions & 0 deletions

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything
2+
**
3+
4+
!/assets/*

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"

.github/workflows/image-build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: TEMPLATE_PYTHON_PACKAGE Image Builder
2+
3+
on:
4+
push:
5+
branches:
6+
- "CHANGEME"
7+
paths-ignore:
8+
- "**/README.md"
9+
- "templates/**"
10+
- ".github/workflows/versionator.yml"
11+
schedule:
12+
- cron: "4 0 * * WED"
13+
14+
jobs:
15+
Uvicorn-Builder:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python_versions: ["3.8", "3.9", "3.10", "3.11", "3.12"]
21+
package_versions: ["0.4.2"]
22+
target_base: ["full", "slim", "alpine"]
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v2
26+
27+
- name: "Create and push"
28+
uses: multi-py/action-python-image-builder@main
29+
with:
30+
package: "quasiqueue"
31+
package_latest_version: "0.4.2"
32+
maintainer: "Robert Hafner <tedivm@tedivm.com>"
33+
python_version: ${{ matrix.python_versions }}
34+
target_base: ${{ matrix.target_base }}
35+
package_version: ${{ matrix.package_versions }}
36+
registry_password: ${{ secrets.GITHUB_TOKEN }}
37+
platform: "linux/amd64,linux/arm64"
38+
39+
# Uncomment to use local docker files instead of action ones.
40+
#dockerfile: "${{ github.workspace }}/dockerfile"
41+
#docker_build_path: "${{ github.workspace }}/"

.github/workflows/versionator.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: TEMPLATE_PYTHON_PACKAGE Version Updater
2+
3+
# Every 30 minutes check for a new version of the package.
4+
on:
5+
push:
6+
branches:
7+
- "main"
8+
# Don't self-trigger
9+
paths-ignore:
10+
- "**/README.md"
11+
- ".github/workflows/image-build.yml"
12+
schedule:
13+
- cron: "0,30 * * * *"
14+
15+
jobs:
16+
Version-Updater:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v2
21+
with:
22+
token: ${{ secrets.WORKFLOW_GITHUB_TOKEN }}
23+
24+
- name: "Update Builder"
25+
uses: multi-py/action-python-versionator@main
26+
with:
27+
package: "quasiqueue"
28+
git_name: "Robert Hafner"
29+
git_email: "tedivm@tedivm.com"
30+
action_path: ${{ github.workspace }}/.github/workflows/image-build.yml

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Robert Hafner
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# multipy-image-template
2+
3+
<!--ts-->
4+
<!--te-->
5+
6+
## Benefits
7+
8+
### Multi Architecture Builds
9+
10+
Every tag in this repository supports these architectures:
11+
12+
* linux/amd64
13+
* linux/arm64
14+
* linux/arm/v7
15+
16+
17+
### Small Images via Multi Stage Builds
18+
19+
All libraries are compiled in one image before being moved into the final published image. This keeps all of the build tools out of the published container layers.
20+
21+
### No Rate Limits
22+
23+
This project uses the Github Container Registry to store images, which have no rate limiting on pulls (unlike Docker Hub).
24+
25+
### Rapid Building of New Versions
26+
27+
Within 30 minutes of a new release to TEMPLATE_PYTHON_PACKAGE on PyPI builds will kick off for new containers. This means new versions can be used in hours, not days.
28+
29+
### Regular Updates
30+
31+
Containers are rebuilt weekly in order to take on the security patches from upstream containers.
32+
33+
## How To
34+
35+
### Full
36+
37+
To pull the latest slim version:
38+
39+
```bash
40+
docker pull ghcr.io/multi-py/multipy-image-template:py3.10-LATEST
41+
```
42+
43+
To include it in the dockerfile instead:
44+
45+
```dockerfile
46+
FROM ghcr.io/multi-py/multipy-image-template:py3.10-LATEST
47+
```
48+
49+
### Slim
50+
51+
To pull the latest slim version:
52+
53+
```bash
54+
docker pull ghcr.io/multi-py/multipy-image-template:py3.10-slim-LATEST
55+
```
56+
57+
To include it in the dockerfile instead:
58+
59+
```dockerfile
60+
FROM ghcr.io/multi-py/multipy-image-template:py3.10-slim-LATEST
61+
```
62+
63+
### Copy Just the Packages
64+
65+
It's also possible to copy just the Python packages themselves. This is particularly useful when you want to use the precompiled libraries from multiple containers.
66+
67+
```dockerfile
68+
FROM python:3.10
69+
70+
COPY --from=ghcr.io/multi-py/multipy-image-template:py3.10-slim-LATEST /usr/local/lib/python3.10/site-packages/* /usr/local/lib/python3.10/site-packages/
71+
```
72+
73+
74+
75+
## Python Versions
76+
77+
This project actively supports these Python versions:
78+
79+
* 3.10
80+
* 3.9
81+
* 3.8
82+
* 3.7
83+
* 3.6
84+
85+
86+
## Image Variants
87+
88+
Like the upstream Python containers themselves a variety of image variants are supported.
89+
90+
91+
### Full
92+
93+
The default container type, and if you're not sure what container to use start here. It has a variety of libraries and build tools installed, making it easy to extend.
94+
95+
96+
97+
### Slim
98+
99+
This container is similar to Full but with far less libraries and tools installed by default. If yo're looking for the tiniest possible image with the most stability this is your best bet.
100+
101+
102+
103+
### Alpine
104+
105+
This container is provided for those who wish to use Alpine. Alpine works a bit differently than the other image types, as it uses `musl` instead of `glibc` and many libaries are not well tested under `musl` at this time.
106+
107+
108+
109+
## Architectures
110+
111+
Every tag in this repository supports these architectures:
112+
113+
* linux/amd64
114+
* linux/arm64
115+
* linux/arm/v7
116+
117+
118+
## Sponsorship
119+
120+
If you get use out of these containers please consider sponsoring me using Github!
121+
<center>
122+
123+
[![Github Sponsorship](https://raw.githubusercontent.com/mechPenSketch/mechPenSketch/master/img/github_sponsor_btn.svg)](https://github.com/sponsors/tedivm)
124+
125+
</center>
126+
127+
## Tags
128+
129+
* Recommended Image: `ghcr.io/multi-py/multipy-image-template:py3.10-0.1.1`
130+
* Slim Image: `ghcr.io/multi-py/multipy-image-template:py3.10-slim-0.1.1`
131+
132+
Tags are based on the package version, python version, and the upstream container the container is based on.
133+
134+
| TEMPLATE_PYTHON_PACKAGE Version | Python Version | Full Container | Slim Container | Alpine Container |
135+
|-----------------------|----------------|----------------|----------------|------------------|
136+
| latest | 3.10 | py3.10-latest | py3.10-slim-latest | py3.10-alpine-latest |
137+
| latest | 3.9 | py3.9-latest | py3.9-slim-latest | py3.9-alpine-latest |
138+
| latest | 3.8 | py3.8-latest | py3.8-slim-latest | py3.8-alpine-latest |
139+
| latest | 3.7 | py3.7-latest | py3.7-slim-latest | py3.7-alpine-latest |
140+
| latest | 3.6 | py3.6-latest | py3.6-slim-latest | py3.6-alpine-latest |
141+
| 0.1.1 | 3.10 | py3.10-0.1.1 | py3.10-slim-0.1.1 | py3.10-alpine-0.1.1 |
142+
| 0.1.1 | 3.9 | py3.9-0.1.1 | py3.9-slim-0.1.1 | py3.9-alpine-0.1.1 |
143+
| 0.1.1 | 3.8 | py3.8-0.1.1 | py3.8-slim-0.1.1 | py3.8-alpine-0.1.1 |
144+
| 0.1.1 | 3.7 | py3.7-0.1.1 | py3.7-slim-0.1.1 | py3.7-alpine-0.1.1 |
145+
| 0.1.1 | 3.6 | py3.6-0.1.1 | py3.6-slim-0.1.1 | py3.6-alpine-0.1.1 |
146+
| 0.1.0 | 3.10 | py3.10-0.1.0 | py3.10-slim-0.1.0 | py3.10-alpine-0.1.0 |
147+
| 0.1.0 | 3.9 | py3.9-0.1.0 | py3.9-slim-0.1.0 | py3.9-alpine-0.1.0 |
148+
| 0.1.0 | 3.8 | py3.8-0.1.0 | py3.8-slim-0.1.0 | py3.8-alpine-0.1.0 |
149+
| 0.1.0 | 3.7 | py3.7-0.1.0 | py3.7-slim-0.1.0 | py3.7-alpine-0.1.0 |
150+
| 0.1.0 | 3.6 | py3.6-0.1.0 | py3.6-slim-0.1.0 | py3.6-alpine-0.1.0 |
151+
152+
153+
### Older Tags
154+
155+
Older tags are left for historic purposes but do not receive updates. A full list of tags can be found on the package's [registry page](https://github.com/multi-py/multipy-image-template/pkgs/container/multipy-image-template).
156+
157+

assets/main.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import asyncio
2+
3+
from quasiqueue import QuasiQueue
4+
5+
6+
async def writer(desired: int):
7+
"""Feeds data to the Queue when it is low.
8+
"""
9+
for x in range(0, desired):
10+
yield x
11+
12+
13+
14+
async def reader(identifier: int|str):
15+
"""Receives individual items from the queue.
16+
17+
Args:
18+
identifier (int | str): Comes from the output of the Writer function
19+
"""
20+
print(f"{identifier}")
21+
22+
23+
runner = QuasiQueue(
24+
"hello_world",
25+
reader=reader,
26+
writer=writer,
27+
)
28+
29+
if __name__ == '__main__':
30+
asyncio.run(runner.main())

assets/start.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /usr/bin/env bash
2+
set -e
3+
4+
#
5+
# The follow block comes from tiangolo/uvicorn-gunicorn-docker
6+
# MIT License: https://github.com/tiangolo/uvicorn-gunicorn-docker/blob/master/LICENSE
7+
#
8+
9+
if [ -f /app/app/main.py ]; then
10+
DEFAULT_MODULE_NAME=app.main
11+
elif [ -f /app/main.py ]; then
12+
DEFAULT_MODULE_NAME=main
13+
fi
14+
MODULE_NAME=${MODULE_NAME:-$DEFAULT_MODULE_NAME}
15+
16+
# If there's a prestart.sh script in the /app directory or other path specified, run it before starting
17+
PRE_START_PATH=${PRE_START_PATH:-/app/prestart.sh}
18+
echo "Checking for script in $PRE_START_PATH"
19+
if [ -f $PRE_START_PATH ]; then
20+
echo "Running script $PRE_START_PATH"
21+
. "$PRE_START_PATH"
22+
else
23+
echo "There is no script $PRE_START_PATH"
24+
fi
25+
26+
#
27+
# End of tiangolo/uvicorn-gunicorn-docker block
28+
#
29+
30+
if [[ $RELOAD == "true" ]]; then
31+
watchfiles "exec python -m $MODULE_NAME" /app
32+
else
33+
exec python -m "$MODULE_NAME"
34+
fi

dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ARG python_version=3.9
2+
ARG build_target=$python_version
3+
ARG publish_target=$python_version
4+
5+
FROM python:$build_target as Builder
6+
7+
# Add arguments to container scope
8+
ARG build_target
9+
ARG package
10+
ARG package_version
11+
12+
# Only add build tools for alpine image. The ubuntu based images have build tools already.
13+
# Only runs if `apk` is on the system.
14+
RUN if which apk ; then apk add python3-dev libffi-dev libevent-dev build-base bash cargo rust gcc musl-dev maturin; fi
15+
16+
# Install packaer and build all dependencies.
17+
RUN pip install $package==$package_version watchfiles
18+
19+
20+
# Build our actual container now.
21+
FROM python:$publish_target
22+
23+
# Add args to container scope.
24+
ARG publish_target
25+
ARG python_version
26+
ARG package
27+
ARG maintainer=""
28+
ARG TARGETPLATFORM=""
29+
LABEL python=$python_version
30+
LABEL package=$package
31+
LABEL maintainer=$maintainer
32+
LABEL org.opencontainers.image.description="python:$publish_target $package:$package_version $TARGETPLATFORM"
33+
34+
35+
# Copy all of the python files built in the Builder container into this smaller container.
36+
COPY --from=Builder /usr/local/lib/python$python_version /usr/local/lib/python$python_version
37+
38+
# Startup Script
39+
COPY ./assets/start.sh /start.sh
40+
RUN chmod +x /start.sh
41+
42+
# Example application so container "works" when run directly.
43+
COPY ./assets/main.py /app/main.py
44+
WORKDIR /app/
45+
46+
ENV PYTHONPATH=/app
47+
48+
CMD ["/start.sh"]

templates/description.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A multiarchitecture container image for running Python with [QuasiQueue](https://github.com/tedivm/quasiqueue).
2+
3+
Looking for the containers? [Head over to the Github Container Registry](https://github.com/multi-py/python-uvicorn/pkgs/container/python-quasiqueue)!

0 commit comments

Comments
 (0)