Skip to content

Commit

Permalink
feat: py3.11 support (#15)
Browse files Browse the repository at this point in the history
* feat: py3.11 support

* fix: include libcom_err
  • Loading branch information
andrewthetechie authored Feb 18, 2023
1 parent dd681f8 commit 7fb869c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 72 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
name: Generate Docs
on:
push:
branches:
- main
pull_request:
jobs:
docs:
name: Generate Docs
runs-on: ubuntu-latest
steps:
- name: Cancel Workflow Action
uses: styfle/[email protected]
with:
all_but_latest: true
access_token: ${{ secrets.THIS_PAT }}
- name: Set up Node
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Copy in Dockerfile
run: cp Docker/Dockerfile Dockerfile
- name: Test action
id: test-action
# test with the local checkout of the action
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name: Lint
on:
push:
pull_request:
branches:
- main
jobs:
lint-and-test:
name: Lint and Test
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.11
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
on:
push:
branches:
- main
name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
token: ${{ secrets.THIS_PAT }}
release-type: simple
16 changes: 0 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,3 @@ jobs:
body: ${{ inputs.releaseNotes }}
draft: false
prerelease: ${{ inputs.prerelease }}
set-dockerfile-back:
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.THIS_PAT }}
fetch-depth: 0
- run: cp Docker/Dockerfile ./Dockerfile
- name: Commit Dockerfile changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "ci: update actions dockerfile for dev"
file_pattern: Dockerfile
skip_fetch: false
skip_checkout: false
17 changes: 17 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Unit Test
on:
push:
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/[email protected]
with:
python-version: "3.11"
- run: pip install -r Docker/builder/rootfs/requirements.txt
- run: pip install -r requirements-dev.txt
- name: Run pytest
run: pytest
58 changes: 15 additions & 43 deletions Docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Distroless runs python 3.9.2
FROM python:3.11-slim-bullseye as builder
FROM python:3.11-slim-bullseye as python-base
ADD Docker/builder/rootfs /
ADD main.py /app/main.py
ADD action.yml /app/action.yml
Expand All @@ -14,30 +14,6 @@ RUN cd /tmp && \
mkdir /dpkg && \
for deb in *.deb; do dpkg --extract $deb /dpkg || exit 10; done

FROM python:3.11-slim-bullseye as python-base

# Update the base image
RUN apt-get update && apt-get upgrade -y

# Setup a non-root user
ARG NONROOT_USER="op"
ARG NONROOT_GROUP="op"

RUN groupadd ${NONROOT_GROUP}
RUN useradd -m ${NONROOT_USER} -g ${NONROOT_GROUP}

USER ${NONROOT_USER}
ENV PATH="/home/${NONROOT_USER}/.local/bin:${PATH}"
WORKDIR /home/${NONROOT_USER}
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1

# upgrade pip and virtualenv
RUN --mount=type=cache,uid=1000,gid=1000,target=/home/op/.cache/pip pip install --upgrade pip && \
pip install --no-warn-script-location --upgrade virtualenv

# use distroless/cc as the base for our final image
# lots of python depends on glibc
FROM gcr.io/distroless/cc-debian11
Expand All @@ -53,29 +29,25 @@ COPY --from=python-base /etc/ld.so.cache /etc/ld.so.cache
# required by lots of packages - e.g. six, numpy, wsgi
# *-linux-gnu makes this builder work with either linux/arm64 or linux/amd64
COPY --from=python-base /lib/*-linux-gnu/libz.so.1 /lib/libs/
COPY --from=python-base /lib/*-linux-gnu/libcom_err.so.2 /lib/libs/
COPY --from=python-base /usr/lib/*-linux-gnu/libffi* /lib/libs/
COPY --from=python-base /lib/*-linux-gnu/libexpat* /lib/libs/

# Add some system utils
COPY --from=python-base /bin/echo /bin/echo
COPY --from=python-base /bin/rm /bin/rm
COPY --from=python-base /bin/sh /bin/sh

# Copy over the app
COPY --from=builder /app /app
COPY --from=builder /dpkg /
COPY --from=python-base /app /app
COPY --from=python-base /dpkg /
WORKDIR /app
ENV PYTHONPATH /app

# non root user stuff
RUN echo "op:x:1000:op" >> /etc/group
RUN echo "op:x:1001:" >> /etc/group
RUN echo "op:x:1000:1001::/home/op:" >> /etc/passwd

# Remove shell utils and pip
RUN rm /bin/sh /bin/echo /bin/rm

# default to running as non-root, uid=1000
USER op
# Add /lib/libs to our path
ENV LD_LIBRARY_PATH="/lib/libs:${LD_LIBRARY_PATH}" \
# Add the app path to our path
PATH="/app/bin:${PATH}" \
# Add the app path to your python path
PYTHONPATH="/app:${PYTHONPATH}" \
# standardise on locale, don't generate .pyc, enable tracebacks on seg faults
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONFAULTHANDLER=1

CMD ["python", "/app/main.py"]

0 comments on commit 7fb869c

Please sign in to comment.