From 6ba5cc6815d319c5e8da3b5a7b1dfc5df95a4134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Fr=C4=85tczak?= Date: Tue, 14 Nov 2023 23:50:10 +0100 Subject: [PATCH] create the bootstrap script and update the README.md --- Dockerfile | 10 ---------- README.md | 22 ++++++++++++++++++++-- bootstrap.sh | 5 ----- default.env | 3 ++- scripts/install.sh | 31 +++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 18 deletions(-) delete mode 100644 Dockerfile delete mode 100644 bootstrap.sh create mode 100644 scripts/install.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 38d8f37..0000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder - -WORKDIR /app - -COPY requirements.txt /app -RUN pip3 install -r requirements.txt - -COPY . /app - -CMD ["python", "main.py"] \ No newline at end of file diff --git a/README.md b/README.md index 4e8e79e..ee4055e 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,28 @@ Bluetooth control app for Wahoo Headwind. ## Usage -To run the flask app: +To run the flask app for development and testing: ```bash +git clone https://teapot.octopusx.de/accidentallycompetent/bluewind.git +cd bluewind +python3 -m venv .venv +source .venv/bin/activate +python3 -m pip install --upgrade pip +pip3 install -r requirements.txt export FLASK_ADDRESS='' -flask --app api run --host=0.0.0.0 +python3 main.py +``` + +To run the flask app in a permanent deployment: +```bash +git clone https://teapot.octopusx.de/accidentallycompetent/bluewind.git +cd bluewind +python3 -m venv .venv +source .venv/bin/activate +python3 -m pip install --upgrade pip +pip3 install -r requirements.txt +cp default.env .env # modify your .env file! +sudo /bin/bash scripts/install.sh # will install and start+enable the systemd service for you ``` ## Support diff --git a/bootstrap.sh b/bootstrap.sh deleted file mode 100644 index cc759ad..0000000 --- a/bootstrap.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -python3 -m venv .venv -source .venv/bin/activate -python3 -m pip install --upgrade pip -pip3 install -r requirements.txt \ No newline at end of file diff --git a/default.env b/default.env index f627499..eac4c0d 100644 --- a/default.env +++ b/default.env @@ -1 +1,2 @@ -FLASK_ADDRESS='F2:B3:F7:6A:24:48' \ No newline at end of file +FLASK_ADDRESS='F2:B3:F7:6A:24:48' +FLASK_URL='127.0.0.1:5000' \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..ddece06 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Export the environment variables +if [ ! -f ".env" ]; then + echo "The .env file does not exist, please make a copy of default.env into .env and adjust its contents before proceeding." + exit 1 +fi +export $(cat .env) + +# Create new systemd file +touch /etc/systemd/system/bluewind.service + +# Fill in the systemd file +echo -e """[Unit] +Description=Flask Application +After=multi-user.target + +[Service] +Type=simple +ExecStart=$(pwd)/.venv/bin/python3 $(pwd)/main.py +Restart=always +Environment="FLASK_ADDRESS=$(echo $FLASK_ADDRESS)" +Environment="FLASK_URL=$(echo $FLASK_URL)" + +[Install] +WantedBy=multi-user.target +""" > /etc/systemd/system/bluewind.service + +# Reload systemd unit, start and enable the service +systemctl daemon-reload +systemctl enable bluewind.service +systemctl start bluewind.service \ No newline at end of file