Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
soerface committed Jun 20, 2023
0 parents commit f268784
Show file tree
Hide file tree
Showing 34 changed files with 6,367 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
localhost, snatch.flipdot.org {
handle_path /static/* {
root * /mnt/static
file_server
}

handle_path /media/* {
root * /mnt/media
file_server
}

handle_path /api/* {
reverse_proxy api:8000
}

handle {
reverse_proxy frontend
}
}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SNATCH

Surveillance Network for Auto Tag Capture and Hunting

## Overview

SNATCH is a tool for capturing car license plates by manual human input.
It allows to record when a car passes by a certain location.

It only saves the license plate temporarily and in a hashed form.

## Setup

```
docker-compose up --build -d
# visit http://localhost
```

## Development

### Frontend

```
cd frontend
npm i
npm run dev
npm run format # reformats the code
```

### Backend

```
cd backend
poetry install
poetry shell
uvicorn main:app --reload
```
20 changes: 20 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.10-slim

ENV POETRY_HOME="/opt/poetry"
ENV POETRY_VERSION=1.4.2
RUN pip install poetry==$POETRY_VERSION
ENV PATH="$POETRY_HOME/bin:$PATH"

WORKDIR /app

COPY pyproject.toml .
COPY poetry.lock .
RUN poetry install --only main

COPY . .

ENTRYPOINT ["poetry", "run"]

CMD ["uvicorn", "--host", "0.0.0.0", "--root-path", "/api", "main:app"]
EXPOSE 8000

3 changes: 3 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from fastapi import FastAPI

app = FastAPI()
422 changes: 422 additions & 0 deletions backend/poetry.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "snatch"
version = "0.1.0"
description = ""
authors = ["soerface <[email protected]>"]
license = "AGPL-3.0-only"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
fastapi = "^0.97.0"
redis = "^4.5.5"
uvicorn = "^0.22.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.3.2"
black = "^23.3.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
43 changes: 43 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
api:
build:
context: ./backend
volumes:
- .:/code
environment:
- REDIS_URL=redis://db:6379/0
depends_on:
- db
frontend:
build:
context: ./frontend
depends_on:
- api
db:
image: redis:7-alpine
command: redis-server --save 60 1 --loglevel warning
volumes:
- redis-data:/data
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 5s
timeout: 5s
retries: 5
caddy:
image: caddy:2.4.5-alpine
ports:
- "80:80"
- "443:443"
volumes:
- "./Caddyfile:/etc/caddy/Caddyfile"
- "caddy-data:/data"
- "static_files:/mnt/static"
# - "media_files:/mnt/media"
depends_on:
- api
- frontend
volumes:
redis-data:
caddy-data:
static_files:
# media_files:
2 changes: 2 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
14 changes: 14 additions & 0 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn',
},
}
24 changes: 24 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
14 changes: 14 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:20-alpine as build
USER node
WORKDIR /home/node

COPY --chown=node package.json package-lock.json ./
RUN npm ci

COPY --chown=node . ./
RUN npm run build

FROM ghcr.io/nikeee/docker-nginx-spa:latest
WORKDIR /app

COPY --from=build /home/node/dist /app
13 changes: 13 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/snatch.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SNATCH</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit f268784

Please sign in to comment.