This commit is contained in:
Boyan 2024-12-07 23:12:56 +01:00
parent b82118f8b2
commit 9aafc9b37c
5 changed files with 60 additions and 3 deletions

18
Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM python:3.9-slim
RUN apt-get update && apt-get install -y \
sqlite3 \
libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY src /app/src
COPY src/manage_users.py /app/src/
RUN python /app/src/manage_users.py init
ENV FLASK_APP=src/app.py
ENV FLASK_RUN_HOST=0.0.0.0
EXPOSE 5000
CMD ["flask", "run"]

View File

@ -16,7 +16,7 @@ git clone https://git.confest.im/boyan_k/shortn
pip install -r requirements.txt pip install -r requirements.txt
``` ```
## Usage ## Usage (no docker)
```bash ```bash
python manage_users.py init # to create the database python manage_users.py init # to create the database
python manage_users.py add # to add a user python manage_users.py add # to add a user
@ -31,9 +31,24 @@ python manage_users.py remove --username <username> # to remove a user
python app.py python app.py
``` ```
## Usage (docker)
This will init the database and create a user with the username `admin` and password `admin`.
```bash
docker compose up -d # remove -d for foreground
```
### Users
```bash
sudo docker exec -it shortn python src/manage_users.py add
sudo docker exec -it shortn python src/manage_users.py list
sudo docker exec -it shortn python src/manage_users.py remove --username <username>
```
> [!NOTE] The database is **ephemeral** and will be lost when the container is removed. That is intentional.
## TODOs ## TODOs
- [x] basic UI (to add links) - [x] basic UI (to add links)
- [x] basic auth for UI - [x] basic auth for UI
- [x] sqlite3 to store links - [x] sqlite3 to store links
- [x] responsive? (sorta) - [x] responsive? (sorta)
- [ ] dockerize - [x] dockerize

13
docker-compose.yml Normal file
View File

@ -0,0 +1,13 @@
services:
shortn:
build:
context: .
container_name: shortn
ports:
- "5000:5000"
volumes:
- ./src:/app/src
environment:
FLASK_APP: src/app.py
FLASK_RUN_HOST: 0.0.0.0
command: sh -c "python /app/src/manage_users.py init && flask run"

7
requirements.txt Normal file
View File

@ -0,0 +1,7 @@
blinker==1.9.0
click==8.1.7
Flask==3.1.0
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==3.0.2
Werkzeug==3.1.3

View File

@ -95,4 +95,8 @@ def main():
print("Invalid command. Use --help for usage information.") print("Invalid command. Use --help for usage information.")
if __name__ == '__main__': if __name__ == '__main__':
try:
main() main()
except KeyboardInterrupt:
sys.exit(1)