Add Docker build/push tooling and Traefik compose
This commit is contained in:
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
@@ -24,11 +24,11 @@
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "Build Docker Image",
|
||||
"label": "Build & Push Docker",
|
||||
"type": "shell",
|
||||
"command": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
|
||||
"args": [
|
||||
"${workspaceFolder}/docker/build_image.py"
|
||||
"${workspaceFolder}/docker/build_and_push_image.py"
|
||||
],
|
||||
"problemMatcher": []
|
||||
}
|
||||
|
||||
15
docker-compose.traefik.yml
Normal file
15
docker-compose.traefik.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
services:
|
||||
astrain:
|
||||
image: git.beging.de/troogs/astrain:latest
|
||||
restart: unless-stopped
|
||||
container_name: astrain
|
||||
networks:
|
||||
- proxy
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.fs-onboarding-si.rule=Host(`astrain.melvin.beging.de`)
|
||||
- traefik.http.services.fs-onboarding-si.loadbalancer.server.port=8080
|
||||
|
||||
networks:
|
||||
proxy:
|
||||
external: true
|
||||
26
docker/build_and_push_image.py
Normal file
26
docker/build_and_push_image.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
scripts = ["build_image.py", "push_image.py"]
|
||||
|
||||
for script in scripts:
|
||||
script_path = script_dir / script
|
||||
print(f"Executing {script}...")
|
||||
try:
|
||||
subprocess.run([sys.executable, str(script_path)], check=True)
|
||||
print(f"{script} executed successfully.\n")
|
||||
except subprocess.CalledProcessError as error:
|
||||
print(f"Error: {script} failed with exit code {error.returncode}.")
|
||||
return error.returncode
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
57
docker/push_image.py
Normal file
57
docker/push_image.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime as dt
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_timestamp_tag(today: dt.date) -> str:
|
||||
year_suffix = today.year % 100
|
||||
day_of_year = today.timetuple().tm_yday
|
||||
return f"{year_suffix}.{day_of_year}"
|
||||
|
||||
|
||||
def run_command(command: list[str], repo_root: Path) -> int:
|
||||
print(" ".join(command))
|
||||
result = subprocess.run(command, cwd=str(repo_root))
|
||||
return result.returncode
|
||||
|
||||
|
||||
def main() -> int:
|
||||
repo_root = Path(__file__).resolve().parents[1]
|
||||
|
||||
today = dt.date.today()
|
||||
timestamp_tag = get_timestamp_tag(today)
|
||||
|
||||
local_image = "troogs/astrain"
|
||||
registry_image = "git.beging.de/troogs/astrain"
|
||||
tags = ["latest", timestamp_tag]
|
||||
|
||||
for tag in tags:
|
||||
tag_cmd = [
|
||||
"docker",
|
||||
"tag",
|
||||
f"{local_image}:{tag}",
|
||||
f"{registry_image}:{tag}",
|
||||
]
|
||||
print(f"Tagging {local_image}:{tag} as {registry_image}:{tag}")
|
||||
exit_code = run_command(tag_cmd, repo_root)
|
||||
if exit_code != 0:
|
||||
return exit_code
|
||||
|
||||
for tag in tags:
|
||||
push_cmd = [
|
||||
"docker",
|
||||
"push",
|
||||
f"{registry_image}:{tag}",
|
||||
]
|
||||
print(f"Pushing {registry_image}:{tag}")
|
||||
exit_code = run_command(push_cmd, repo_root)
|
||||
if exit_code != 0:
|
||||
return exit_code
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user