Skip to content

Commit

Permalink
Several changes, revealed during smoke test on final stages
Browse files Browse the repository at this point in the history
+ documentation start
  • Loading branch information
leechwort committed Feb 4, 2024
1 parent be74e5e commit 94db087
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 148 deletions.
146 changes: 8 additions & 138 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,146 +9,16 @@ create a system that any maker space in the world can easily set up for
its own use. The system is completely open-source, including the backend,
reader firmware, and PCB schematics.

## Setup on Raspberry Pi OS
Simplest way to bring PRISMO to your life is to use Raspberry Pi and graphical
desktop environment. Here is full description how to do this: [instruction](docs/rpi_installation_instructions.md)

## Config handling
By default, PRISMO searches for a file named `config_default.json` inside
the `/app` directory. This is suitable for development purposes, but for
production deployments, you should specify your own configuration file and
pass its path as the `PRISMO_CONFIG` environment variable. When running
PRISMO in a Docker container, this path is specified in the `Dockerfile`
like so:
## Reader hardware build

```commandline
ENV PRISMO_CONFIG=/app/external/config_docker.json
```
In this example, the path `app/external/config_docker.json` is relative to
the container's internal directory and mapped from an external directory
(see the following paragraph for details).
Readers itself has their own repository and building instructions,
follow [repo](https://github.com/hacklabkyiv/prismo-reader) to build your own beautiful reader.

## Running in `Docker`
## Reader software flashing

Running PRISMO in a separate Docker container offers several advantages. It
isolates data and ensures a well-defined environment for smooth operation.
You can verify everything is ready for Docker deployment by running the
following command:
```commandline
$ docker build --no-cache -t prismo-app .
```
This command build a container and sets all environment variables from dockerfile.
```commandline
$ docker run --name=prismo-app -p 80:5000 --restart always --detach -v "$(pwd)/data/:/app/external/" prismo-app
```
This command runs the newly built container and starts the server on port 80. Note that on some systems, port 80 might be
unavailable for non-privileged users. For development purposes, you can use
the alternative mapping \`5000\:5000\` instead\.
As shown in the command, the `-v "</span>(pwd)/data/:/app/external/"`
option mounts an external volume where you should store your `database.db`
and `config_docker.json` files. This volume persists data and configuration
outside the container, ensuring they are not lost even if the container is
deleted.
Flashing reader is performed from Raspberry Pi itself...(to be continued)

**Additional Notes:**

- Remember to replace the placeholder values for environment variables like `DATABASE_URL` and `SECRET_KEY` with your actual settings in the example commands.

## Installation by docker

- Install docker on the host machine.
Check [the tutorial for Raspberry Pi 4](https://github.com/codingforentrepreneurs/Pi-Awesome/blob/main/how-tos/Docker%20%26%20Docker%20Compose%20on%20Raspberry%20Pi.md)
- Create a folder `data` - the folder use for keep all persistent data, like a database.
- Run docker container:

```bash
docker run --name=prismo-app -p 80:5000 --restart always --detach -v "$(pwd)/data/:/app/external/" hacklabkyiv/prismo-app:0.1.7
```

Add docker to autostart:

```bash
sudo systemctl enable docker
```

The application ready to work and available on `http://localhost:5000`

### The reader firmware

The reader is a device which connected to the network and read RFID cards. The reader firmware is stored in
the `prismo-reader` [repository](https://github.com/hacklabkyiv/prismo-reader/tree/micropython_pn532).

## Development

### Preconditions

- Python 3.10+ with pip
- git
- supervisor(optional)

### Step-by-step installation

1. Clone the repository:

```sh
git clone git@github.com:hacklabkyiv/prismo.git
```
or by https:
```sh
git clone https://github.com/hacklabkyiv/prismo.git
```

2. Install virtualenv in project's directory:
```sh
$ python3 -m venv ./virtualenv
```
3. Activate virtual environment
```
source ./virtualenv/bin/activate
```
4. Install required packages:
```sh
pip3 install -r requirements.txt
```
5. Run for debugging and development: (it will reload app on code changes and enable debug mode)
```sh
export FLASK_APP=application.py
flask run --debug
```
if you want to autorestart you app on Flask changes, you can do `export FLASK_DEBUG=1`. In case of `Import Error` run `pip3 install --upgrade watchdog`.
By default, this should be run by Prismo admin process, but for debugging purpose you should run this commands by
yourself.
## Database
All information about the database is stored in [doc/database.md](docs/database.md) file.
## API
The docs for API is stored in [docs/api.md](docs/api.md) file.
## Slack
Slack integration works with slack bot. You need to create slack bot in your slack workspace and get token for it.
Scope:
- chat:write
- files:write
- incoming-webhook
## Build final docker image and deployment
The main target platform is `linux/arm64/v8` (Raspberry Pi 4). To build docker image for this platform you should use
buildx.
Execute `docker login` with hacklabkyiv credentials.
Execute this commands in the root directory of the project:
```
docker buildx create --use
docker buildx build --platform linux/arm64/v8 -t hacklabkyiv/prismo-app:<version> --push .
```
File renamed without changes.
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ services:
build: .
environment:
HOST_HOSTNAME: $HOST_HOSTNAME
HOST_WIFI_SSID: $HOST_WIFI_SSID
HOST_WIFI_PASSWORD: $HOST_WIFI_PASSWORD
container_name: prismo-app
restart: always
ports:
- 5000:5000
- 80:5000
privileged: true
volumes:
- "./data/:/app/external/"
- /run/udev:/run/udev:ro
Expand Down
2 changes: 0 additions & 2 deletions docker_run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

export HOST_HOSTNAME=$(hostnamectl hostname)
export HOST_WIFI_SSID=$(nmcli -s device wifi show-password | grep "SSID"| cut -d" " -f2)
export HOST_WIFI_PASSWORD=$(nmcli -s device wifi show-password | grep "Password"| cut -d" " -f2)

docker compose up
80 changes: 80 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Developers info
====================================

### Preconditions

- Python 3.10+ with pip
- git
- supervisor(optional)

### Step-by-step installation

1. Clone the repository:

```sh
git clone git@github.com:hacklabkyiv/prismo.git
```
or by https:
```sh
git clone https://github.com/hacklabkyiv/prismo.git
```

2. Install virtualenv in project's directory:
```sh
$ python3 -m venv ./virtualenv
```
3. Activate virtual environment
```
source ./virtualenv/bin/activate
```
4. Install required packages:
```sh
pip3 install -r requirements.txt
```
5. Run for debugging and development: (it will reload app on code changes and enable debug mode)
```sh
export FLASK_APP=application.py
flask run --debug
```
if you want to autorestart you app on Flask changes, you can do `export FLASK_DEBUG=1`. In case of `Import Error` run `pip3 install --upgrade watchdog`.
By default, this should be run by Prismo admin process, but for debugging purpose you should run this commands by
yourself.
## Config handling
By default, PRISMO searches for a file named `config_default.json` inside
the `/app` directory. This is suitable for development purposes, but for
production deployments, you should specify your own configuration file and
pass its path as the `PRISMO_CONFIG` environment variable. When running
PRISMO in a Docker container, this path is specified in the `Dockerfile`
like so:
```commandline
ENV PRISMO_CONFIG=/app/external/config_docker.json
```
In this example, the path `app/external/config_docker.json` is relative to
the container's internal directory and mapped from an external directory
(see the following paragraph for details).

## Database

All information about the database is stored in [doc/database.md](docs/database.md) file.

## API

The docs for API is stored in [docs/api.md](docs/api.md) file.

## Slack

Slack integration works with slack bot. You need to create slack bot in your slack workspace and get token for it.
Scope:

- chat:write
- files:write
- incoming-webhook
27 changes: 23 additions & 4 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
Docker tips and tricks
================================================

Some problems, which can occurs during work with docker.
## Running in `Docker`

Use official documentaion for installation on desktop.
https://docs.docker.com/engine/install/ubuntu/
Running PRISMO in a separate Docker container offers several advantages. It
isolates data and ensures a well-defined environment for smooth operation.
You can verify everything is ready for Docker deployment by running the
following command:
```commandline
$ docker build --no-cache -t prismo-app .
```
This command build a container and sets all environment variables from dockerfile.
```commandline
$ docker run --name=prismo-app -p 80:5000 --restart always --detach -v "$(pwd)/data/:/app/external/" prismo-app
```
This command runs the newly built container and starts the server on port 80. Note that on some systems, port 80 might be
unavailable for non-privileged users. For development purposes, you can use
the alternative mapping \`5000\:5000\` instead\.
As shown in the command, the `-v "</span>(pwd)/data/:/app/external/"`
option mounts an external volume where you should store your `database.db`
and `config_docker.json` files. This volume persists data and configuration
outside the container, ensuring they are not lost even if the container is
deleted.

To be continued....:)
**Additional Notes:**

- Remember to replace the placeholder values for environment variables like `DATABASE_URL` and `SECRET_KEY` with your actual settings in the example commands.
Binary file added docs/images/customization_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions docs/rpi_installation_instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Installing PRISMO Access System on Raspberry Pi OS
==================================================
## Prerequisites:

* Raspberry Pi device
* Raspberry Pi Imager tool(https://www.raspberrypi.com/software/)
* Internet connection

## Raspberry Pi OS installation

Install Raspberry Pi OS as usual:
* Use the Pi Imager tool to flash Raspberry Pi OS onto a microSD card.
* During the initial setup, press "Edit settings" in the "Use OS customization?" dialog.
* Set the hostname to "prismo" (or your preferred hostname).
* Configure the Wi-Fi settings correctly.

![Customization settings](images/customization_settings.png "customization settings")


* Insert the microSD card and power on the Raspberry Pi.

## Install Docker and Docker Compose:

* Open a terminal window and run the following command:
```commandline
curl -sSL https://get.docker.com | sh
```

* Add the current user to the docker group:
```commandline
sudo usermod -aG docker ${USER}
```

* Reboot the Raspberry Pi:
```commandline
sudo reboot
```

* Clone the PRISMO Repository and run docker script:

```commandline
git clone https://github.com/hacklabkyiv/prismo.git
cd prismo
./docker-run.sh
```


* Access PRISMO: Open a web browser on your computer or mobile device.
Navigate to the address `prismo.local` (or the hostname you set).
You should see the PRISMO entry screen.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ slack-bolt
# Used by reader flasher script
intelhex
pyserial
adafruit-ampy
rshell
esptool

0 comments on commit 94db087

Please sign in to comment.