Skip to content

Commit ed0bbc4

Browse files
author
Kristian Berg
committed
Initial version
Signed-off-by: Kristian Berg <[email protected]>
0 parents  commit ed0bbc4

8 files changed

+233
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# First rule of vim, dont talk about .swp files
2+
.*.swp

Dockerfile-3.6

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM evryfs/base-python:3.6
2+
ARG UVICORN_VERSION=0.10.8
3+
ARG BUILD_DATE
4+
ARG BUILD_URL
5+
ARG GIT_URL
6+
ARG GIT_COMMIT
7+
ARG PYTHON_VERSION
8+
LABEL maintainer="Kristian Berg <[email protected]>" \
9+
org.opencontainers.image.title="base-python-asgi" \
10+
org.opencontainers.image.created=$BUILD_DATE \
11+
org.opencontainers.image.authors="Kristian Berg <[email protected]>" \
12+
org.opencontainers.image.url=$BUILD_URL \
13+
org.opencontainers.image.documentation="https://github.com/evryfs/base-python-asgi/" \
14+
org.opencontainers.image.source=$GIT_URL \
15+
org.opencontainers.image.version=$PYTHON_VERSION-$UVICORN_VERSION \
16+
org.opencontainers.image.revision=$GIT_COMMIT \
17+
org.opencontainers.image.vendor="EVRY Financial Services" \
18+
org.opencontainers.image.licenses="proprietary-license" \
19+
org.opencontainers.image.description="Base image for python 3.6 with uvicorn ASGI server"
20+
21+
ENV UVICORN_PORT 8000
22+
ENV UVICORN_HOST 0.0.0.0
23+
USER root
24+
RUN apt-get update && \
25+
apt-get install -y gcc
26+
RUN pip install uvicorn==$UVICORN_VERSION
27+
RUN apt-get purge -y gcc
28+
COPY start_uvicorn /bin/
29+
COPY asgi.py /usr/local/lib/python3.6/site-packages/
30+
RUN chmod 755 /bin/start_uvicorn
31+
USER 1001:100
32+
WORKDIR /app
33+
EXPOSE $UVICORN_PORT
34+
ENTRYPOINT ["/bin/start_uvicorn"]
35+
CMD ["asgi:app"]

Dockerfile-3.7

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM evryfs/base-python:3.7
2+
ARG UVICORN_VERSION=0.10.8
3+
ARG BUILD_DATE
4+
ARG BUILD_URL
5+
ARG GIT_URL
6+
ARG GIT_COMMIT
7+
ARG PYTHON_VERSION
8+
LABEL maintainer="Kristian Berg <[email protected]>" \
9+
org.opencontainers.image.title="base-python-asgi" \
10+
org.opencontainers.image.created=$BUILD_DATE \
11+
org.opencontainers.image.authors="Kristian Berg <[email protected]>" \
12+
org.opencontainers.image.url=$BUILD_URL \
13+
org.opencontainers.image.documentation="https://github.com/evryfs/base-python-asgi/" \
14+
org.opencontainers.image.source=$GIT_URL \
15+
org.opencontainers.image.version=$PYTHON_VERSION-$UVICORN_VERSION \
16+
org.opencontainers.image.revision=$GIT_COMMIT \
17+
org.opencontainers.image.vendor="EVRY Financial Services" \
18+
org.opencontainers.image.licenses="proprietary-license" \
19+
org.opencontainers.image.description="Base image for python 3.7 with uvicorn ASGI server"
20+
21+
ENV UVICORN_PORT 8000
22+
ENV UVICORN_HOST 0.0.0.0
23+
USER root
24+
RUN apt-get update && \
25+
apt-get install -y gcc
26+
RUN pip install uvicorn==$UVICORN_VERSION
27+
RUN apt-get purge -y gcc
28+
COPY start_uvicorn /bin/
29+
COPY asgi.py /usr/local/lib/python3.7/site-packages/
30+
RUN chmod 755 /bin/start_uvicorn
31+
USER 1001:100
32+
WORKDIR /app
33+
EXPOSE $UVICORN_PORT
34+
ENTRYPOINT ["/bin/start_uvicorn"]
35+
CMD ["asgi:app"]

Dockerfile-3.8

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM evryfs/base-python:3.8
2+
ARG UVICORN_VERSION=0.10.8
3+
ARG BUILD_DATE
4+
ARG BUILD_URL
5+
ARG GIT_URL
6+
ARG GIT_COMMIT
7+
ARG PYTHON_VERSION
8+
LABEL maintainer="Kristian Berg <[email protected]>" \
9+
org.opencontainers.image.title="base-python-asgi" \
10+
org.opencontainers.image.created=$BUILD_DATE \
11+
org.opencontainers.image.authors="Kristian Berg <[email protected]>" \
12+
org.opencontainers.image.url=$BUILD_URL \
13+
org.opencontainers.image.documentation="https://github.com/evryfs/base-python-asgi/" \
14+
org.opencontainers.image.source=$GIT_URL \
15+
org.opencontainers.image.version=$PYTHON_VERSION-$UVICORN_VERSION \
16+
org.opencontainers.image.revision=$GIT_COMMIT \
17+
org.opencontainers.image.vendor="EVRY Financial Services" \
18+
org.opencontainers.image.licenses="proprietary-license" \
19+
org.opencontainers.image.description="Base image for python 3.8 with uvicorn ASGI server"
20+
21+
ENV UVICORN_PORT 8000
22+
ENV UVICORN_HOST 0.0.0.0
23+
USER root
24+
RUN apt-get update && \
25+
apt-get install -y gcc
26+
RUN pip install uvicorn==$UVICORN_VERSION
27+
RUN apt-get purge -y gcc
28+
COPY start_uvicorn /bin/
29+
COPY asgi.py /usr/local/lib/python3.8/site-packages/
30+
RUN chmod 755 /bin/start_uvicorn
31+
USER 1001:100
32+
WORKDIR /app
33+
EXPOSE $UVICORN_PORT
34+
ENTRYPOINT ["/bin/start_uvicorn"]
35+
CMD ["asgi:app"]

Makefile

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
UVICORN_VERSION := 0.10.8
2+
BUILD_URL ?= $(shell pwd)
3+
BUILD_DATE ?= $(shell date --rfc-3339=ns)
4+
GIT_URL := $(shell git config --get remote.origin.url)
5+
GIT_COMMIT := $(shell git rev-parse HEAD)
6+
PYTHON_38 := $(shell head -n1 Dockerfile-3.8|cut -d":" -f2|cut -d"-" -f1)
7+
PYTHON_37 := $(shell head -n1 Dockerfile-3.7|cut -d":" -f2|cut -d"-" -f1)
8+
PYTHON_36 := $(shell head -n1 Dockerfile-3.6|cut -d":" -f2|cut -d"-" -f1)
9+
10+
3.8:
11+
@echo "Building base-python-asgi with uvicorn $(UVICORN_VERSION) and python $(PYTHON_38)"
12+
docker build . \
13+
-t evryfs/base-python-asgi:$(PYTHON_38)-$(UVICORN_VERSION) \
14+
-t evryfs/base-python-asgi:3.8-stable \
15+
-t quay.io/evryfs/base-python-asgi:$(PYTHON_38)-$(UVICORN_VERSION) \
16+
-t quay.io/evryfs/base-python-asgi:3.8-stable \
17+
--build-arg UVICORN_VERSION="$(UVICORN_VERSION)" \
18+
--build-arg BUILD_DATE="$(BUILD_DATE)" \
19+
--build-arg BUILD_URL="$(BUILD_URL)" \
20+
--build-arg GIT_URL="$(GIT_URL)" \
21+
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
22+
-f Dockerfile-3.8
23+
24+
3.7:
25+
@echo "Building base-python-asgi with uvicorn $(UVICORN_VERSION) and python $(PYTHON_38)"
26+
docker build . \
27+
-t evryfs/base-python-asgi:$(PYTHON_37)-$(UVICORN_VERSION) \
28+
-t evryfs/base-python-asgi:3.7-stable \
29+
-t quay.io/evryfs/base-python-asgi:$(PYTHON_37)-$(UVICORN_VERSION) \
30+
-t quay.io/evryfs/base-python-asgi:3.7-stable \
31+
--build-arg UVICORN_VERSION="$(UVICORN_VERSION)" \
32+
--build-arg BUILD_DATE="$(BUILD_DATE)" \
33+
--build-arg BUILD_URL="$(BUILD_URL)" \
34+
--build-arg GIT_URL="$(GIT_URL)" \
35+
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
36+
-f Dockerfile-3.7
37+
38+
3.6:
39+
@echo "Building base-python-asgi with uvicorn $(UVICORN_VERSION) and python $(PYTHON_38)"
40+
docker build . \
41+
-t evryfs/base-python-asgi:$(PYTHON_36)-$(UVICORN_VERSION) \
42+
-t evryfs/base-python-asgi:3.6-stable \
43+
-t quay.io/evryfs/base-python-asgi:$(PYTHON_36)-$(UVICORN_VERSION) \
44+
-t quay.io/evryfs/base-python-asgi:3.6-stable \
45+
--build-arg UVICORN_VERSION="$(UVICORN_VERSION)" \
46+
--build-arg BUILD_DATE="$(BUILD_DATE)" \
47+
--build-arg BUILD_URL="$(BUILD_URL)" \
48+
--build-arg GIT_URL="$(GIT_URL)" \
49+
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
50+
-f Dockerfile-3.7
51+
52+
push:
53+
docker push quay.io/evryfs/base-python-asgi:3.8-stable
54+
docker push quay.io/evryfs/base-python-asgi:$(PYTHON_38)-$(UVICORN_VERSION)
55+
docker push quay.io/evryfs/base-python-asgi:3.7-stable
56+
docker push quay.io/evryfs/base-python-asgi:$(PYTHON_37)-$(UVICORN_VERSION)
57+
docker push quay.io/evryfs/base-python-asgi:3.6-stable
58+
docker push quay.io/evryfs/base-python-asgi:$(PYTHON_36)-$(UVICORN_VERSION)
59+
60+
all: 3.8 3.7 3.6 push

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# EVRY FS python ASGI base image
2+
3+
This image forms the basis for running python ASGI applications. It is based on
4+
the EVRY python base image and uses uvicorn.
5+
6+
## Usage
7+
8+
The image bundles a wrapper script for uvicorn at `/bin/start_uvicorn`. It uses
9+
environment flags to control how the ASGI application is started.
10+
11+
### Available flags
12+
13+
Flag | Default | Comment
14+
---------------- | ----------------- | ---------------------------------------------------
15+
UVICORN_PORT | 8000 | Application port.
16+
UVICORN_HOST | 0.0.0.0 | Application bind address.
17+
18+
### Creating a Dockerfile
19+
20+
To utilize this image to create a container for your application, create a new
21+
Dockerfile based on this. Then add your python sauce to the container and set
22+
the name of the ASGI module with `CMD ["module:callable"]`.
23+
24+
```dockerfile
25+
FROM evryfs/base-python-asgi:3.7-stable
26+
ARG BUILD_DATE
27+
ARG BUILD_URL
28+
ARG GIT_URL
29+
ARG GIT_COMMIT
30+
LABEL maintainer="Your Name <[email protected]>"
31+
com.finods.ccm.system="<system short name>"
32+
com.finods.ccm.group="<finods group>"
33+
org.opencontainers.image.title="<application name>"
34+
org.opencontainers.image.created=$BUILD_DATE
35+
org.opencontainers.image.authors="<name of system responsible>"
36+
org.opencontainers.image.url=$BUILD_URL
37+
org.opencontainers.image.documentation="<link to SAD>"
38+
org.opencontainers.image.source=$GIT_URL
39+
org.opencontainers.image.version="<version number>"
40+
org.opencontainers.image.revision=$GIT_COMMIT
41+
org.opencontainers.image.vendor="EVRY Financial Services"
42+
org.opencontainers.image.licenses="proprietary-license"
43+
org.opencontainers.image.description="<system description>"
44+
45+
COPY . .
46+
CMD ["asgi_module:app"]
47+
```
48+
49+
The default workdir for this image is /app, so any sauce will be copied there.
50+
Remember to reset WORKDIR to /app, if you do additional steps in your
51+
derivative image. The wrapper scripts depends on the module being either in
52+
python's site-packages or present in the current directory.

asgi.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def app(scope):
2+
async def asgi(receive, send):
3+
await send(
4+
{
5+
"type": "http.response.start",
6+
"status": 200,
7+
"headers": [[b"content-type", b"text/plain"]],
8+
}
9+
)
10+
await send({"type": "http.response.body", "body": b"Hello, world!"})
11+
12+
return asgi

start_uvicorn

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
uvicorn --port $UVICORN_PORT --host $UVICORN_HOST $*

0 commit comments

Comments
 (0)