added docker as an example

This commit is contained in:
Kristian Krsnik 2025-01-04 20:05:01 +01:00
parent 0901edf8eb
commit 2414e01f8b
Signed by: Kristian
GPG Key ID: FD1330AC9F909E85
4 changed files with 61 additions and 5 deletions

28
Dockerfile Normal file
View File

@ -0,0 +1,28 @@
# Nix builder
FROM nixos/nix:latest AS builder
# Copy our source and setup our working dir.
COPY . /tmp/build
WORKDIR /tmp/build
# Build our Nix environment
RUN nix \
--extra-experimental-features "nix-command flakes" \
--option filter-syscalls false \
build
# Copy the Nix store closure into a directory. The Nix store closure is the
# entire set of Nix store values that we need for our build.
RUN mkdir /tmp/nix-store-closure
RUN cp -r $(nix-store -qR result/) /tmp/nix-store-closure
# Final image is based on scratch. We copy a bunch of Nix dependencies
# but they're fully self-contained so we don't need Nix anymore.
FROM scratch
WORKDIR /app
# Copy /nix/store
COPY --from=builder /tmp/nix-store-closure /nix/store
COPY --from=builder /tmp/build/result /app
CMD ["/app/bin/testdata"]

15
docker-compose.yaml Normal file
View File

@ -0,0 +1,15 @@
services:
testdata:
image: result/latest
build:
dockerfile: ./Dockerfile
environment:
TESTDATA_HOST: 0.0.0.0
TESTDATA_PORT: 1234
TESTDATA_CONFIG: ./config.json
volumes:
- ./config.json:/app/config.json
- ./db.json:/app/db.json
- ./log.jsonl:/app/log.jsonl

View File

@ -1,6 +1,6 @@
[project] [project]
name = "testdata" name = "testdata"
version = "1.1.0" version = "1.2.0"
requires-python = "~=3.12, <4" requires-python = "~=3.12, <4"
dependencies = [ dependencies = [
"fastapi~=0.115.3", "fastapi~=0.115.3",
@ -31,7 +31,7 @@ where = ["src"]
testdata = ["py.typed"] testdata = ["py.typed"]
[tool.autopep8] [tool.autopep8]
max_line_length = 175 max_line_length = 150
[tool.pylint.'MESSAGES CONTROL'] [tool.pylint.'MESSAGES CONTROL']
disable = [ disable = [

19
src/testdata/main.py vendored
View File

@ -1,3 +1,4 @@
import os
import sys import sys
import argparse import argparse
import asyncio import asyncio
@ -11,9 +12,21 @@ def parse_args(args: list[str]):
parser = argparse.ArgumentParser(formatter_class=formatter) parser = argparse.ArgumentParser(formatter_class=formatter)
parser.add_argument('-c', '--config', type=argparse.FileType('r'), default='./config.json', help='Path to config file in JSON format.', ) parser.add_argument(
parser.add_argument('-l', '--listen', type=str, default='0.0.0.0', help='IP on which to listen.') '-c', '--config', type=argparse.FileType('r'),
parser.add_argument('-p', '--port', type=int, default='8080', help='Port on which to serve the webserver.') default=os.environ['TESTDATA_CONFIG'] if 'TESTDATA_CONFIG' in os.environ else './config.json',
help='Path to config file in JSON format.'
)
parser.add_argument(
'-l', '--listen', type=str,
default=os.environ['TESTDATA_HOST'] if 'TESTDATA_HOST' in os.environ else '0.0.0.0',
help='IP on which to listen.'
)
parser.add_argument(
'-p', '--port', type=int,
default=os.environ['TESTDATA_PORT'] if 'TESTDATA_PORT' in os.environ else 8080,
help='Port on which to serve the webserver.'
)
return parser.parse_args(args) return parser.parse_args(args)