Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Alpine Linux #37

Merged
merged 3 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 58 additions & 46 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,58 @@ jobs:
needs: [python]
strategy:
matrix:
alpine-version: ["", "alpine"]
python-version: [3.8, 3.9]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: python3 -m pip install httpie
- name: Set up versions and Docker tags for Python and Alpine Linux
id: setup
run: |
ALPINE_VERSION=${{ matrix.alpine-version }}
ALPINE_TAG=${ALPINE_VERSION:+-$ALPINE_VERSION}
PYTHON_VERSION=${{ matrix.python-version }}
PYTHON_TAG="-python$PYTHON_VERSION"
echo "ALPINE_VERSION=$ALPINE_VERSION" >> $GITHUB_ENV
echo "ALPINE_TAG=$ALPINE_TAG" >> $GITHUB_ENV
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
echo "PYTHON_TAG=$PYTHON_TAG" >> $GITHUB_ENV
- name: Log in to Docker registry
run: |
echo ${{ secrets.PAT_GHCR }} | docker login ghcr.io \
-u ${{ github.actor }} --password-stdin
- name: Build Docker images
run: |
PY=${{ matrix.python-version }}
docker build . --rm --target base \
--build-arg PYTHON_VERSION="$PY" \
--cache-from python:"$PY" \
-t ghcr.io/br3ndonland/inboard:base
--build-arg ALPINE_VERSION="$ALPINE_VERSION" \
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
--cache-from python:"$PYTHON_VERSION$ALPINE_TAG" \
-t ghcr.io/br3ndonland/inboard:base"$ALPINE_TAG"
docker build . --rm --target starlette \
--build-arg PYTHON_VERSION="$PY" \
-t ghcr.io/br3ndonland/inboard:starlette
--build-arg ALPINE_VERSION="$ALPINE_VERSION" \
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
-t ghcr.io/br3ndonland/inboard:starlette"$ALPINE_TAG"
docker build . --rm --target fastapi \
--build-arg PYTHON_VERSION="$PY" \
-t ghcr.io/br3ndonland/inboard:fastapi
--build-arg ALPINE_VERSION="$ALPINE_VERSION" \
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
-t ghcr.io/br3ndonland/inboard:fastapi"$ALPINE_TAG"
- name: Run Docker containers for testing
run: |
docker run -d -p 80:80 \
-e "BASIC_AUTH_USERNAME=test_user" \
-e "BASIC_AUTH_PASSWORD=r4ndom_bUt_memorable" \
ghcr.io/br3ndonland/inboard:base
ghcr.io/br3ndonland/inboard:base"$ALPINE_TAG"
docker run -d -p 81:80 \
-e "BASIC_AUTH_USERNAME=test_user" \
-e "BASIC_AUTH_PASSWORD=r4ndom_bUt_memorable" \
ghcr.io/br3ndonland/inboard:starlette
ghcr.io/br3ndonland/inboard:starlette"$ALPINE_TAG"
docker run -d -p 82:80 \
-e "BASIC_AUTH_USERNAME=test_user" \
-e "BASIC_AUTH_PASSWORD=r4ndom_bUt_memorable" \
ghcr.io/br3ndonland/inboard:fastapi
ghcr.io/br3ndonland/inboard:fastapi"$ALPINE_TAG"
- name: Smoke test Docker containers
run: |
handle_error_code() {
Expand Down Expand Up @@ -145,55 +159,53 @@ jobs:
github.ref == 'refs/heads/main'
)
run: |
docker push ghcr.io/br3ndonland/inboard:base
docker push ghcr.io/br3ndonland/inboard:starlette
docker push ghcr.io/br3ndonland/inboard:fastapi
docker push ghcr.io/br3ndonland/inboard:base"$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:starlette"$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:fastapi"$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:fastapi \
ghcr.io/br3ndonland/inboard:latest
docker push ghcr.io/br3ndonland/inboard:latest
ghcr.io/br3ndonland/inboard:fastapi"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:latest"$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:latest"$ALPINE_TAG"
- name: Tag and push Docker images with Python version
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main'
run: |
PY_TAG=python${{ matrix.python-version }}
docker tag \
ghcr.io/br3ndonland/inboard:base \
ghcr.io/br3ndonland/inboard:base-"$PY_TAG"
ghcr.io/br3ndonland/inboard:base"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:base"$PYTHON_TAG$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:starlette \
ghcr.io/br3ndonland/inboard:starlette-"$PY_TAG"
ghcr.io/br3ndonland/inboard:starlette"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:starlette"$PYTHON_TAG$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:fastapi \
ghcr.io/br3ndonland/inboard:fastapi-"$PY_TAG"
docker push ghcr.io/br3ndonland/inboard:base-"$PY_TAG"
docker push ghcr.io/br3ndonland/inboard:starlette-"$PY_TAG"
docker push ghcr.io/br3ndonland/inboard:fastapi-"$PY_TAG"
ghcr.io/br3ndonland/inboard:fastapi"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:fastapi"$PYTHON_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:base"$PYTHON_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:starlette"$PYTHON_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:fastapi"$PYTHON_TAG$ALPINE_TAG"
- name: Tag and push Docker images with Git tag
if: startsWith(github.ref, 'refs/tags/')
run: |
GIT_TAG=$(echo ${{ github.ref }} | cut -d / -f 3)
PY_TAG=python${{ matrix.python-version }}
docker tag \
ghcr.io/br3ndonland/inboard:base \
ghcr.io/br3ndonland/inboard:base-"$GIT_TAG"
ghcr.io/br3ndonland/inboard:base"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:base-"$GIT_TAG$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:starlette \
ghcr.io/br3ndonland/inboard:starlette-"$GIT_TAG"
ghcr.io/br3ndonland/inboard:starlette"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:starlette-"$GIT_TAG$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:fastapi \
ghcr.io/br3ndonland/inboard:fastapi-"$GIT_TAG"
ghcr.io/br3ndonland/inboard:fastapi"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:fastapi-"$GIT_TAG$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:base \
ghcr.io/br3ndonland/inboard:base-"$GIT_TAG"-"$PY_TAG"
ghcr.io/br3ndonland/inboard:base"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:base"-$GIT_TAG$PYTHON_TAG$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:starlette \
ghcr.io/br3ndonland/inboard:starlette-"$GIT_TAG"-"$PY_TAG"
ghcr.io/br3ndonland/inboard:starlette"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:starlette"-$GIT_TAG$PYTHON_TAG$ALPINE_TAG"
docker tag \
ghcr.io/br3ndonland/inboard:fastapi \
ghcr.io/br3ndonland/inboard:fastapi-"$GIT_TAG"-"$PY_TAG"
docker push ghcr.io/br3ndonland/inboard:base-"$GIT_TAG"
docker push ghcr.io/br3ndonland/inboard:starlette-"$GIT_TAG"
docker push ghcr.io/br3ndonland/inboard:fastapi-"$GIT_TAG"
docker push ghcr.io/br3ndonland/inboard:base-"$GIT_TAG"-"$PY_TAG"
docker push ghcr.io/br3ndonland/inboard:starlette-"$GIT_TAG"-"$PY_TAG"
docker push ghcr.io/br3ndonland/inboard:fastapi-"$GIT_TAG"-"$PY_TAG"
ghcr.io/br3ndonland/inboard:fastapi"$ALPINE_TAG" \
ghcr.io/br3ndonland/inboard:fastapi"-$GIT_TAG$PYTHON_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:base-"$GIT_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:starlette-"$GIT_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:fastapi-"$GIT_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:base-"$GIT_TAG$PYTHON_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:starlette-"$GIT_TAG$PYTHON_TAG$ALPINE_TAG"
docker push ghcr.io/br3ndonland/inboard:fastapi-"$GIT_TAG$PYTHON_TAG$ALPINE_TAG"
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG PYTHON_VERSION=3.9
FROM python:${PYTHON_VERSION} AS base
ARG PYTHON_VERSION=3.9 ALPINE_VERSION=
FROM python:${PYTHON_VERSION}${ALPINE_VERSION:+-$ALPINE_VERSION} AS base
LABEL org.opencontainers.image.authors="Brendon Smith <[email protected]>"
LABEL org.opencontainers.image.description="Docker images and utilities to power your Python APIs and help you ship faster."
LABEL org.opencontainers.image.licenses="MIT"
Expand All @@ -9,7 +9,8 @@ LABEL org.opencontainers.image.url="https://github.com/br3ndonland/inboard/pkgs/
ENV APP_MODULE=inboard.app.main_base:app PATH=/opt/poetry/bin:$PATH POETRY_HOME=/opt/poetry POETRY_VIRTUALENVS_CREATE=false PYTHONPATH=/app
COPY poetry.lock pyproject.toml /app/
WORKDIR /app/
RUN curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/HEAD/get-poetry.py && \
RUN wget -qO get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/HEAD/get-poetry.py && \
sh -c '. /etc/os-release; if [ "$ID" = "alpine" ]; then apk add --no-cache --virtual .build-deps gcc libc-dev make; fi' && \
python get-poetry.py -y && poetry install --no-dev --no-interaction --no-root
COPY inboard /app/inboard
ENTRYPOINT ["python"]
Expand Down
65 changes: 37 additions & 28 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,43 @@

## Pull images

Docker images are stored in [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry) (GHCR), which is a Docker registry like Docker Hub. Public Docker images can be pulled anonymously from `ghcr.io`.

Simply running `docker pull ghcr.io/br3ndonland/inboard` will pull the latest FastAPI image (Docker uses the `latest` tag by default). If specific versions of inboard or Python are desired, append the version numbers to the specified Docker tags as shown below _(new in inboard version 0.6.0)_.

```sh
# Pull latest FastAPI image
docker pull ghcr.io/br3ndonland/inboard

# Pull latest version of each image
docker pull ghcr.io/br3ndonland/inboard:base
docker pull ghcr.io/br3ndonland/inboard:fastapi
docker pull ghcr.io/br3ndonland/inboard:starlette

# Pull image from specific release
docker pull ghcr.io/br3ndonland/inboard:base-0.6.0
docker pull ghcr.io/br3ndonland/inboard:fastapi-0.6.0
docker pull ghcr.io/br3ndonland/inboard:starlette-0.6.0

# Pull image with specific Python version
docker pull ghcr.io/br3ndonland/inboard:base-python3.8
docker pull ghcr.io/br3ndonland/inboard:fastapi-python3.8
docker pull ghcr.io/br3ndonland/inboard:starlette-python3.8

# Pull image from specific release and with specific Python version
docker pull ghcr.io/br3ndonland/inboard:base-0.6.0-python3.8
docker pull ghcr.io/br3ndonland/inboard:fastapi-0.6.0-python3.8
docker pull ghcr.io/br3ndonland/inboard:starlette-0.6.0-python3.8
```
Docker images are stored in [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry) (GHCR), which is a Docker registry like Docker Hub. Public Docker images can be pulled anonymously from `ghcr.io`. The inboard images are based on the [official Python Docker images](https://hub.docker.com/_/python).

Simply running `docker pull ghcr.io/br3ndonland/inboard` will pull the latest FastAPI image (Docker uses the `latest` tag by default). If specific versions of inboard or Python are desired, append the version numbers to the specified Docker tags as shown below _(new in inboard version 0.6.0)_. All the available images are also provided with [Alpine Linux](https://alpinelinux.org/) builds, which are available by appending `-alpine` _(new in inboard version 0.11.0)_.

!!! info "Available Docker tags"

```sh
# Pull latest FastAPI image (Docker automatically appends the `latest` tag)
docker pull ghcr.io/br3ndonland/inboard

# Pull latest version of each image
docker pull ghcr.io/br3ndonland/inboard:base
docker pull ghcr.io/br3ndonland/inboard:fastapi
docker pull ghcr.io/br3ndonland/inboard:starlette

# Pull image from specific release (new in inboard 0.6.0)
docker pull ghcr.io/br3ndonland/inboard:base-0.6.0
docker pull ghcr.io/br3ndonland/inboard:fastapi-0.6.0
docker pull ghcr.io/br3ndonland/inboard:starlette-0.6.0

# Pull image with specific Python version
docker pull ghcr.io/br3ndonland/inboard:base-python3.8
docker pull ghcr.io/br3ndonland/inboard:fastapi-python3.8
docker pull ghcr.io/br3ndonland/inboard:starlette-python3.8

# Pull image from specific release and with specific Python version
docker pull ghcr.io/br3ndonland/inboard:base-0.6.0-python3.8
docker pull ghcr.io/br3ndonland/inboard:fastapi-0.6.0-python3.8
docker pull ghcr.io/br3ndonland/inboard:starlette-0.6.0-python3.8

# Append `-alpine` to any of the above for Alpine Linux (new in inboard 0.11.0)
docker pull ghcr.io/br3ndonland/inboard:latest-alpine
docker pull ghcr.io/br3ndonland/inboard:fastapi-alpine
docker pull ghcr.io/br3ndonland/inboard:fastapi-0.11.0-alpine
docker pull ghcr.io/br3ndonland/inboard:fastapi-python3.8-alpine
docker pull ghcr.io/br3ndonland/inboard:fastapi-0.11.0-python3.8-alpine
```

## Use images in a _Dockerfile_

Expand Down