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

Future code base components? (python 3.12 / pyproject.toml vs setup.py / poetry vs pip-pipenv-twine-... / docker improvements) #181

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e1530dd
Use of pkg_resources is deprecated in favor of importlib.resources, i…
stynoo Nov 13, 2024
9c5ac51
The recommended way of using Setuptools has shifted in the direction …
stynoo Nov 13, 2024
0e920f4
Update Dockerfile to use poetry & run as a non-priviledged user.
stynoo Nov 13, 2024
63920bb
up to new major version - https://packaging.python.org/en/latest/spec…
stynoo Nov 13, 2024
09edea9
migrate release script from setup.py/twine to pyproject.toml/poetry
stynoo Nov 13, 2024
131195d
do_release.sh: user versions & tags from pyproject.toml
stynoo Nov 13, 2024
69cff35
sync.py: minimal requirement python 3.12
stynoo Nov 13, 2024
c166add
build-publish.yml: update to use poetry
stynoo Nov 13, 2024
c351a31
update version in pyproject.toml from the git tags
stynoo Dec 7, 2024
9896a15
check if we are good to run on ubuntu-24.04 (latest will upgrade soon…
stynoo Dec 7, 2024
43951b5
test run on ubuntu-24.04 successfull, reverting to latest, we are goo…
stynoo Dec 7, 2024
ac480e9
remove .VERSION from Dockerfile
stynoo Dec 7, 2024
192a6f7
test package building to test-pypi
stynoo Dec 11, 2024
6d99ecb
build-publish.yml: allow trusted package publishing
stynoo Dec 11, 2024
75b598a
build-publish.yml: remove secrets
stynoo Dec 11, 2024
53827f8
build-publish.yml: split build & push
stynoo Dec 11, 2024
dd3055d
build-publish.yml: Store the distribution packages
stynoo Dec 11, 2024
c8de115
build-publish.yml: match versions
stynoo Dec 11, 2024
49a1afe
build-publish.yml: publish always to testpypi but only to pypi on re…
stynoo Dec 11, 2024
ebb3a10
build-publish.yml: add skip-existing to testpypi
stynoo Dec 11, 2024
5a3c36a
build-publish.yml: enrich github release with package
stynoo Dec 11, 2024
30247bc
sync.py: add version parameter && black code formatting
stynoo Dec 14, 2024
5f30683
Dockerfile: best practices & prep for supercronic usage
stynoo Dec 15, 2024
569d443
docker-image.yml: prevent unknown/unknown - OS/Arch - images pushed t…
stynoo Dec 15, 2024
2fd7c1c
streamline actions / only prod push on releases
stynoo Dec 15, 2024
2995e46
docker-image.yml: case
stynoo Dec 15, 2024
745ea1e
docker-image.yml: streamline action filters
stynoo Dec 15, 2024
b90cdcd
build-publish.yml: remove double condition
stynoo Dec 15, 2024
32adfd3
Update README.md
stynoo Dec 15, 2024
016a6aa
Merge branch 'master' of github.com:stynoo/withings-sync
stynoo Dec 15, 2024
64ba9c3
README.md: updates
stynoo Dec 15, 2024
1052bdf
README.md: more updates
stynoo Dec 15, 2024
458b786
README.md: cleanup
stynoo Dec 15, 2024
64b3adc
README.md: more cleanup
stynoo Dec 15, 2024
cb17773
README.md: expand docker-compose commands
stynoo Dec 17, 2024
e158679
README.md: work on expanding the pip installation & running methods
stynoo Dec 18, 2024
028045f
README.md: more improvements to the installation section
stynoo Dec 18, 2024
7b13b81
README.md: expand docker instructions
stynoo Dec 18, 2024
1b48102
README.md: expand even more on docker compose install & execution met…
stynoo Dec 18, 2024
b1cc2e3
README.md: formatting
stynoo Dec 18, 2024
316c944
README.md: add normal docker instructions
stynoo Dec 18, 2024
bc90031
README.md: moved Obtaining Authorization to the relevant install sect…
stynoo Dec 18, 2024
71bbb59
README.md: add .withings_user.json to docker-compose section
stynoo Dec 18, 2024
b9343ec
update to latest packages
stynoo Dec 20, 2024
1d174b1
README.md: fix some issues in the readme that prevent proper auth
stynoo Dec 20, 2024
198591c
pyproject.toml: make sure we sync and fill all entries with the old s…
stynoo Dec 20, 2024
ac82ad3
Dockerfile: optimize layers
stynoo Dec 20, 2024
7e4944c
README.md: add logging to the docker compose method
stynoo Dec 22, 2024
f124b7e
README.md: more formatting
stynoo Dec 22, 2024
db3a1c2
README.md: even more formatting
stynoo Dec 22, 2024
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
1 change: 0 additions & 1 deletion .VERSION

This file was deleted.

104 changes: 79 additions & 25 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,97 @@
---

name: Build and Publish Release via PyPi
name: Build and Publish Release to PyPI & GitHub

on: push

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- name: Update version file ⬆️
- name: Checkout repository 🛒
uses: actions/checkout@v4
- name: Update version in pyproject.toml ⬆️
uses: brettdorrans/[email protected]
longstone marked this conversation as resolved.
Show resolved Hide resolved
with:
filename: '.VERSION'
placeholder: '${VERSION}'

- name: Set up Python 3.12
filename: 'pyproject.toml'
placeholder: '1.0.0.dev1'
- name: Set up Python 3.12 🐍
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install and configure Poetry 📜
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
- name: Build & Package project 👷
run: poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/withings-sync
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }} # LEAVING THIS HERE UNTIL TRUSTED PUBLISHING IS IN PLACE

- name: Install pypa/build
run: >-
python -m
pip install
build
--user
publish-to-github-release:
name: Upload the Python 🐍 distribution to GitHub Release
if: startsWith(github.ref, 'refs/tags/') # only upload to GitHub Release on tag pushes
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Release
uses: fnkr/github-action-ghr@v1
env:
GHR_PATH: dist/
GHR_REPLACE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build a source tarball
run: >-
python -m
build
--sdist
--outdir dist/ .

- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/withings-sync
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
skip-existing: true
35 changes: 13 additions & 22 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,55 @@

name: Publish Docker Image

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
schedule:
- cron: '21 5 */5 * *'
push:
branches: [ master ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
on: push

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
name: Build and publish Docker image 📦 to ghcr 🗃️
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
- name: Checkout repository 🛒
uses: actions/checkout@v4

- name: Update version file ⬆️
- name: Update version in pyproject.toml ⬆️
uses: brettdorrans/[email protected]
with:
filename: '.VERSION'
placeholder: '${VERSION}'
filename: 'pyproject.toml'
placeholder: '1.0.0.dev1'

- name: Set up QEMU
- name: Set up QEMU 👷
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
- name: Set up Docker Buildx 👷
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
- name: Log in to the Container registry 🗃️
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels) for Docker 🗂️
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image 📦 to ghcr
- name: Build and push Docker image 📦 to ghcr 🗃️
uses: docker/build-push-action@v6
with:
context: .
push: true
push: ${{ startsWith(github.ref, 'refs/tags/') }} # only upload to ghcr on tag pushes
provenance: false
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
40 changes: 28 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
FROM python:3.12-alpine

# Install python-lxml
RUN apk add --no-cache --virtual .build-deps \
gcc musl-dev \
libxslt-dev libxml2-dev && \
pip install lxml setuptools && \
apk del .build-deps && \
apk add --no-cache libxslt libxml2
ENV PROJECT="withings-sync" \
PACKAGE="withings_sync"

RUN mkdir -p /src
COPY . /src
RUN apk --no-cache add supercronic

RUN cd /src && \
pip install .
RUN adduser -D $PROJECT

ENTRYPOINT ["withings-sync"]
ENV PROJECT_DIR="/home/${PROJECT}"

USER $PROJECT
WORKDIR $PROJECT_DIR

ENV PATH="${PROJECT_DIR}/.poetry/bin:${PATH}" \
PATH="${PROJECT_DIR}/.local/bin:${PATH}" \
PIP_ROOT_USER_ACTION=ignore \
PIP_DISABLE_PIP_VERSION_CHECK=on \
POETRY_HOME="${PROJECT_DIR}/.poetry" \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR="/tmp/poetry_cache"

RUN pip install poetry

COPY --chown=$PROJECT:$PROJECT pyproject.toml poetry.lock README.md $PROJECT_DIR/
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR

COPY --chown=$PROJECT:$PROJECT $PACKAGE ./$PACKAGE/
RUN poetry install --without dev
stynoo marked this conversation as resolved.
Show resolved Hide resolved

ENTRYPOINT ["poetry", "run", "withings-sync"]
Loading