-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linter to PR and minify Docker image (#3)
* Add linters for PR * Update Dockerfile and Docker image * Update building process * Update a Python version to 3.12
- Loading branch information
Showing
15 changed files
with
345 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
.env | ||
NPSdir | ||
TORRENTdir | ||
.editorconfig | ||
.gitignore | ||
app/config/local.py | ||
.dockerignore | ||
docker-compose.yml | ||
docker-compose.local.yml | ||
wiki/ | ||
.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: 2 | ||
updates: | ||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
|
||
assignees: | ||
- "jag-k" | ||
|
||
# Maintain dependencies for Poetry | ||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
|
||
# Include a list of updated dependencies | ||
# with a prefix determined by the dependency group | ||
commit-message: | ||
prefix: "poetry" | ||
prefix-development: "poetry dev" | ||
include: "scope" | ||
|
||
assignees: | ||
- "jag-k" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: PR Validation | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
validate-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check labels | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
# language=JavaScript | ||
script: | | ||
const { data: pullRequest } = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
}); | ||
const labels = pullRequest.labels.map(label => label.name); | ||
const invalidLabels = ['feature request', 'invalid', 'question']; | ||
const hasInvalidLabel = labels.some(label => invalidLabels.includes(label)); | ||
if (labels.length === 0) { | ||
core.setFailed('Pull request must have at least one label!'); | ||
} | ||
if (hasInvalidLabel) { | ||
core.setFailed('Pull request must have an invalid label: ' + invalidLabels.join(', ')); | ||
} | ||
- name: Check assignees | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
# language=JavaScript | ||
script: | | ||
const { data: pullRequest } = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
}); | ||
if (pullRequest.assignees.length === 0) { | ||
core.setFailed('Pull request must have an assignee'); | ||
} | ||
- name: Check draft status | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
# language=JavaScript | ||
script: | | ||
const { data: pullRequest } = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
}); | ||
if (pullRequest.draft) { | ||
core.setFailed('Pull request must not be a draft'); | ||
} | ||
validate-code: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.get_version.outputs.version }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install poetry | ||
run: pipx install poetry | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.12' | ||
cache: 'poetry' | ||
|
||
- name: Install dependencies | ||
run: poetry install | ||
|
||
- name: Run Ruff | ||
run: poetry run ruff check --output-format=github . | ||
|
||
- name: Run pre-commit hooks | ||
run: poetry run pre-commit run --all-files --show-diff-on-failure | ||
|
||
- name: Get version from pyproject.toml | ||
id: get_version | ||
run: | | ||
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT | ||
validate-branch: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- validate-code | ||
|
||
if: startsWith(github.head_ref, 'release/') | ||
steps: | ||
- name: Check branch name with version | ||
run: | | ||
# Extract the branch name from the GitHub context | ||
branch_name=${{ github.head_ref }} | ||
# Check if the branch name starts with "release/" and does not match the version | ||
if [[ $branch_name == release/* && $branch_name != "release/${{ needs.validate-code.outputs.version }}" ]]; then | ||
echo "Branch name does not match the version in pyproject.toml" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
FROM python:3.11-slim | ||
FROM python:3.12-slim as base | ||
|
||
LABEL org.opencontainers.image.source = "https://github.com/jag-k/owntinfoil" | ||
LABEL org.opencontainers.image.source="https://github.com/jag-k/owntinfoil" | ||
LABEL org.opencontainers.image.description="OwnTinfoil Image" | ||
LABEL org.opencontainers.image.licenses="MIT" | ||
|
||
WORKDIR /app | ||
|
||
ENV NPS_DIR=/nps | ||
ENV TORRENT_DIR=/torrents | ||
ENV PIP_DEFAULT_TIMEOUT=100 \ | ||
# Allow statements and log messages to immediately appear | ||
PYTHONUNBUFFERED=1 \ | ||
# disable a pip version check to reduce run-time & log-spam | ||
PIP_DISABLE_PIP_VERSION_CHECK=1 \ | ||
# cache is useless in docker image, so disable to reduce image size | ||
PIP_NO_CACHE_DIR=1 | ||
ENV PYTHONPATH=/app | ||
ENV POETRY_VERSION=1.7.1 | ||
WORKDIR $PYTHONPATH | ||
|
||
FROM base as builder | ||
|
||
ARG POETRY_VERSION=1.7.1 | ||
RUN pip install "poetry==$POETRY_VERSION" | ||
|
||
COPY pyproject.toml poetry.lock ./ | ||
RUN poetry config virtualenvs.create false && \ | ||
poetry install --without dev | ||
|
||
COPY . /app | ||
# Set poetry config to install packages in /venv/project/lib/python3.12/site-packages | ||
RUN poetry config virtualenvs.path "/venv" && \ | ||
poetry config virtualenvs.prompt "project" && \ | ||
poetry install --no-root --only main | ||
|
||
|
||
FROM base as final | ||
|
||
ENV NPS_DIR=/nps | ||
ENV TORRENT_DIR=/torrents | ||
|
||
# Copy python side-packages from builder | ||
COPY --from=builder "/venv/project/lib/python3.12/site-packages" "/usr/local/lib/python3.11/site-packages" | ||
|
||
COPY . $PYTHONPATH | ||
|
||
#ENTRYPOINT ["/bin/bash"] | ||
CMD ["python", "app/main.py"] |
Empty file.
Oops, something went wrong.