add dockerfile and gitea workflow
This commit is contained in:
46
.gitea/workflows/publish-docker.yml
Normal file
46
.gitea/workflows/publish-docker.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: Build and Publish Docker Image
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.br0tkasten.de
|
||||
username: ${{ gitea.actor }}
|
||||
# access token of the user triggering this action
|
||||
# in gitea -> user settings -> applications -> new token -> write:packages and write:repositories
|
||||
# then in gitea -> user settings -> actions -> secrets -> add new secret named "TOKEN" with the value of the access token.
|
||||
password: ${{ secrets.TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: git.br0tkasten.de/${{ gitea.repository }}
|
||||
flavor: |
|
||||
latest=true
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=semver,pattern={{version}}
|
||||
type=sha
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
__pycache__/
|
||||
venv/
|
||||
instance/
|
||||
webvars.db
|
||||
|
||||
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
|
||||
# Install curl for health check
|
||||
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy the requirements file into the container
|
||||
COPY requirements.txt .
|
||||
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy the current directory contents into the container at /app
|
||||
COPY . .
|
||||
|
||||
# Make port 80 available to the world outside this container
|
||||
EXPOSE 80
|
||||
|
||||
# Add health check
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD curl http://localhost || exit 1
|
||||
|
||||
# Run the application using Gunicorn
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:80", "--workers", "4", "wsgi:app"]
|
||||
68
README.md
68
README.md
@@ -0,0 +1,68 @@
|
||||
# WebVars
|
||||
|
||||
WebVars is a lightweight Flask application for storing and retrieving configuration variables. It supports namespacing by project and uses SQLite for persistence.
|
||||
|
||||
## Features
|
||||
|
||||
- **Simple API**: Get and set variables via HTTP GET requests.
|
||||
- **Namespacing**: Organize variables by namespace and project.
|
||||
- **Dockerized**: Ready to deploy with Docker and Docker Compose.
|
||||
|
||||
## API Usage
|
||||
|
||||
### Set a Variable
|
||||
To set a variable, make a GET request to the following pattern:
|
||||
`GET /<namespace>/<project>/<name>/<value>`
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
curl http://localhost:8080/dev/backend/api_key/secret123
|
||||
```
|
||||
|
||||
### Get a Variable
|
||||
To retrieve a variable, make a GET request to:
|
||||
`GET /<namespace>/<project>/<name>`
|
||||
|
||||
**Example:**
|
||||
```bash
|
||||
curl http://localhost:8080/dev/backend/api_key
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
### Using Docker Compose
|
||||
|
||||
The easiest way to run WebVars is with Docker Compose.
|
||||
|
||||
1. **Start the service:**
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
The service will be available at `http://localhost:8080`.
|
||||
|
||||
2. **Persistence:**
|
||||
The `docker-compose.yml` is configured to mount a local `webvars.db` file to `/app/webvars.db` inside the container. It is recommended to create this file before starting the container to ensure it is treated as a file, not a directory.
|
||||
|
||||
```bash
|
||||
touch webvars.db
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Using Docker CLI
|
||||
|
||||
You can also build and run the container manually.
|
||||
|
||||
1. **Build the image:**
|
||||
```bash
|
||||
docker build -t webvars .
|
||||
```
|
||||
|
||||
2. **Run the container:**
|
||||
```bash
|
||||
touch webvars.db
|
||||
docker run -d \
|
||||
-p 8080:80 \
|
||||
-v $(pwd)/webvars.db:/app/webvars.db \
|
||||
--name webvars \
|
||||
webvars
|
||||
```
|
||||
|
||||
2
app.py
2
app.py
@@ -31,6 +31,8 @@ def index(namespace,project,name,value):
|
||||
db.session.commit()
|
||||
|
||||
v = Webvar.query.filter(Webvar.namespace == namespace).filter(Webvar.project == project).filter(Webvar.name == name).first()
|
||||
if v is None:
|
||||
return "Not Found", '404', {'Content-Type': 'text/plain; charset=utf-8'}
|
||||
return v.value, '200', {'Content-Type': 'text/plain; charset=utf-8'}
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
11
docker-compose.yml
Normal file
11
docker-compose.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
services:
|
||||
webvars:
|
||||
build:
|
||||
context: .
|
||||
image: git.br0tkasten.de/br0tkasten/webvars:latest
|
||||
container_name: webvars
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./webvars.db:/app/webvars.db
|
||||
restart: unless-stopped
|
||||
Reference in New Issue
Block a user