mirror of
https://github.com/kevinveenbirkenbach/homepage.veen.world.git
synced 2025-09-09 19:27:11 +02:00
Compare commits
3 Commits
4d68ed2a24
...
35bfeeb51e
Author | SHA1 | Date | |
---|---|---|---|
35bfeeb51e | |||
dfbc840c69 | |||
1bea9703ea |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
app/config.yaml
|
app/config.yaml
|
||||||
*__pycache__*
|
*__pycache__*
|
||||||
app/static/cache/*
|
app/static/cache/*
|
||||||
|
.env
|
11
Dockerfile
11
Dockerfile
@@ -11,8 +11,11 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|||||||
# Copy application code
|
# Copy application code
|
||||||
COPY app/ .
|
COPY app/ .
|
||||||
|
|
||||||
# Expose port
|
# Set default port environment variable
|
||||||
EXPOSE 5000
|
ENV PORT=5000
|
||||||
|
|
||||||
# Start command
|
# Expose port (optional for documentation)
|
||||||
CMD ["python", "app.py"]
|
EXPOSE ${PORT}
|
||||||
|
|
||||||
|
# Start command using shell to allow env substitution
|
||||||
|
CMD ["sh", "-c", "exec python app.py --port=${PORT}"]
|
||||||
|
@@ -64,4 +64,5 @@ def index():
|
|||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=(FLASK_ENV == "development"), host="0.0.0.0", port=5000)
|
port = int(os.getenv("PORT", 5000))
|
||||||
|
app.run(debug=(FLASK_ENV == "development"), host="0.0.0.0", port=port)
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
portfolio:
|
portfolio:
|
||||||
build:
|
build:
|
||||||
@@ -6,7 +8,9 @@ services:
|
|||||||
image: application-portfolio
|
image: application-portfolio
|
||||||
container_name: portfolio
|
container_name: portfolio
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "${PORT:-5000}:${PORT:-5000}"
|
||||||
volumes:
|
volumes:
|
||||||
- ./app:/app
|
- ./app:/app
|
||||||
|
environment:
|
||||||
|
- PORT=${PORT:-5000}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
2
env.example
Normal file
2
env.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
PORT=5000
|
||||||
|
FLASK_ENV=production
|
19
main.py
19
main.py
@@ -22,6 +22,17 @@ import argparse
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Always load .env from the script's directory
|
||||||
|
dotenv_path = Path(__file__).resolve().parent / ".env"
|
||||||
|
|
||||||
|
if dotenv_path.exists():
|
||||||
|
load_dotenv(dotenv_path)
|
||||||
|
else:
|
||||||
|
print(f"⚠️ Warning: No .env file found at {dotenv_path}")
|
||||||
|
PORT = int(os.getenv("PORT", 5000))
|
||||||
|
|
||||||
def run_command(command, dry_run=False):
|
def run_command(command, dry_run=False):
|
||||||
"""Utility function to run a shell command."""
|
"""Utility function to run a shell command."""
|
||||||
@@ -94,7 +105,7 @@ def run_dev(args):
|
|||||||
volume_mapping = f"{current_dir}/app/:/app"
|
volume_mapping = f"{current_dir}/app/:/app"
|
||||||
command = [
|
command = [
|
||||||
"docker", "run", "-d",
|
"docker", "run", "-d",
|
||||||
"-p", "5000:5000",
|
"-p", f"{PORT}:{PORT}",
|
||||||
"--name", "portfolio",
|
"--name", "portfolio",
|
||||||
"-v", volume_mapping,
|
"-v", volume_mapping,
|
||||||
"-e", "FLASK_APP=app.py",
|
"-e", "FLASK_APP=app.py",
|
||||||
@@ -115,7 +126,7 @@ def run_prod(args):
|
|||||||
"""
|
"""
|
||||||
command = [
|
command = [
|
||||||
"docker", "run", "-d",
|
"docker", "run", "-d",
|
||||||
"-p", "5000:5000",
|
"-p", "{PORT}:{PORT}",
|
||||||
"--name", "portfolio",
|
"--name", "portfolio",
|
||||||
"application-portfolio"
|
"application-portfolio"
|
||||||
]
|
]
|
||||||
@@ -194,7 +205,7 @@ def browse(args):
|
|||||||
|
|
||||||
This command launches the Chromium browser to view the running application.
|
This command launches the Chromium browser to view the running application.
|
||||||
"""
|
"""
|
||||||
command = ["chromium", "http://localhost:5000"]
|
command = ["chromium", f"http://localhost:{PORT}"]
|
||||||
run_command(command, args.dry_run)
|
run_command(command, args.dry_run)
|
||||||
|
|
||||||
|
|
||||||
@@ -222,7 +233,7 @@ def main():
|
|||||||
|
|
||||||
# Browse command
|
# Browse command
|
||||||
parser_browse = subparsers.add_parser(
|
parser_browse = subparsers.add_parser(
|
||||||
"browse", help="Open http://localhost:5000 in Chromium browser."
|
"browse", help="Open application in Chromium browser."
|
||||||
)
|
)
|
||||||
parser_browse.set_defaults(func=browse)
|
parser_browse.set_defaults(func=browse)
|
||||||
|
|
||||||
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
python-dotenv
|
Reference in New Issue
Block a user