Merge pull request #3 from overspend1/codex/fix-dockerfile-and-compose-for-meme-wrangler-dy6rbm
fix: support compose env overrides
This commit was merged in pull request #3.
This commit is contained in:
10
.ENV.example
Normal file
10
.ENV.example
Normal file
@@ -0,0 +1,10 @@
|
||||
# Sample environment for Meme Wrangler Docker stack.
|
||||
# Copy to `.ENV` and adjust secrets before deploying.
|
||||
TELEGRAM_BOT_TOKEN=
|
||||
OWNER_ID=0
|
||||
CHANNEL_ID=
|
||||
POSTGRES_DB=meme_wrangler
|
||||
POSTGRES_USER=meme
|
||||
POSTGRES_PASSWORD=meme
|
||||
MEMEBOT_BACKUP_DIR=/app/backups
|
||||
# MEMEBOT_BACKUP_PASSWORD_HASH=
|
||||
@@ -5,3 +5,4 @@ __pycache__
|
||||
backups
|
||||
.env
|
||||
.env.*
|
||||
.ENV
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
memes.db
|
||||
.env
|
||||
.env
|
||||
.ENV
|
||||
|
||||
@@ -29,6 +29,6 @@
|
||||
- Link issues or TODOs, flag breaking changes in bold, and include screenshots only when UI-facing Telegram copy changes.
|
||||
|
||||
## Deployment & Secret Tips
|
||||
- Keep `.env` out of version control; copy from `.env.example` and set `TELEGRAM_BOT_TOKEN`, `OWNER_ID`, `CHANNEL_ID`, `POSTGRES_*` credentials, and `DATABASE_URL` for local runs.
|
||||
- Keep `.ENV` (or `.env`) out of version control; copy from `.ENV.example` and set `TELEGRAM_BOT_TOKEN`, `OWNER_ID`, `CHANNEL_ID`, `POSTGRES_*` credentials, and `DATABASE_URL` for local runs.
|
||||
- Only override `MEMEBOT_BACKUP_PASSWORD_HASH` if you plan to replace the baked-in SHA-256 hash for backup commands.
|
||||
- Docker workflows mount backups in `./backups/` and keep the PostgreSQL cluster in the `pgdata` volume; prune carefully when resetting schedules. New memes automatically generate a fresh backup file in that directory.
|
||||
|
||||
@@ -37,8 +37,8 @@ sudo usermod -aG docker $USER
|
||||
Copy the example file and edit it:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
nano .env # or use any text editor
|
||||
cp .ENV.example .ENV
|
||||
nano .ENV # or use any text editor
|
||||
```
|
||||
|
||||
Fill in your actual values:
|
||||
@@ -49,6 +49,8 @@ CHANNEL_ID=@yourchannel
|
||||
POSTGRES_DB=meme_wrangler
|
||||
POSTGRES_USER=meme
|
||||
POSTGRES_PASSWORD=meme
|
||||
# Optional: adjust which env file Compose should read (defaults to .ENV)
|
||||
# COMPOSE_ENV_FILE=staging.env
|
||||
# Optional: hash (SHA-256) for replacing the baked-in backup secret
|
||||
# MEMEBOT_BACKUP_PASSWORD_HASH=<your_sha256_hash>
|
||||
# Optional: adjust DATABASE_URL for non-compose workflows
|
||||
@@ -58,7 +60,7 @@ POSTGRES_PASSWORD=meme
|
||||
### 2. Build and Run with Docker Compose (Easiest)
|
||||
|
||||
```bash
|
||||
# Build and start in background
|
||||
# Build and start in background (stack reads .ENV automatically)
|
||||
docker-compose up -d
|
||||
|
||||
# View logs
|
||||
@@ -73,6 +75,10 @@ docker-compose restart
|
||||
|
||||
That's it! Your bot is now running in Docker! 🎉
|
||||
|
||||
#### Deploying with Portainer Stacks
|
||||
|
||||
When launching the stack from Portainer, upload your `.ENV` file through the **Environment variables** tab—Portainer saves it beside the stack as `/data/compose/<stack-id>/.ENV`, which matches the default expected by `docker-compose.yml`. Only set `COMPOSE_ENV_FILE` if you deliberately use a different name.
|
||||
|
||||
## Alternative: Using Docker Commands Directly
|
||||
|
||||
### Build the Image
|
||||
@@ -152,9 +158,9 @@ ssh -i /path/to/ssh_key username@server_ip
|
||||
# Navigate to bot directory
|
||||
cd ~/meme-wrangler
|
||||
|
||||
# Create .env file
|
||||
cp .env.example .env
|
||||
nano .env # Fill in your credentials
|
||||
# Create .ENV file
|
||||
cp .ENV.example .ENV
|
||||
nano .ENV # Fill in your credentials
|
||||
|
||||
# Build and run
|
||||
docker-compose up -d
|
||||
@@ -308,8 +314,8 @@ scp -i /path/to/key -r \
|
||||
ssh -i /path/to/key username@server_ip
|
||||
cd ~/memebot
|
||||
|
||||
# Create .env file
|
||||
nano .env # Add your credentials
|
||||
# Create .ENV file
|
||||
nano .ENV # Add your credentials
|
||||
|
||||
# Run with Docker Compose
|
||||
docker-compose up -d
|
||||
|
||||
@@ -10,10 +10,10 @@ The easiest way to run the bot is using Docker:
|
||||
|
||||
1. **Set up environment variables:**
|
||||
```bash
|
||||
cp .env.example .env
|
||||
nano .env # Edit with your bot credentials
|
||||
cp .ENV.example .ENV
|
||||
nano .ENV # Edit with your bot credentials
|
||||
```
|
||||
The compose stack expects PostgreSQL credentials, so populate `POSTGRES_DB`, `POSTGRES_USER`, and `POSTGRES_PASSWORD` (defaults provided). Backups are protected by a built-in SHA-256 hash; optionally define `MEMEBOT_BACKUP_PASSWORD_HASH` to replace it.
|
||||
The compose file now looks for `.ENV` by default so Portainer and other orchestrators can supply secrets without additional flags. Copy `.ENV.example` to `.ENV`, then populate `TELEGRAM_BOT_TOKEN`, `OWNER_ID`, `CHANNEL_ID`, and the Postgres settings. You can still point the stack at a different file by exporting `COMPOSE_ENV_FILE` (e.g. `COMPOSE_ENV_FILE=staging.env docker compose up -d`). Backups are protected by a built-in SHA-256 hash; optionally define `MEMEBOT_BACKUP_PASSWORD_HASH` to replace it.
|
||||
|
||||
2. **Run with Docker Compose:**
|
||||
```bash
|
||||
@@ -25,6 +25,8 @@ The easiest way to run the bot is using Docker:
|
||||
docker-compose logs -f
|
||||
```
|
||||
|
||||
Deploying via Portainer? Upload your `.ENV` file under **Environment variables**—Portainer stores it beside the stack so the compose file picks it up automatically. Override `COMPOSE_ENV_FILE` only when you use a differently named file.
|
||||
|
||||
4. **Stop the bot:**
|
||||
```bash
|
||||
docker-compose down
|
||||
|
||||
22
deploy.sh
22
deploy.sh
@@ -26,16 +26,20 @@ if [ -z "$SERVER" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Step 1: Checking if .env file exists..."
|
||||
if [ ! -f ".env" ]; then
|
||||
echo "Error: .env file not found!"
|
||||
echo "Please create .env file with your credentials:"
|
||||
echo " cp .env.example .env"
|
||||
echo " nano .env"
|
||||
ENV_FILE=".ENV"
|
||||
echo "Step 1: Checking for environment file (.ENV or .env)..."
|
||||
if [ -f "$ENV_FILE" ]; then
|
||||
echo "✓ .ENV file found"
|
||||
elif [ -f ".env" ]; then
|
||||
ENV_FILE=".env"
|
||||
echo "✓ .env file found"
|
||||
else
|
||||
echo "Error: No environment file found!"
|
||||
echo "Please create one with your credentials:"
|
||||
echo " cp .ENV.example .ENV"
|
||||
echo " nano .ENV"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ .env file found"
|
||||
echo ""
|
||||
|
||||
echo "Step 2: Uploading files to server..."
|
||||
@@ -45,7 +49,7 @@ scp -i "$SSH_KEY" \
|
||||
docker-compose.yml \
|
||||
bot.py \
|
||||
requirements.txt \
|
||||
.env \
|
||||
"$ENV_FILE" \
|
||||
"$SERVER":~/meme-wrangler/
|
||||
|
||||
echo "✓ Files uploaded"
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
x-env-file: &compose_env_file ${COMPOSE_ENV_FILE:-.ENV}
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15
|
||||
container_name: meme-wrangler-db
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env
|
||||
- *compose_env_file
|
||||
environment:
|
||||
- POSTGRES_DB=${POSTGRES_DB:-meme_wrangler}
|
||||
- POSTGRES_USER=${POSTGRES_USER:-meme}
|
||||
@@ -26,7 +28,7 @@ services:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
env_file:
|
||||
- .env
|
||||
- *compose_env_file
|
||||
environment:
|
||||
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN:-}
|
||||
- OWNER_ID=${OWNER_ID:-}
|
||||
@@ -34,8 +36,8 @@ services:
|
||||
- POSTGRES_DB=${POSTGRES_DB:-meme_wrangler}
|
||||
- POSTGRES_USER=${POSTGRES_USER:-meme}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-meme}
|
||||
- DATABASE_URL=postgresql://${POSTGRES_USER:-meme}:${POSTGRES_PASSWORD:-meme}@postgres:5432/${POSTGRES_DB:-meme_wrangler}
|
||||
- MEMEBOT_BACKUP_DIR=/app/backups
|
||||
- DATABASE_URL=${DATABASE_URL:-postgresql://${POSTGRES_USER:-meme}:${POSTGRES_PASSWORD:-meme}@postgres:5432/${POSTGRES_DB:-meme_wrangler}}
|
||||
- MEMEBOT_BACKUP_DIR=${MEMEBOT_BACKUP_DIR:-/app/backups}
|
||||
volumes:
|
||||
- ./backups:/app/backups
|
||||
logging:
|
||||
|
||||
Reference in New Issue
Block a user