Skip to content
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
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.venv
data
.env
tests
__pycache__
*.py[cod]
10 changes: 8 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
GARMIN_USERNAME=<your username / email>
GARMIN_PASSWORD=<your password>
WITHINGS_CLIENT_ID=
WITHINGS_CLIENT_SECRET=
WITHINGS_REDIRECT_URI=
SYNC_INTERVAL=1h
TZ=UTC
LOG_LEVEL=INFO
PUID=1000
PGID=1000
97 changes: 0 additions & 97 deletions .github/workflows/build-publish.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ jobs:
- name: Checkout repository 🛒
uses: actions/checkout@v6

- name: Update version in pyproject.toml ⬆️
if: startsWith(github.ref, 'refs/tags/')
run: |
VERSION=${GITHUB_REF#refs/tags/}
sed -i "s/version = \"1.0.0.dev1\"/version = \"$VERSION\"/" pyproject.toml

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

Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Python package

on:
push:
tags:
- "v*"

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Set version from tag
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
python - <<'PY'
import os
import re
from pathlib import Path

version = os.environ["RELEASE_TAG"].removeprefix("v")
if not re.fullmatch(r"\d+\.\d+\.\d+(?:[a-zA-Z0-9.-]+)?", version):
raise SystemExit("Release tag must contain a valid package version.")
path = Path("pyproject.toml")
content, count = re.subn(
r'(?m)^version = "[^"]+"$',
f'version = "{version}"',
path.read_text(),
count=1,
)
if count != 1:
raise SystemExit("Could not update the project version.")
path.write_text(content)
PY
- run: python -m pip install build
- run: python -m build
- uses: pypa/gh-action-pypi-publish@release/v1
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test and build

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- run: pip install -e ".[test]"
- run: pytest
- run: docker compose build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*.egg-info/
dist/
.idea
*.json
.env
data/
.venv/
53 changes: 17 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
FROM python:3.12-alpine
FROM python:3.12-slim

ARG PROJECT="withings-sync"
ARG PACKAGE="withings_sync"
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG PUID=1000
ARG PGID=1000

RUN apk --no-cache add supercronic
RUN apt-get update && apt-get install -y --no-install-recommends tzdata && \
rm -rf /var/lib/apt/lists/* && \
groupadd --gid "${PGID}" app && \
useradd --uid "${PUID}" --gid app --create-home --shell /usr/sbin/nologin app && \
mkdir -p /app /data && chown app:app /app /data

RUN if getent passwd ${USER_UID} >/dev/null; then \
deluser $(getent passwd ${USER_UID} | cut -d: -f1); fi && \
if getent group ${USER_GID} >/dev/null; then \
delgroup $(getent group ${USER_GID} | cut -d: -f1); fi
RUN addgroup --system --gid ${USER_GID} ${PROJECT} && \
adduser --system --disabled-password --home /home/${PROJECT} \
--uid ${USER_UID} --ingroup ${PROJECT} ${PROJECT}
WORKDIR /app
COPY pyproject.toml README.md ./
COPY withings_sync ./withings_sync
RUN pip install --no-cache-dir .

ENV PROJECT_DIR="/home/${PROJECT}"
ENV DATA_DIR=/data \
PYTHONUNBUFFERED=1

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

ENTRYPOINT ["poetry", "run", "withings-sync"]
USER app
ENTRYPOINT ["withings-sync"]
CMD []
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

Loading
Loading