Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM python:3.9-slim

WORKDIR /app

COPY Pipfile Pipfile.lock /app/
FROM docker.io/library/python:3.9-slim

RUN apt-get update && apt-get install -y \
gcc \
libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir pipenv

WORKDIR /app

COPY Pipfile Pipfile.lock /app/
RUN pipenv install --system --deploy

COPY src/ /app/

EXPOSE 8000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
107 changes: 107 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Variables
ENV_FILE := .env

# read envfile for persistancy
-include $(ENV_FILE)

# ENV Variables
STAGE ?= local
HOSTNAME ?= localhost
# set to your birdweather station id
STATION_ID ?=

# docker internals
DOCKER_COMPOSE_FILE = docker-compose.yml
DOCKER_COMPOSE_CMD = docker compose
DOCKER_SERVICE =
DOCKER_LOGS_FOLLOW =

# use 80:, 443: to bind to lower ports instead of a 8000:
# use a empty value for random ports
PUBLIC_PORT_HTTP ?= 8000:
PUBLIC_PORT_HTTPS ?= 8443:

# fallback to older version docker-compose
ifneq ($(shell which docker-compose),)
DOCKER_COMPOSE_CMD = docker-compose
endif

# if you are more modern and use podman and podman-compose
ifneq ($(shell which podman-compose),)
DOCKER_COMPOSE_CMD = podman-compose
endif

# Ensure exported variables are available in all recipes
export STAGE HOSTNAME STATION_ID DOCKER_COMPOSE_CMD
export PUBLIC_PORT_HTTP PUBLIC_PORT_HTTPS

.PHONY: all
all: banner

.PHONY: run
run: banner up welcome

.PHONY: up
up:
$(DOCKER_COMPOSE_CMD) -f $(DOCKER_COMPOSE_FILE) up --detach

.PHONY: build
build: Dockerfile down up

Dockerfile: Pipfile.lock
$(DOCKER_COMPOSE_CMD) -f $(DOCKER_COMPOSE_FILE) build
touch $@

Pipfile.lock: Pipfile
$(DOCKER_COMPOSE_CMD) -f $(DOCKER_COMPOSE_FILE) run --volume ./:/app2 \
--workdir /app2 --entrypoint=/usr/local/bin/pipenv app lock

.PHONY: stop
stop: down banner goodbye

.PHONY: down
down:
$(DOCKER_COMPOSE_CMD) -f $(DOCKER_COMPOSE_FILE) down

.PHONY: ps
ps:
$(DOCKER_COMPOSE_CMD) -f $(DOCKER_COMPOSE_FILE) ps

.PHONY: logs
logs:
$(DOCKER_COMPOSE_CMD) -f $(DOCKER_COMPOSE_FILE) logs $(DOCKER_SERVICE) $(DOCKER_LOGS_FOLLOW)

.PHONY: banner
banner:
@echo ""
@echo " \\\\ "
@echo " (o> "
@echo " \\\\_//) "
@echo " \_/_)"
@echo " _|_ "

welcome:
@echo ""
@echo "\033[1;34m👋 Welcome to the vogel-spotter application\033[0m"
@echo ""

goodbye:
@echo ""
@echo "\033[1;34m👋 Goodbye\033[0m"
@echo ""

# write a envfile to make your variables persistant
export ENV_FILE_CONTENTS
$(ENV_FILE):
@echo "$${ENV_FILE_CONTENTS}" > $@
# contents of $(ENV_FILE)
@cat $@

# contents of the env file
define ENV_FILE_CONTENTS
STATION_ID=$(STATION_ID)
STAGE=$(STAGE)
HOSTNAME=$(HOSTNAME)
PUBLIC_PORT_HTTP=$(PUBLIC_PORT_HTTP)
PUBLIC_PORT_HTTPS=$(PUBLIC_PORT_HTTPS)
endef
81 changes: 48 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- [▲ Vercel](#-vercel)
- [💻 Lokaal](#-lokaal)
- [🌐 Server](#-server)
- [🪹 Voorbeeld .env bestand](#-voorbeeld-env-bestand)
- [🦆 Projectstructuur](#-projectstructuur)
- [🐓 Frontend](#-frontend)
- [🦉 Backend](#-backend)
Expand All @@ -31,7 +30,7 @@ Het doel is om vogelliefhebbers een eenvoudig platform te bieden om vogelactivit
## 🐤 Functies

- Weergave van recente vogelwaarnemingen van het afgelopen uur.
- Geeft de status van het BirdWeather-station weer (online/offline).
- Weergave van top 25 meest waargenomen vogelsoorten op dit BirdWeather-station.
- Responsief ontwerp geschikt voor verschillende schermformaten.
- Ondersteuning voor dark mode voor gebruik in omgevingen met weinig licht.
- Bevat een refresh-knop voor snelle updates.
Expand All @@ -50,48 +49,63 @@ Het is mogelijk om de applicatie te implementeren op [Vercel](https://vercel.com

[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/iMartzen/vogel-spotter)

Vergeet niet om de omgevingsvariabele toe te voegen aan de setup. Raadpleeg de [Vercel documentatie](https://vercel.com/docs/projects/environment-variables) voor meer informatie.
Vergeet niet om de omgevingsvariabele `STATION_ID` toe te voegen aan de setup. Raadpleeg de [Vercel documentatie](https://vercel.com/docs/projects/environment-variables) voor meer informatie.

### 💻 Lokaal

Het is ook mogelijk om lokaal de applicatie te draaien. Volg hieronder de stappen.

1. **Clone de repository**:

```bash
git clone https://github.com/iMartzen/vogel-spotter.git
cd vogel-spotter
```

2. **Start de applicatie en volg de instructies**:
2. **Start de applicatie**:

```bash
./run.sh
make run STATION_ID=XXX
```

*Als het script geen uitvoerrechten heeft:* `chmod +x run.sh`
*Vervang XXX met het nummer van je station id

3. **Open je browser** en ga naar:
4. **Open je browser** en ga naar:

```bash
https://$HOSTNAME.local
https://localhost:8443
```
5. **Stop de applicatie**

4. **Stop de applicatie**
```bash
make stop
```

6. **Genereer een `.env` bestand met het `STATION_ID` om deze te onthouden** (optioneel):

Na het opslaan van STATION_ID kun je `make run` en `make stop` gebruiken zonder opnieuw je STATION_ID op te geven.
```bash
./stop.sh
make .env STATION_ID=XXX -B
```
*Vervang XXX met het nummer van je station id

*Als het script geen uitvoerrechten heeft:* `chmod +x stop.sh`
7. **Expert instellingen (poorten, hostnaam, stage)**

### 🌐 Server
Je kunt ook de standaard PUBLIC_PORT_HTTPS (standaard `8443:`), PUBLIC_PORT_HTTP (standaard `8000:`), de HOSTNAME (standaard `localhost`) en STAGE (standaard `local`) aanpassen en opslaan.

Gebruik het [Ansible-playbook](/ansible/playbook.yml) om de applicatie te implementeren op een server. Raadpleeg de [README.md](/ansible/README.md) voor vereisten en installatie-instructies.
Bij het starten `make run`:

### 🪹 Voorbeeld `.env` bestand
- `make run PUBLIC_PORT_HTTPS=443:`: start op poort 443 en open op `https://localhost/`
- `make run HOSTNAME=test.localhost`: de server werkt op `https://test.localhost:8443/`

```bash
STATION_ID=1
```
Sla deze instellingen op in je `.env` bestand.

- `make .env PUBLIC_PORT_HTTPS=443: -B`: volgende `make run` zal standaard op `https://localhost/` starten.
- `make .env HOSTNAME=test.localhost`: de server start altijd op `https://test.localhost:8443/`

### 🌐 Server

Gebruik het [Ansible-playbook](/ansible/playbook.yml) om de applicatie te implementeren op een server. Raadpleeg de [README.md](/ansible/README.md) voor vereisten en installatie-instructies.

## 🦆 Projectstructuur

Expand All @@ -111,15 +125,15 @@ De backend is gebouwd met **FastAPI** en biedt de API-endpoints. Deze backend ha
### 🦢 API Endpoints

- **`/api/detections`**: Geeft recente vogelwaarnemingen van het afgelopen uur terug.
- **`/api/status`**: Geeft de status van het BirdWeather-station terug (online/offline).
- **`/api/top25`**: Retourneert de top 25 van meest waargenomen vogelsoorten op dit BirdWeather-station.

## 🔒 HTTPS-Portal

De setup maakt gebruik van [https-portal](https://github.com/SteveLTN/https-portal) in de Docker Compose-setup. HTTPS-Portal is een volledig geautomatiseerde HTTPS-server, aangedreven door Nginx, Let's Encrypt en Docker. Het vereenvoudigt het verkrijgen en vernieuwen van SSL-certificaten voor je applicatie.

## 🕊️ Inspiratie

Dit project is geïnspireerd door het <luistervink.nl>-project, dat zich richt op het monitoren en analyseren van vogelgeluiden. vogel-spotter bouwt voort op dat idee door waarnemingen van BirdWeather-stations te integreren in een gebruiksvriendelijke webapplicatie.
Dit project is geïnspireerd door het [luistervink.nl](https://www.luistervink.nl) project, dat zich richt op het monitoren en analyseren van vogelgeluiden. vogel-spotter bouwt voort op dat idee door waarnemingen van BirdWeather-stations te integreren in een gebruiksvriendelijke webapplicatie.

## 🐦 Licentie

Expand All @@ -131,7 +145,6 @@ Dit project is gelicentieerd onder de **MIT-licentie**. Zie het bestand [LICENSE

- **Dagelijkse top 10**: Voeg een lijst toe met de 10 meest waargenomen vogels van vandaag.
- **Maandelijkse statistieken**: Toon het aantal waarnemingen per vogelsoort gedurende een maand.
- **Top 25 aller tijden**: Voeg een overzicht toe van de 25 meest gespotte vogels sinds het begin van de registratie.

---

Expand All @@ -148,7 +161,6 @@ Dit project is gelicentieerd onder de **MIT-licentie**. Zie het bestand [LICENSE
- [▲ Vercel](#-vercel)
- [💻 Locally](#-locally)
- [🌐 Server](#-server)
- [🪹 Example .env file](#-example-env-file)
- [🦆 Project Structure](#-project-structure)
- [🦚 Frontend](#-frontend)
- [🦢 Backend](#-backend)
Expand All @@ -165,7 +177,7 @@ The goal is to provide bird enthusiasts with a simple platform to track bird act
## 🐤 Features

- Display recent bird sightings from the past hour.
- Show the status of the BirdWeather station (online/offline).
- Display of the top 25 most observed bird species at this BirdWeather station.
- Responsive design suitable for various screen sizes.
- Support for dark mode for use in low-light environments.
- Includes a refresh button for quick updates.
Expand Down Expand Up @@ -195,27 +207,31 @@ Don't forget to add the environment variable to the setup. Refer to the [Vercel
cd vogel-spotter
```

2. **Run the application and follow the instructions**:
2. **Generate an `.env` file with the `STATION_ID`**:

```bash
./run.sh
make .env STATION_ID=XXX -B
```

*If the script does not have execution permissions:* `chmod +x run.sh`
*Replace XXX with the number of your station ID.

3. **Open your browser** and navigate to:
3. **Run the application and follow the instructions**:

```bash
https://$HOSTNAME.local
make run
```

4. **Stop the application**
4. **Open your browser** and navigate to:

```bash
./stop.sh
https://localhost:8443
```

*If the script does not have execution permissions:* `chmod +x stop.sh`
5. **Stop the application**

```bash
make stop
```

### 🌐 Server

Expand Down Expand Up @@ -245,15 +261,15 @@ The backend is built with **FastAPI** and provides the API endpoints. This backe
### 🐓 API Endpoints

- **`/api/detections`**: Returns recent bird sightings from the past hour.
- **`/api/status`**: Returns the status of the BirdWeather station (online/offline).
- **`/api/top25`**: Returns the top 25 most observed bird species at this BirdWeather station.

## 🔒 HTTPS-Portal

The setup uses [https-portal](https://github.com/SteveLTN/https-portal) in the Docker Compose setup. HTTPS-Portal is a fully automated HTTPS server powered by Nginx, Let's Encrypt, and Docker. It simplifies the process of obtaining and renewing SSL certificates for your application.

## 🕊️ Inspiration

This project is inspired by the <luistervink.nl> project, which focuses on monitoring and analyzing bird sounds. vogel-spotter builds on that idea by integrating observations from BirdWeather stations into a user-friendly web application.
This project is inspired by the [luistervink.nl](https://www.luistervink.nl) project, which focuses on monitoring and analyzing bird sounds. vogel-spotter builds on that idea by integrating observations from BirdWeather stations into a user-friendly web application.

## 🐦 License

Expand All @@ -265,4 +281,3 @@ This project is licensed under the **MIT license**. See the [LICENSE](LICENSE) f

- **Daily Top 10**: Add a list of the 10 most observed birds of today.
- **Monthly Statistics**: Show the number of observations per bird species over a month.
- **Top 25 All Time**: Add an overview of the 25 most spotted birds since the start of the registration.
18 changes: 9 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ services:
build:
context: .
dockerfile: Dockerfile
env_file:
- .env
environment:
STATION_ID: "${STATION_ID}"
volumes:
- ./src:/app
ports:
- '8000:8000'
# ports:
# - '8000:8000'
networks:
- vs_network

https-portal:
depends_on:
- app
image: steveltn/https-portal:1
image: docker.io/steveltn/https-portal:1
ports:
- '80:80'
- '443:443'
- "${PUBLIC_PORT_HTTP}80"
- "${PUBLIC_PORT_HTTPS}443"
environment:
DOMAINS: 'localhost -> http://app:8000'
STAGE: 'local'
DOMAINS: "${HOSTNAME} -> http://app:8000"
STAGE: "${STAGE}"
volumes:
- https-portal-data:/var/lib/https-portal
networks:
Expand Down
Loading