Skip to content

Commit

Permalink
feat(py): update Dockerfile and compose
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 17, 2024
1 parent 7a795ab commit a587fd2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions template/py/{{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ COPY . .
# Ensure the application builds and tests are executed correctly
RUN hatch build && hatch test

HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"

CMD ["python", "src/app.py"]
8 changes: 8 additions & 0 deletions template/py/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ ruff:
image:
@docker image build -t $(APP_NAME) .

# Start a compose service
compose-up:
@docker compose -f ./compose.yml -p $(APP_NAME) up -d

# Shutdown a compose service
compose-down:
@docker compose -f ./compose.yml down

# Clean build artifacts
clean:
@rm -rf build dist *.egg-info htmlcov .coverage coverage.xml coverage.lcov
Expand Down
6 changes: 3 additions & 3 deletions template/py/{{cookiecutter.project_slug}}/compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: Compose specification

service:
services:
{{cookiecutter.project_slug}}:
build: .
ports:
- 8000:8000

networks:
{{cookiecutter.project_slug}}-net:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
from http.server import HTTPServer, SimpleHTTPRequestHandler


def run_server(port=8000):
handler = SimpleHTTPRequestHandler
with HTTPServer(("", port), handler) as httpd:
print(f"Serving at port {port}")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nShutting down the server...")
httpd.shutdown()


if __name__ == "__main__":
print("hello, world")
run_server()

0 comments on commit a587fd2

Please sign in to comment.