Skip to content

Commit

Permalink
Merge pull request #1 from inean/asyncio
Browse files Browse the repository at this point in the history
Move logic to an asyncio based one
  • Loading branch information
inean authored Aug 19, 2024
2 parents 796e6ad + c3dec95 commit 8bb26fe
Show file tree
Hide file tree
Showing 49 changed files with 2,686 additions and 842 deletions.
4 changes: 4 additions & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--container-architecture linux/arm64
--container-options --security-opt label:disable
--action-offline-mode
--artifact-server-path /tmp
42 changes: 42 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Builder image
FROM debian:bookworm-slim AS builder

# hadolint ignore=DL3008
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl
EOF

# Install and initialize rye
ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"

# hadolint ignore=DL4006
RUN <<EOF
curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash
rye config --set-bool behavior.global-python=true
rye config --set-bool behavior.use-uv=true
EOF

# Copy project
WORKDIR /opt

# Find pinned python version on current project and download it
COPY ./.python-version ./
RUN rye pin "$(cat .python-version)"

# Devcontainer image
FROM mcr.microsoft.com/vscode/devcontainers/base:bookworm
COPY --from=builder /opt/rye /opt/rye

ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"
ENV PYTHONUNBUFFERED=True

# Use rye as the default python and uv as default package manager
RUN <<EOF
rye config --set-bool behavior.global-python=true
rye config --set-bool behavior.use-uv=true
EOF

RUN chown -R vscode $RYE_HOME
73 changes: 73 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// For format details, see https://aka.ms/devcontainer.json. For config options
{
"name": "CloudFlare DNS Updater",
"shutdownAction": "stopCompose",
"workspaceFolder": "/workspace",

// Docker Compose Options
"dockerComposeFile": "docker-compose.yml",
"service": "devcontainer",

"features": {
"ghcr.io/dhoeric/features/hadolint:1": { },
"ghcr.io/devcontainers/features/docker-outside-of-docker": {
"postCreateCommand": "sudo usermod -aG docker vscode"
}
},
"customizations": {
"vscode": {
"extensions": [
// Python exrtensions
"charliermarsh.ruff",
"codezombiech.gitignore",
"exiasr.hadolint",
"kevinrose.vsc-python-indent",
"mosapride.zenkaku",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-vscode-remote.remote-containers",
"njpwerner.autodocstring",
"shardulm94.trailing-spaces",
"usernamehw.errorlens",
"yzhang.markdown-all-in-one"

// Project related extensions
],
"settings": {
"python.defaultInterpreterPath": "${containerWorkspaceFolder}/.venv/bin/python",
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.rulers": [
88
]
},
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/bin/zsh"
}
}
}
}
},

// Forward traefik dashboard port
"forwardPorts": [ 8080 ],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "rye sync -f",

// use 'postStartCommand' to run commands after the container is started.
"postStartCommand": "which git && rye run pre-commit install",

// Run vscode-server as non-root user
"containerUser": "vscode"

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
//"remoteUser": "root"
}
51 changes: 51 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
version: '3.8'
name: "cloudflare-updater"
services:
devcontainer:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
environment:
- PYTHONUNBUFFERED=1
volumes:
- ..:/workspace:cached
cap_add:
- SYS_ADMIN
- AUDIT_WRITE
security_opt:
- seccomp=unconfined
- label=disable
- apparmor=unconfined
depends_on:
- traefik
- whoami
# Override the default command so things don't shut down after the process ends.
command: sleep infinity
labels:
- "traefik.enable=false"

traefik:
image: traefik:v3.1
container_name: traefik
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
ports:
- "8080:8080"
- "80:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
cap_add:
- SYS_ADMIN
security_opt:
- seccomp=unconfined
- label=disable
- apparmor=unconfined

whoami:
image: containous/whoami
container_name: whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
examples/
src/mock.py
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

42 changes: 0 additions & 42 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

23 changes: 0 additions & 23 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

69 changes: 69 additions & 0 deletions .github/actions/setup-python-with-rye/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
name: Setup Rye
description: Install Python with Rye

inputs:
python-version:
description: Python version
required: false
rye-version:
description: Rye version
required: false
default: "latest"

outputs:
python-version:
description: The Python version to use
value: ${{ steps.compute-python-version.outputs.python-version }}

runs:
using: composite
steps:
- name: Compute Python Version
id: compute-python-version
run: |
PYTHON_VERSION="${{ inputs.python-version }}"
if [ -z "$PYTHON_VERSION" ]; then
PYTHON_VERSION=$(cat .python-version)
fi
if [ -z "$PYTHON_VERSION" ]; then
echo "No Python version specified, and no .python-version file found"
exit 1
fi
echo "Python version specified: $PYTHON_VERSION"
echo "python-version=$PYTHON_VERSION" >> $GITHUB_OUTPUT
shell: bash

- name: Install Rye
uses: eifinger/setup-rye@v4
with:
enable-cache: true
cache-prefix: ${{ steps.compute-python-version.outputs.python-version }}

- name: Set Rye Config
run: |
rye config --set-bool behavior.global-python=true
rye config --set-bool behavior.use-uv=true
shell: bash

- name: Pin Python Version ${{ steps.compute-python-version.outputs.python-version }}
run: |
export PYTHONUNBUFFERED=True
rye pin ${{ steps.compute-python-version.outputs.python-version }}
shell: bash

- name: Install dependencies
if: steps.setup-rye.outputs.cache-hit != 'true'
run: |
if [ -f requirements.lock ] && [ -f requirements-dev.lock ]; then
rye sync --no-lock
else
rye sync
fi
shell: bash

- name: Cache pre-commit
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.cache/pre-commit
key: pre-commit-|${{ steps.compute-python-version.outputs.python-version }}|${{ hashFiles('.pre-commit-config.yaml') }}
1 change: 0 additions & 1 deletion .github/config.yml

This file was deleted.

15 changes: 12 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
---
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
- package-ecosystem: pip
directory: "/"
schedule:
interval: "daily"
interval: weekly
commit-message:
prefix: "chore(rye)"

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
commit-message:
prefix: "chore(github-actions)"
21 changes: 21 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Actions CI

on:
push:
branches: [ main ]

pull_request:
branches: [ main ]

jobs:
lint-actions:

runs-on: ubuntu-latest

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

- name: Lint GitHub Actions
uses: eifinger/actionlint-action@v1
Loading

0 comments on commit 8bb26fe

Please sign in to comment.