Skip to content

Commit

Permalink
Pin and test Poetry version in Docker
Browse files Browse the repository at this point in the history
Poetry has introduced a number of problematic changes recently.
To help buffer against these problematic changes, this commit will
implement installation of specific versions of Poetry, rather than the
latest version.

- Add `POETRY_VERSION` build argument and default to Dockerfile
- Use `POETRY_VERSION` build argument when building Docker images
- Run a shell test to assert that `poetry -V` matches `POETRY_VERSION`
  • Loading branch information
br3ndonland committed Sep 19, 2021
1 parent a38617d commit 036b57c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,51 @@ jobs:
run: |
docker build . --rm --target base \
--build-arg LINUX_VERSION="$LINUX_VERSION" \
--build-arg POETRY_VERSION="$POETRY_VERSION" \
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
--cache-from python:"$PYTHON_VERSION$LINUX_TAG" \
-t ghcr.io/br3ndonland/inboard:base"$LINUX_TAG"
docker build . --rm --target starlette \
--build-arg LINUX_VERSION="$LINUX_VERSION" \
--build-arg POETRY_VERSION="$POETRY_VERSION" \
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
-t ghcr.io/br3ndonland/inboard:starlette"$LINUX_TAG"
docker build . --rm --target fastapi \
--build-arg LINUX_VERSION="$LINUX_VERSION" \
--build-arg POETRY_VERSION="$POETRY_VERSION" \
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
-t ghcr.io/br3ndonland/inboard:fastapi"$LINUX_TAG"
- name: Run Docker containers for testing
run: |
docker run -d -p 80:80 \
docker run -d -p 80:80 --name inboard-base \
-e "BASIC_AUTH_USERNAME=test_user" \
-e "BASIC_AUTH_PASSWORD=r4ndom_bUt_memorable" \
ghcr.io/br3ndonland/inboard:base"$LINUX_TAG"
docker run -d -p 81:80 \
docker run -d -p 81:80 --name inboard-starlette \
-e "BASIC_AUTH_USERNAME=test_user" \
-e "BASIC_AUTH_PASSWORD=r4ndom_bUt_memorable" \
ghcr.io/br3ndonland/inboard:starlette"$LINUX_TAG"
docker run -d -p 82:80 \
docker run -d -p 82:80 --name inboard-fastapi \
-e "BASIC_AUTH_USERNAME=test_user" \
-e "BASIC_AUTH_PASSWORD=r4ndom_bUt_memorable" \
ghcr.io/br3ndonland/inboard:fastapi"$LINUX_TAG"
- name: Test Poetry version in Docker containers
run: |
test_poetry_version_in_docker() {
echo "The POETRY_VERSION environment variable is set to $POETRY_VERSION."
local poetry_version_in_docker
for container_name in "$@"; do
poetry_version_in_docker=$(docker exec "$container_name" poetry -V)
if [ -n "$poetry_version_in_docker" ]; then
echo "Docker container $container_name has $poetry_version_in_docker."
fi
case $poetry_version_in_docker in
*$POETRY_VERSION*) echo "Poetry versions match for $container_name." ;;
*) echo "Poetry version test failed for $container_name." && return 1 ;;
esac
done
}
test_poetry_version_in_docker inboard-base inboard-starlette inboard-fastapi
- name: Smoke test Docker containers
run: |
handle_error_code() {
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.source="https://github.com/br3ndonland/inboard"
LABEL org.opencontainers.image.title="inboard"
LABEL org.opencontainers.image.url="https://github.com/br3ndonland/inboard/pkgs/container/inboard"
ARG LINUX_VERSION
ENV APP_MODULE=inboard.app.main_base:app LINUX_VERSION=$LINUX_VERSION PATH=/opt/poetry/bin:$PATH POETRY_HOME=/opt/poetry POETRY_VIRTUALENVS_CREATE=false PYTHONPATH=/app
ARG LINUX_VERSION POETRY_VERSION=1.1.7
ENV APP_MODULE=inboard.app.main_base:app LINUX_VERSION=$LINUX_VERSION PATH=/opt/poetry/bin:$PATH POETRY_HOME=/opt/poetry POETRY_VERSION=$POETRY_VERSION POETRY_VIRTUALENVS_CREATE=false PYTHONPATH=/app
COPY poetry.lock pyproject.toml /app/
WORKDIR /app/
RUN sh -c 'if [ "$LINUX_VERSION" = "slim" ]; then apt-get update -qy && apt-get install -qy --no-install-recommends gcc libc-dev make wget; fi' && \
wget -qO get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/HEAD/get-poetry.py && \
wget -qO get-poetry.py "https://raw.githubusercontent.com/python-poetry/poetry/$POETRY_VERSION/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 && \
sh -c 'if [ "$LINUX_VERSION" = "slim" ]; then apt-get purge --auto-remove -qy gcc libc-dev make wget; fi' && \
Expand Down

0 comments on commit 036b57c

Please sign in to comment.