Skip to content

Commit 2194e4f

Browse files
authored
Back to python (#33)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced health check endpoints for application monitoring. - Enhanced video upload process with organized folders for each member and video. - Implemented image service to generate images in multiple formats. - **Enhancements** - Optimized Docker build process with a separate builder stage and non-root user setup. - Restructured project functionality to better facilitate video uploads. - Improved error handling and content type validation for image uploads. - **Refactor** - Updated folder structure creation for members and videos. - Refined symlink handling across services. - **Documentation** - Added comprehensive docstrings to model classes. - Updated README to reflect shift in project functionality. - **Tests** - Modified video model tests to support list of URLs. - **Chores** - Enhanced CI/CD pipeline with new jobs for linting, testing, and Docker image publishing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 686f3a7 commit 2194e4f

File tree

21 files changed

+1882
-447
lines changed

21 files changed

+1882
-447
lines changed

.circleci/config.yml

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,79 @@
11
version: 2.1
22
orbs:
33
python: circleci/[email protected]
4+
docker: circleci/[email protected]
5+
github-cli: circleci/[email protected]
6+
executors:
7+
python:
8+
docker:
9+
- image: cimg/python:3.12.2
10+
defaults:
11+
docker_publish: &docker_publish
12+
image: bsstudio/bss-web-file-api
13+
registry: ghcr.io
14+
executor: docker/docker
15+
remote-docker-version: default
16+
use-remote-docker: true
17+
remote-docker-dlc: true
18+
use-buildkit: true
19+
tag_only: &tag_only
20+
filters:
21+
branches:
22+
ignore: /.*/
23+
tags:
24+
only: /.*/
425
jobs:
526
lint:
6-
docker:
7-
- image: cimg/python:3.12.1
27+
executor: python
828
steps:
929
- checkout
1030
- python/install-packages:
1131
pkg-manager: poetry
1232
- run: poetry run isort . --check
13-
- run: poetry run black --check .
33+
- run: poetry run black . --check
34+
- run: poetry run mypy -p src.bss_web_file_server
35+
verify-requirements:
36+
executor: python
37+
steps:
38+
- checkout
39+
- python/install-packages:
40+
pkg-manager: poetry
41+
- run: poetry export -o requirements.txt
42+
- run: git diff --exit-code
43+
github_release:
44+
docker:
45+
- image: cimg/base:stable
46+
steps:
47+
- checkout
48+
- github-cli/install:
49+
version: 2.43.1
50+
- github-cli/setup:
51+
version: 2.43.1
52+
- run: gh release create << pipeline.git.tag >> -t << pipeline.git.tag >> --generate-notes
1453
workflows:
15-
app:
54+
Build:
1655
jobs:
17-
- lint
56+
- lint:
57+
name: Lint
58+
- verify-requirements:
59+
name: Verify requirements.txt
1860
- python/test:
61+
name: Unit tests
1962
pkg-manager: poetry
2063
test-tool: pytest
21-
version: 3.12.1
64+
version: 3.12.2
65+
- docker/hadolint:
66+
name: Lint Dockerfile
67+
- docker/publish:
68+
name: Build docker image
69+
<<: *docker_publish
70+
deploy: false
71+
Release:
72+
jobs:
73+
- docker/publish:
74+
name: Publish image
75+
<<: [*docker_publish, *tag_only]
76+
tag: latest,<< pipeline.git.tag >>
77+
- github_release:
78+
name: Create release
79+
<<: *tag_only

.dockerignore

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
### Python template
2+
# Byte-compiled / optimized / DLL files
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# poetry
99+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100+
# This is especially recommended for binary packages to ensure reproducibility, and is more
101+
# commonly ignored for libraries.
102+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103+
#poetry.lock
104+
105+
# pdm
106+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107+
#pdm.lock
108+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109+
# in version control.
110+
# https://pdm.fming.dev/#use-with-ide
111+
.pdm.toml
112+
113+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
114+
__pypackages__/
115+
116+
# Celery stuff
117+
celerybeat-schedule
118+
celerybeat.pid
119+
120+
# SageMath parsed files
121+
*.sage.py
122+
123+
# Environments
124+
.env
125+
.venv
126+
env/
127+
venv/
128+
ENV/
129+
env.bak/
130+
venv.bak/
131+
132+
# Spyder project settings
133+
.spyderproject
134+
.spyproject
135+
136+
# Rope project settings
137+
.ropeproject
138+
139+
# mkdocs documentation
140+
/site
141+
142+
# mypy
143+
.mypy_cache/
144+
.dmypy.json
145+
dmypy.json
146+
147+
# Pyre type checker
148+
.pyre/
149+
150+
# pytype static type analyzer
151+
.pytype/
152+
153+
# Cython debug symbols
154+
cython_debug/
155+
156+
# PyCharm
157+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159+
# and can be added to the global gitignore or merged into this file. For a more nuclear
160+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
161+
.idea/
162+
163+
.git

Dockerfile

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
1-
FROM python:3.12.2 as poetry
2-
RUN pip install poetry==1.7.1
1+
FROM python:3.12 as builder
32

4-
FROM poetry
53
WORKDIR /app
64

7-
COPY pyproject.toml poetry.lock ./
8-
RUN poetry install --no-root --no-directory
5+
# python
6+
ENV PYTHONUNBUFFERED=1 \
7+
# prevents python creating .pyc files
8+
PYTHONDONTWRITEBYTECODE=1 \
9+
\
10+
# pip
11+
PIP_NO_CACHE_DIR=off \
12+
PIP_DISABLE_PIP_VERSION_CHECK=on
913

10-
COPY ./src/ ./src
11-
COPY ./README.md ./
12-
RUN poetry install --only=main
14+
COPY ./requirements.txt ./
1315

14-
RUN mkdir -p /data/{m,member,v,video}
15-
ENV SERVER_BASE_PATH="/data"
16+
RUN pip wheel --no-cache-dir --no-deps --wheel-dir ./wheels -r requirements.txt
1617

18+
FROM python:3.12-slim AS app
19+
20+
# use non-root user
21+
RUN adduser --system --group --home /home/abc abc
22+
USER abc:abc
23+
WORKDIR /home/abc
24+
25+
# python
26+
ENV PYTHONUNBUFFERED=1 \
27+
# prevents python creating .pyc files
28+
PYTHONDONTWRITEBYTECODE=1 \
29+
\
30+
# pip
31+
PIP_NO_CACHE_DIR=off \
32+
PIP_DISABLE_PIP_VERSION_CHECK=on
33+
34+
COPY --from=builder /app/wheels ./wheels
35+
COPY --from=builder /app/requirements.txt ./
36+
37+
RUN pip install --no-cache-dir ./wheels/*
38+
39+
COPY ./src ./src
40+
41+
EXPOSE 80
1742
CMD ["uvicorn", "src.bss_web_file_server.main:app", "--host", "0.0.0.0", "--port", "80"]

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
11
# BSS Web File Server
2-
Manage symlinks and image uploads
2+
3+
This project aims to help the video upload process.
4+
It will create folders for each member and video
5+
based on their uuid.
6+
7+
## Run server
8+
9+
```shell
10+
uvicorn src.bss_web_file_server.main:app
11+
```
12+
13+
## Development
14+
15+
```shell
16+
uvicorn src.bss_web_file_server.main:app --reload
17+
```
18+
19+
## Lint
20+
21+
```shell
22+
poetry run isort . --check
23+
poetry run black . --check
24+
poetry run mypy -p src.bss_web_file_server
25+
```
26+
27+
Apply lint
28+
29+
```shell
30+
poetry run isort .
31+
poetry run black .
32+
```
33+
34+
## Test
35+
36+
```shell
37+
poetry run pytest
38+
```
39+
40+
## Build docker image
41+
```shell
42+
docker build -t bss_web_file_server .
43+
```
44+
45+
## Run docker compose
46+
```shell
47+
docker-compose up
48+
```

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3.9"
2+
services:
3+
app:
4+
build:
5+
context: .
6+
ports:
7+
- "80:80"
8+
environment:
9+
SERVER_BASE_PATH: /assets
10+
healthcheck:
11+
test: "wget --tries=1 --no-verbose -qO- http://localhost:80/health | grep -q UP"
12+
start_period: 5s
13+
interval: 10s
14+
timeout: 5s
15+
retries: 5
16+
volumes:
17+
- ./assets:/assets

0 commit comments

Comments
 (0)