Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev env #8

Merged
merged 60 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0fca428
Initial commit
frgfm Apr 3, 2021
ffb11fd
Add the base for the docker swarm
ThibaultDac Apr 8, 2021
5013946
Merge branch 'main' of github.com:pyronear/pyro-devops
Apr 24, 2024
93ffa2f
feat: add new docker-compose dev env
Apr 17, 2024
1cb8373
fix: add user of the same group than devices
Apr 17, 2024
e8b07b3
feat: add precommit hook config
Apr 17, 2024
e33c6f6
feat: add yml precommit
Apr 17, 2024
a2df596
refactor(init script): use logging lib instead of print
Apr 17, 2024
561b2d6
feat: add new gitAction for precommit hook
Apr 17, 2024
84c4f94
feat: add gitAction to test docker-compose
Apr 17, 2024
ef8121e
fix(gitAction docker-compose): add a step to check logs
Apr 17, 2024
c7612da
feat: add healthcheck of pyro-api & change precommit config
Apr 17, 2024
e879b36
fix: use python3.9 in gitAction
Apr 18, 2024
8a590e9
fix: python version error
Apr 22, 2024
2814d74
feat: add a reolink "dev" camera
Apr 23, 2024
b42c3f4
refactor: create a Makefile and new directories
Apr 23, 2024
93a227c
fix: use Makefile in the gitAction
Apr 23, 2024
2602e08
refactor: generate self signed certificate in the reolink script
Apr 23, 2024
21c87cd
feat: launch test every night
Apr 23, 2024
46e1cf0
feat: add comment explining how to load images in the env
Apr 23, 2024
151b7d7
feat(test): add a test which will check that an alert has been sent
Apr 23, 2024
20e8caf
feat(test): add a test for localstack
Apr 24, 2024
1ab6717
fix: cachez moi ces erreurs que je ne saurais voir
Apr 24, 2024
20a020f
fix (gitAction) : exclude log error from localstack initialisation
Apr 24, 2024
0f5472a
fix(localstack): error in localstack usage
Apr 26, 2024
ddb69c5
fix(test): localstack test
Apr 26, 2024
d44e3ca
fix(gitAction) : grep error
Apr 26, 2024
fc62eef
fix(gitAction) : grep error
Apr 26, 2024
2d9286d
fix(gitAction): exit 0
Apr 26, 2024
33fb6fc
fix(gitAction): tant pis
Apr 26, 2024
cc7541c
fix: add"site" bucket behavior
May 3, 2024
d9a6729
Revert "fix: add"site" bucket behavior"
May 21, 2024
a8150cc
feat: add test in Makefile
May 21, 2024
b1995a6
30-> 60
May 21, 2024
efa6df3
feat: add platform container
Jun 4, 2024
a629740
feat: add a scd camera for test
Jun 26, 2024
7a1a774
feat: update api and init script with new data model
Jun 28, 2024
86b17f0
fix: new credentials.json model
Jul 2, 2024
3b7a66f
feat: add new camera with ptz endpoint
Jul 2, 2024
7f480d0
fix tests
Jul 2, 2024
2524663
fix: add azimuth in credentials.json
Jul 3, 2024
1320562
small fixes
Jul 13, 2024
fbb1ce9
refactor: rm type from orga
Jul 14, 2024
bae9456
rm lat / lon from var env
Sep 16, 2024
06b05c1
feat: add engine healthcheck
Sep 17, 2024
168b215
feat: add ETL container
Oct 26, 2024
e6557f4
fix telegram error
RonanMorgan Nov 5, 2024
33c28fe
small refactor
RonanMorgan Jan 29, 2025
3891f71
add file in gitignore
RonanMorgan Jan 29, 2025
9b09b02
rm LOGIN env var from front
RonanMorgan Jan 29, 2025
de09c0d
fix test detection -> detections
RonanMorgan Jan 29, 2025
8702372
fix test media error
RonanMorgan Jan 29, 2025
d77f8ee
fix test
RonanMorgan Jan 29, 2025
c01e57a
fix precommit hook
RonanMorgan Jan 29, 2025
1e5069e
fix CI
RonanMorgan Jan 29, 2025
a88b5c4
Readme. Rm useless var env
RonanMorgan Jan 29, 2025
c9bda0b
README
RonanMorgan Jan 29, 2025
0ad605a
try fixing CI
RonanMorgan Jan 29, 2025
e47b802
fix github workflow
RonanMorgan Jan 29, 2025
8627b32
fix CI
RonanMorgan Jan 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
API_URL=http://pyro_api:5050
CAM_USER=my_dummy_login
CAM_PWD=my_dummy_pwd

LOKI_URL=http://my-loki-service.com
PROMTAIL_DEVICE_SCOPE=tower_scope
PROMTAIL_DEVICE_NAME=tower_name

SUPERADMIN_LOGIN=dummy_login
SUPERADMIN_PWD=dummy&P@ssw0rd!

POSTGRES_USER=dummy_pg_user
POSTGRES_PASSWORD=dummy_pg_pwd
POSTGRES_DB=dummy_pg_db

S3_ENDPOINT_URL=http://localstack:4566
S3_ACCESS_KEY=fake
S3_SECRET_KEY=fake
S3_REGION=us-east-1
60 changes: 60 additions & 0 deletions .github/workflows/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Docker Compose Up and Health Check

on:
pull_request:
push:
branches: [main]
schedule:
- cron: "0 0 * * *"

jobs:
docker-compose-up:
name: Docker Compose Up
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.9]
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Wait for containers to start
run: make build

- name: Run docker-compose up -d
run: make run

# Wait for containers to start up (adjust the sleep time as needed)
- name: Wait for containers to start
run: sleep 120

- name: Check container health
run: docker compose ps --filter "status=unhealthy" --quiet
continue-on-error: true
id: check_health

- name: Print container health status
run: |-
if [ -z "${{ steps.check_health.outputs.stdout }}" ]; then
echo "All containers are healthy"
exit 0
else
echo "Some containers are unhealthy"
exit 1
fi

- name: load tests requirements
run: pip install -r tests/requirements.txt

- name: launch tests
run: pytest tests/*

- name: Capture logs
run: docker compose logs --tail=40 > logs.txt

- name: Show logs
run: cat logs.txt

- name: Filter logs
run: cat logs.txt | grep -i -E "error|exception" | grep -v -i "hypercorn.error" || true
22 changes: 22 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
architecture: x64
- uses: pre-commit/[email protected]
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*.onnx
*.jpg
data/images/
*.pem
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -26,7 +30,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST

venv_*
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down Expand Up @@ -102,8 +106,8 @@ celerybeat.pid
*.sage.py

# Environments
.env
.venv
.env
env/
venv/
ENV/
Expand All @@ -127,3 +131,10 @@ dmypy.json

# Pyre type checker
.pyre/

model_metadata.json
metadata.yaml
model_ncnn.py
model.ncnn.bin
model.ncnn.param
*.zip
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
default_language_version:
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
exclude: .conda
- id: check-toml
- id: check-added-large-files
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-ast
- id: check-json
- id: check-merge-conflict
- id: no-commit-to-branch
args: [--branch, main]
- id: debug-statements
language_version: python3
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.3.0
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.290
hooks:
- id: ruff
args:
- --fix
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.3.1
hooks:
- id: python-safety-dependencies-check

- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint-docker
name: Lint Dockerfiles (Docker image)
description: Runs hadolint Docker image to lint Dockerfiles
language: docker_image
types: [dockerfile]
entry: ghcr.io/hadolint/hadolint hadolint
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build the docker images contained in this repo

build:
docker build -f containers/init_script/Dockerfile -t pyronear/pyro-api-init:latest containers/init_script/
docker build -f containers/dev_reolink/Dockerfile -t pyronear/dev-reolink:latest containers/dev_reolink/
docker build -f containers/reolink_dev2/Dockerfile -t pyronear/reolink-dev2:latest containers/reolink_dev2/

build-external:
cd ../pyro-api/; make build
cd ../pyro-engine/; make build-lib
cd ../pyro-engine/; make build-app
cd ../pyro-platform/; make build


build-all: build build-external

run-api:
cp .env.test .env
docker compose up -d

run-engine:
cp .env.test .env
docker compose --profile engine up -d

run-etl:
cp .env.test .env
docker compose --profile etl up -d

run:
cp .env.test .env
docker compose --profile front --profile engine up -d

stop:
docker compose --profile front --profile engine --profile etl down

test:
pytest -s tests/*
104 changes: 40 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,58 @@
# pyro-devops
**README**

Deployment and infrastructure management



## Getting started

## Structure

The file docker-swarm.yml is used for the docker swarm
The folder nginx is a demo for a image of a reverse proxy with nginx
This Docker Compose configuration sets up a development environment for Pyronear's API along with supporting services like a PostgreSQL database, LocalStack for S3 emulation, Pyro Engine, and Promtail for log shipping.

### Prerequisites
- Docker and Docker Compose installed on your system.
- Precommit hook installed on this repo


- Docker swarm



### Installation
### Services
1. **pyro-api**: Runs the Pyronear API using uvicorn.
2. **db**: PostgreSQL database for the API.
3. **localstack**: Emulates AWS S3 using LocalStack.
4. **pyro-engine**: Pyro Engine service.
5. **reolink_dev**: a service which imitate a reolink camera by sending back pictures of fire.
6. **frontend**: our webapp available on the 8085 port.

https://docs.docker.com/get-docker/
### Usage

https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/
First you have to create a .env file, a simple copy of the .env.test would be enough.
```
cp .env.test .env
```


## Security good practice
https://docs.docker.com/engine/install/linux-postinstall/
Log your infrastructure and your containers (portainer,...)
Run your ssh/administration on a private network (with bastion + vpn)
https://www.stackrox.com/post/2019/09/docker-security-101/
AppArmor/ SELinux,failtoban, iptable, waf
Check your SLA, IT Disastery Recovery process
Vulnerability assessment and management (VAM)
Identity and Access Management
Start the Docker services using the following command:
```
make build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make this on two lines or add a && I don't know why but it's display one line

make run
```
Then, you will be able to connect to the API thanks to the credentials in the .env file

## Usage
If you want to launch only the engine and two dev-cameras you can use :
```
make run-engine
```

you can check that everyhing is working thanks to the following commands :
```
docker logs init
docker logs engine
```

### Accessing the API
Once the services are up and running, you can access the Pyronear API at `http://localhost:5050/docs`.


Export the variables/secret in your env file (if you don't have a Vault)
```
export BUCKET_MEDIA_FOLDER=media
...
```

If needed build your images (for exemple the mynginx image in the folder nginx) and push it in the local registry
### Accessing the web-app
Since Dash can be a bit capricious, you should launch a private window from you browser and access the web app at `http://localhost:8050`

### Cleanup
To stop and remove the Docker services, run:
```
docker run -d -p 5000:5000 --restart=always --name registry registry:2 #start the local registry

docker build -t pyro/mynginx .

docker image tag pyro/mynginx localhost:5000/mynginx

docker push localhost:5000/mynginx:latest

docker pull localhost:5000/mynginx
make stop
```

and after deploy your docker swarm
```

docker stack deploy -c docker-swarm.yml my_node

```

You can check that the service is running with



```

docker service ls

docker ps

docker service logs xxxxxx
### More images in the Reoling Dev Camera

```
you need to create a directory data/images before launching the env, with the images inside !
23 changes: 23 additions & 0 deletions containers/dev_reolink/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use the official Python image as the base image
FROM python:3.9-slim

# hadolint ignore=DL3008
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Set the working directory in the container
WORKDIR /app

# Install dependencies
RUN pip install --no-cache-dir flask==3.0.3

# Copy the Flask server files into the container
COPY reolinkcamera.py /app/

# Expose port 5000 for Flask server
EXPOSE 443

# Command to run the Flask server
CMD ["python", "/app/reolinkcamera.py"]
Loading