From b35141d1c7e046caa333b334310845d28d582a18 Mon Sep 17 00:00:00 2001 From: pauli Date: Wed, 20 May 2026 21:47:48 +0200 Subject: [PATCH] Add Dockerfile, compose, env example and CI deploy workflow --- .env.example | 11 ++++++++ .github/workflows/deploy.yml | 55 ++++++++++++++++++++++++++++++++++++ .gitignore | 7 +++++ Dockerfile | 17 +++++++++++ docker-compose.yml | 11 ++++++++ 5 files changed, 101 insertions(+) create mode 100644 .env.example create mode 100644 .github/workflows/deploy.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..6015c13 --- /dev/null +++ b/.env.example @@ -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 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..b06de41 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc6c78e --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.env +__pycache__/ +.venv/ +*.pyc +dist/ +build/ +/.pytest_cache diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..356373c --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3bfb8f9 --- /dev/null +++ b/docker-compose.yml @@ -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