Skip to content

Commit 8e7b2f2

Browse files
committed
Refactor Dockerfile, update dependencies, and enhance README
- Changed working directory in Dockerfile from /usr/src/app to /usr/app. - Added SQLite and other dependencies in Dockerfile. - Introduced entrypoint script and adjusted permissions for non-root user. - Updated poetry.lock and pyproject.toml to reflect new dependencies and versions. - Enhanced README with new features, requirements, and deployment instructions. - Improved caching and error handling in main application logic. - Added new styles and functionality in templates for better user experience. - Removed obsolete Kubernetes deployment files and updated Skaffold configuration.
1 parent e1918a9 commit 8e7b2f2

29 files changed

+2641
-1031
lines changed

.dockerignore

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
.pytest_cache/
8+
9+
# Virtual Environment
10+
.env
11+
.venv
12+
env/
13+
venv/
14+
ENV/
15+
16+
# IDE
17+
.idea/
18+
.vscode/
19+
*.swp
20+
*.swo
21+
22+
# Logs
23+
*.log
24+
25+
# Local development
26+
.git/
27+
.gitignore
28+
README.md
29+
tests/
30+
docs/
31+
32+
# Docker
33+
Dockerfile
34+
.dockerignore
35+
36+
# Kubernetes
37+
deploy/
38+
skaffold.yaml
39+
40+
# Database
41+
*.db
42+
*.sqlite3

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ deploy/k8s/secret.yaml
33
deploy/k8s/ingress.yaml
44
.venv/**
55
.venv/
6-
__pycache__
6+
__pycache__
7+
deploy/k8s/overlays
8+
deploy/k8s/base/secret.yaml

.pre-commit-config.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 24.10.0
4+
hooks:
5+
- id: black
6+
language_version: python3
7+
args: [--line-length=100]
8+
9+
- repo: https://github.com/Yelp/detect-secrets
10+
rev: v1.5.0
11+
hooks:
12+
- id: detect-secrets
13+
args: ['--baseline', '.secrets.baseline']
14+
exclude: package.lock.json
15+
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v5.0.0
18+
hooks:
19+
- id: trailing-whitespace
20+
- id: end-of-file-fixer
21+
- id: check-yaml
22+
- id: check-added-large-files
23+
- id: check-json
24+
- id: check-case-conflict
25+
- id: check-merge-conflict

.secrets.baseline

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{
2+
"version": "1.5.0",
3+
"plugins_used": [
4+
{
5+
"name": "ArtifactoryDetector"
6+
},
7+
{
8+
"name": "AWSKeyDetector"
9+
},
10+
{
11+
"name": "AzureStorageKeyDetector"
12+
},
13+
{
14+
"name": "Base64HighEntropyString",
15+
"limit": 4.5
16+
},
17+
{
18+
"name": "BasicAuthDetector"
19+
},
20+
{
21+
"name": "CloudantDetector"
22+
},
23+
{
24+
"name": "DiscordBotTokenDetector"
25+
},
26+
{
27+
"name": "GitHubTokenDetector"
28+
},
29+
{
30+
"name": "GitLabTokenDetector"
31+
},
32+
{
33+
"name": "HexHighEntropyString",
34+
"limit": 3.0
35+
},
36+
{
37+
"name": "IbmCloudIamDetector"
38+
},
39+
{
40+
"name": "IbmCosHmacDetector"
41+
},
42+
{
43+
"name": "IPPublicDetector"
44+
},
45+
{
46+
"name": "JwtTokenDetector"
47+
},
48+
{
49+
"name": "KeywordDetector",
50+
"keyword_exclude": ""
51+
},
52+
{
53+
"name": "MailchimpDetector"
54+
},
55+
{
56+
"name": "NpmDetector"
57+
},
58+
{
59+
"name": "OpenAIDetector"
60+
},
61+
{
62+
"name": "PrivateKeyDetector"
63+
},
64+
{
65+
"name": "PypiTokenDetector"
66+
},
67+
{
68+
"name": "SendGridDetector"
69+
},
70+
{
71+
"name": "SlackDetector"
72+
},
73+
{
74+
"name": "SoftlayerDetector"
75+
},
76+
{
77+
"name": "SquareOAuthDetector"
78+
},
79+
{
80+
"name": "StripeDetector"
81+
},
82+
{
83+
"name": "TelegramBotTokenDetector"
84+
},
85+
{
86+
"name": "TwilioKeyDetector"
87+
}
88+
],
89+
"filters_used": [
90+
{
91+
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
92+
},
93+
{
94+
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
95+
"min_level": 2
96+
},
97+
{
98+
"path": "detect_secrets.filters.heuristic.is_indirect_reference"
99+
},
100+
{
101+
"path": "detect_secrets.filters.heuristic.is_likely_id_string"
102+
},
103+
{
104+
"path": "detect_secrets.filters.heuristic.is_lock_file"
105+
},
106+
{
107+
"path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string"
108+
},
109+
{
110+
"path": "detect_secrets.filters.heuristic.is_potential_uuid"
111+
},
112+
{
113+
"path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign"
114+
},
115+
{
116+
"path": "detect_secrets.filters.heuristic.is_sequential_string"
117+
},
118+
{
119+
"path": "detect_secrets.filters.heuristic.is_swagger_file"
120+
},
121+
{
122+
"path": "detect_secrets.filters.heuristic.is_templated_secret"
123+
}
124+
],
125+
"results": {
126+
"src/main.py": [
127+
{
128+
"type": "Secret Keyword",
129+
"filename": "src/main.py",
130+
"hashed_secret": "7e6a3680012346b94b54731e13d8a9ffa3790645",
131+
"is_verified": false,
132+
"line_number": 304
133+
}
134+
]
135+
},
136+
"generated_at": "2025-01-14T23:13:44Z"
137+
}

Dockerfile

+18-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ENV PYTHONFAULTHANDLER=1 \
1111
CRYPTOGRAPHY_DONT_BUILD_RUST=1 \
1212
TZ='Europe/Rome'
1313

14-
WORKDIR /usr/src/app
14+
WORKDIR /usr/app
1515

1616
# Installiamo le dipendenze di sistema necessarie per Alpine
1717
RUN apk add --no-cache \
@@ -25,7 +25,10 @@ RUN apk add --no-cache \
2525
openssl-dev \
2626
cargo \
2727
make \
28-
bind-tools
28+
bind-tools \
29+
sqlite
30+
31+
RUN mkdir /data && chown nobody:nobody /data
2932

3033
# Installiamo poetry e configuriamolo
3134
RUN pip3 install --no-cache-dir --upgrade pip && \
@@ -40,10 +43,20 @@ RUN poetry install --only main --no-interaction --no-ansi
4043

4144
# Copiamo il resto del codice sorgente
4245
COPY src/ ./
46+
COPY entrypoint.sh ./
47+
COPY dev-tools/ ./dev-tools/
48+
# Rendiamo eseguibile lo script di entrypoint
49+
RUN chmod +x entrypoint.sh
50+
# Rendi scrivibile i file per l'utente nobody
51+
RUN chown -R 1000:1000 /usr/app && chmod -R u+w /usr/app
4352

44-
# Copiamo i file statici
45-
COPY src/static /app/src/static
53+
# Create user ilpoastapi with uid 1000 and gid 1000 using adduser, and add group ilpoastapi
54+
RUN addgroup -g 1000 ilpoastapi && adduser -u 1000 -G ilpoastapi -s /bin/sh -D ilpoastapi && chown -R ilpoastapi:ilpoastapi /usr/app && chmod -R u+w /usr/app
4655

4756
EXPOSE 5000
4857

49-
CMD ["uvicorn", "main:app", "--proxy-headers", "--port", "5000", "--host", "0.0.0.0", "--forwarded-allow-ips", "*"]
58+
# Imposta l'utente non-root
59+
# USER nobody
60+
USER ilpoastapi
61+
62+
ENTRYPOINT ["./entrypoint.sh"]

0 commit comments

Comments
 (0)