Skip to content

Commit 8facc54

Browse files
authored
[infra] switch to poetry (#8)
1 parent 731dda4 commit 8facc54

File tree

15 files changed

+2245
-111
lines changed

15 files changed

+2245
-111
lines changed

.devcontainer/Dockerfile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
################################################################################
2+
# Base
3+
# - a single-version python slim-bullseye image
4+
# Installs
5+
# - poetry in /opt/poetry
6+
# - adds a user called 'zen'
7+
# Size
8+
# - 300MB
9+
################################################################################
10+
11+
ARG PYTHON_VERSION=3.8.15
12+
ARG DEBIAN_VERSION=bullseye
13+
14+
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION}
15+
16+
ARG NAME=poetry-zen
17+
ARG POETRY_VERSION=1.3.2
18+
ENV POETRY_HOME=/opt/poetry
19+
ENV PATH="${POETRY_HOME}/bin:${PATH}"
20+
21+
################################################################################
22+
# Poetry
23+
################################################################################
24+
25+
RUN apt-get update && apt-get install -y --no-install-recommends \
26+
# For poetry
27+
curl \
28+
# For pytrees
29+
graphviz \
30+
make \
31+
# For convenience
32+
bash \
33+
bash-completion \
34+
ca-certificates \
35+
git \
36+
less \
37+
ssh \
38+
vim \
39+
wget \
40+
&& \
41+
curl -sSL https://install.python-poetry.org | POETRY_VERSION=${POETRY_VERSION} python3 - && \
42+
poetry config virtualenvs.create false && \
43+
poetry completions bash >> ~/.bash_completion
44+
45+
################################################################################
46+
# Login Shells for Debugging & Development
47+
################################################################################
48+
49+
# In a login shell (below), the PATH env doesn't survive, configure it at ground zero
50+
RUN echo "export PATH=${POETRY_HOME}/bin:${PATH}" >> /etc/profile
51+
ENV TERM xterm-256color
52+
ENTRYPOINT ["/bin/bash", "--login", "-i"]
53+
54+
################################################################################
55+
# Development with a user, e.g. for vscode devcontainers
56+
################################################################################
57+
58+
ARG USERNAME=zen
59+
ARG USER_UID=1000
60+
ARG USER_GID=${USER_UID}
61+
62+
RUN groupadd --gid $USER_GID $USERNAME && \
63+
useradd --uid $USER_UID --gid $USER_GID -s "/bin/bash" -m $USERNAME && \
64+
apt-get install -y sudo && \
65+
echo "${USERNAME} ALL=NOPASSWD: ALL" > /etc/sudoers.d/${USERNAME} && \
66+
chmod 0440 /etc/sudoers.d/${USERNAME}
67+
RUN echo "export PS1='\[\033[01;36m\](docker)\[\033[00m\] \[\033[01;32m\]\u@${NAME}\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" >> /home/${USERNAME}/.bashrc && \
68+
echo "alias ll='ls --color=auto -alFNh'" >> /home/${USERNAME}/.bashrc && \
69+
echo "alias ls='ls --color=auto -Nh'" >> /home/${USERNAME}/.bashrc && \
70+
poetry completions bash >> /home/${USERNAME}/.bash_completion
71+
72+
# touch /home/${USERNAME}/.bash_completion && chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.bash_completion
73+
74+
################################################################################
75+
# Debugging with root
76+
################################################################################
77+
78+
RUN echo "export PS1='\[\033[01;36m\](docker)\[\033[00m\] \[\033[01;32m\]\u@${NAME}\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" >> ${HOME}/.bashrc && \
79+
echo "alias ll='ls --color=auto -alFNh'" >> ${HOME}/.bashrc && \
80+
echo "alias ls='ls --color=auto -Nh'" >> ${HOME}/.bashrc

.devcontainer/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Development Environment
2+
3+
These VSCode devcontainers setup multiple environments for testing against
4+
different python versins.
5+
6+
## Setup
7+
8+
```
9+
$ git clone [email protected]:splintered-reality/py_trees.git
10+
$ code ./py_trees
11+
```
12+
13+
## VSCode DevContainer
14+
15+
At this point you can either "Re-open project in container" to develop against
16+
the default python version.
17+
18+
Alternatively "Open Folder in Container" and point it at one of the
19+
`py<MAJOR><MINOR>` subfolders in this directory to develop against a different
20+
python version.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "headless-py310",
3+
4+
"build": {
5+
"dockerfile": "../Dockerfile",
6+
"args": {
7+
"NAME": "py_trees-310",
8+
"POETRY_VERSION": "1.8.4",
9+
"PYTHON_VERSION": "3.10.15",
10+
"DEBIAN_VERSION": "bookworm"
11+
}
12+
},
13+
"containerEnv": {
14+
"POETRY_HTTP_BASIC_PYPI_USERNAME": "${localEnv:POETRY_HTTP_BASIC_PYPI_USERNAME}",
15+
"POETRY_HTTP_BASIC_PYPI_PASSWORD": "${localEnv:POETRY_HTTP_BASIC_PYPI_PASSWORD}"
16+
},
17+
"remoteUser": "zen",
18+
"customizations": {
19+
"vscode": {
20+
"extensions": [
21+
"bierner.github-markdown-preview",
22+
"bungcip.better-toml",
23+
"streetsidesoftware.code-spell-checker",
24+
"lextudio.restructuredtext",
25+
"ms-python.python",
26+
"omnilib.ufmt"
27+
]
28+
}
29+
},
30+
"postCreateCommand": "poetry install",
31+
// "workspaceMount": "source=${localWorkspaceFolder}/../..,target=/workspaces,type=bind",
32+
// "workspaceFolder": "/workspaces"
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "headless-py38",
3+
4+
"build": {
5+
"dockerfile": "../Dockerfile",
6+
"args": {
7+
"NAME": "streamlit_parameters",
8+
"POETRY_VERSION": "1.8.4",
9+
"PYTHON_VERSION": "3.8.16",
10+
"DEBIAN_VERSION": "bookworm"
11+
},
12+
"context": ".."
13+
},
14+
"containerEnv": {
15+
"POETRY_HTTP_BASIC_PYPI_USERNAME": "${localEnv:POETRY_HTTP_BASIC_PYPI_USERNAME}",
16+
"POETRY_HTTP_BASIC_PYPI_PASSWORD": "${localEnv:POETRY_HTTP_BASIC_PYPI_PASSWORD}"
17+
},
18+
"remoteUser": "zen",
19+
"customizations": {
20+
"vscode": {
21+
"extensions": [
22+
"bierner.github-markdown-preview",
23+
"bierner.markdown-preview-github-styles",
24+
"bungcip.better-toml",
25+
"eamodio.gitlens",
26+
"ms-python.python",
27+
"omnilib.ufmt",
28+
"redhat.vscode-yaml",
29+
"streetsidesoftware.code-spell-checker",
30+
"tht13.rst-vscode"
31+
]
32+
}
33+
},
34+
"postCreateCommand": "poetry install",
35+
// Breaks codespaces
36+
// "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind",
37+
// "workspaceFolder": "/workspaces"
38+
}

.github/workflows/continuous_integration.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/pre-merge.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: pre-merge
2+
3+
on:
4+
push:
5+
branches: [ devel ]
6+
pull_request:
7+
branches: [ devel ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-24.04
13+
strategy:
14+
matrix:
15+
python-version: ["3.8", "3.10"]
16+
include:
17+
- python-version: "3.8"
18+
python-py-version: "py38"
19+
- python-version: "3.10"
20+
python-py-version: "py310"
21+
container: ghcr.io/${{ github.repository }}:${{ matrix.python-py-version }}-poetry-bullseye
22+
credentials:
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
- name: Python Version
30+
run: python3 --version
31+
- name: Poetry Venv Dir
32+
run: |
33+
echo "VENV_DIR=$(poetry config virtualenvs.path)" >> $GITHUB_ENV
34+
35+
- name: Restore the Cache
36+
id: cache-deps
37+
uses: actions/cache@v3
38+
with:
39+
path: ${{ env.VENV_DIR }}
40+
# bump the suffix if you need to force-refresh the cache
41+
key: streamlit-parameters-cache-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock', '**/tox.ini') }}-1
42+
43+
# Install all deps, sans the project (--no-root)
44+
- name: Poetry - Install Dependencies
45+
run: poetry install --no-interaction --no-root
46+
if: steps.cache-deps.outputs.cache-hit != 'true'
47+
48+
# Project is installed separately to avoid always invalidating the cache
49+
- name: Poetry - Install Project
50+
run: poetry install --no-interaction
51+
- name: Tox - Tests [py38]
52+
# fast this time around since the last step did the installation, venv.bash will only check here
53+
run: |
54+
source ./venv.bash
55+
tox -e py38
56+
57+
- name: Tox - Tests
58+
run: poetry run tox --workdir ${{ env.VENV_DIR }} -e ${{ matrix.python-py-version }}
59+
60+
- name: Tox - Formatters, Linters
61+
run: poetry run tox --workdir ${{ env.VENV_DIR }} -e check
62+
63+
- name: Froody
64+
run: echo I am froody, you should be too
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: push-poetry-image
2+
3+
env:
4+
REGISTRY: ghcr.io
5+
IMAGE_NAME: ${{ github.repository }}
6+
POETRY_VERSION: 1.8.4
7+
PYTHON_PRIMARY_VERSION: 3.10.15
8+
PYTHON_PRIMARY_TAG: py310
9+
PYTHON_SECONDARY_VERSION: 3.8.16
10+
PYTHON_SECONDARY_TAG: py38
11+
DEBIAN_VERSION: bullseye
12+
13+
on:
14+
push:
15+
paths:
16+
- .devcontainer/Dockerfile
17+
branches:
18+
- devel
19+
workflow_dispatch:
20+
21+
jobs:
22+
push-poetry-image:
23+
runs-on: ubuntu-24.04
24+
permissions:
25+
contents: read
26+
packages: write
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
- name: Login to GCR
31+
uses: docker/login-action@v2
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
- name: Metadata
37+
id: meta
38+
uses: docker/metadata-action@v4
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
- name: Echo
42+
run: |
43+
echo "USER: ${{ github.actor }}"
44+
echo "REPOSITORY: ${{ github.repository }}"
45+
echo "POETRY_VERSION: ${POETRY_VERSION}"
46+
echo "PYTHON_PRIMARY_VERSION: ${PYTHON_PRIMARY_VERSION}"
47+
echo "PYTHON_SECONDARY_VERSION: ${PYTHON_SECONDARY_VERSION}"
48+
echo "TAGS: ${{ steps.meta.outputs.tags }}"
49+
echo "LABELS: ${{ steps.meta.outputs.labels }}"
50+
- name: Image - poetry${{ env.POETRY_VERSION }}-python${{ env.PYTHON_PRIMARY_VERSION }}
51+
uses: docker/build-push-action@v3
52+
with:
53+
file: ./.devcontainer/Dockerfile
54+
push: true
55+
build-args: |
56+
PYTHON_VERSION=${{ env.PYTHON_PRIMARY_VERSION }}
57+
POETRY_VERSION=${{ env.POETRY_VERSION }}
58+
DEBIAN_VERSION=${{ env.DEBIAN_VERSION }}
59+
tags: |
60+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PYTHON_PRIMARY_TAG }}-poetry-${{ env.DEBIAN_VERSION }}
61+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:python${{ env.PYTHON_PRIMARY_VERSION }}-poetry${{ env.POETRY_VERSION }}-${{ env.DEBIAN_VERSION }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
- name: Image - poetry${{ env.POETRY_VERSION }}-python${{ env.PYTHON_SECONDARY_VERSION }}
64+
uses: docker/build-push-action@v3
65+
with:
66+
file: ./.devcontainer/Dockerfile
67+
push: true
68+
build-args: |
69+
PYTHON_VERSION=${{ env.PYTHON_SECONDARY_VERSION }}
70+
POETRY_VERSION=${{ env.POETRY_VERSION }}
71+
DEBIAN_VERSION=${{ env.DEBIAN_VERSION }}
72+
tags: |
73+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PYTHON_SECONDARY_TAG }}-poetry-${{ env.DEBIAN_VERSION }}
74+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:python${{ env.PYTHON_SECONDARY_VERSION }}-poetry${{ env.POETRY_VERSION }}-${{ env.DEBIAN_VERSION }}
75+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/release_archive.yaml renamed to .github/workflows/release-archive.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release Archive
1+
name: release-archive
22

33
on:
44
release:

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Cut a release whenever a new tag is pushed to the repo.
22
# You should use an annotated tag, like `git tag -a v1.2.3`
33
# and put the release notes into the commit message for the tag.
4-
name: Release
4+
name: release
55

66
on:
77
push:

0 commit comments

Comments
 (0)