Add Dockerfile, compose, env example and CI deploy workflow

This commit is contained in:
pauli 2026-05-20 21:47:48 +02:00
parent add2e6aa46
commit b35141d1c7
5 changed files with 101 additions and 0 deletions

11
.env.example Normal file
View File

@ -0,0 +1,11 @@
# Copy this file to .env and fill in secrets. Do NOT commit .env
# Example env file for local deployment
PORT=8501
IMAGE_NAME=wm2026_simulator:latest
# Set a password used by your deployment or reverse proxy
STREAMLIT_PASSWORD=changeme
# Optional: remote deploy settings (used by CI if provided as secrets)
DEPLOY_HOST=example.com
DEPLOY_USER=deploy
DEPLOY_PASSWORD=supersecret

55
.github/workflows/deploy.yml vendored Normal file
View File

@ -0,0 +1,55 @@
name: Build and Deploy
on:
push:
branches: [ main, master ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
optional-deploy:
runs-on: ubuntu-latest
needs: build-and-push
if: ${{ secrets.DEPLOY_HOST && secrets.DEPLOY_USER && secrets.DEPLOY_PASSWORD }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install sshpass
run: sudo apt-get update && sudo apt-get install -y sshpass
- name: Copy files and restart remote compose
env:
HOST: ${{ secrets.DEPLOY_HOST }}
USER: ${{ secrets.DEPLOY_USER }}
PASS: ${{ secrets.DEPLOY_PASSWORD }}
IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
run: |
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no $USER@$HOST "mkdir -p ~/wm2026_deploy && exit"
sshpass -p "$PASS" scp -o StrictHostKeyChecking=no docker-compose.yml $USER@$HOST:~/wm2026_deploy/
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no $USER@$HOST "cd ~/wm2026_deploy && docker pull $IMAGE || true && docker-compose up -d --build"

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.env
__pycache__/
.venv/
*.pyc
dist/
build/
/.pytest_cache

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=8501
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Copy application files
COPY . /app
EXPOSE ${PORT}
CMD ["streamlit", "run", "app.py", "--server.port", "${PORT}", "--server.address", "0.0.0.0"]

11
docker-compose.yml Normal file
View File

@ -0,0 +1,11 @@
version: '3.8'
services:
app:
build: .
image: ${IMAGE_NAME:-wm2026_simulator:latest}
ports:
- "${PORT:-8501}:8501"
environment:
- PORT=${PORT:-8501}
- STREAMLIT_PASSWORD=${STREAMLIT_PASSWORD}
restart: unless-stopped