chore: Update Docker configuration for improved image management

- Modified docker-compose.yml to support using a pre-built image from GitHub Container Registry, with automatic tagging based on the current git branch.
- Enhanced docker-setup.sh to detect the current git branch and set the Docker image tag accordingly, creating or updating the .env file with the appropriate configuration.
This commit is contained in:
agessaman
2026-01-17 10:40:25 -08:00
parent 458c920c2b
commit 6a1a78cb2a
3 changed files with 66 additions and 6 deletions

12
.env.example Normal file
View File

@@ -0,0 +1,12 @@
# Docker image configuration
# This file is auto-generated by docker-setup.sh based on your current git branch
# You can manually override these values if needed
# Docker image registry (default: ghcr.io/agessaman/meshcore-bot)
DOCKER_IMAGE_REGISTRY=ghcr.io/agessaman/meshcore-bot
# Docker image tag (auto-detected from git branch)
# - main/master branches -> latest
# - dev branch -> dev
# - other branches -> branch name (with / replaced by -)
DOCKER_IMAGE_TAG=latest

View File

@@ -1,11 +1,14 @@
services:
meshcore-bot:
build:
context: .
dockerfile: Dockerfile
# Image will be built locally (not pulled from registry)
# To avoid pull warnings, run: docker compose build
image: meshcore-bot:latest
# Option 1: Build locally - uncomment to build from source
# build:
# context: .
# dockerfile: Dockerfile
# Option 2: Use pre-built image from GitHub Container Registry (default)
# Image tag is automatically set based on current git branch via .env file
# Set DOCKER_IMAGE_REGISTRY in .env to override (default: ghcr.io/agessaman/meshcore-bot)
image: ${DOCKER_IMAGE_REGISTRY:-ghcr.io/agessaman/meshcore-bot}:${DOCKER_IMAGE_TAG:-latest}
container_name: meshcore-bot
restart: unless-stopped

View File

@@ -237,6 +237,51 @@ else
echo " - Or use TCP/BLE connection instead"
fi
# Detect git branch and set Docker image tag
echo ""
echo "Detecting git branch for Docker image tag..."
# Try to get current branch name
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
DOCKER_IMAGE_TAG="latest"
DOCKER_IMAGE_REGISTRY="ghcr.io/agessaman/meshcore-bot"
if [ -n "$GIT_BRANCH" ]; then
# Map branch names to image tags
case "$GIT_BRANCH" in
main|master)
DOCKER_IMAGE_TAG="latest"
;;
*)
# Use branch name as tag (e.g., dev -> dev, feature/xyz -> feature-xyz)
DOCKER_IMAGE_TAG=$(echo "$GIT_BRANCH" | sed 's/[\/_]/-/g')
;;
esac
echo " ✓ Detected branch: $GIT_BRANCH -> image tag: $DOCKER_IMAGE_TAG"
else
echo " ⚠️ Not a git repository or branch detection failed, using 'latest'"
fi
# Create or update .env file for docker-compose
ENV_FILE=".env"
if [ ! -f "$ENV_FILE" ] || ! grep -q "^DOCKER_IMAGE_TAG=" "$ENV_FILE" 2>/dev/null; then
echo "" >> "$ENV_FILE"
echo "# Docker image configuration (auto-generated by docker-setup.sh)" >> "$ENV_FILE"
echo "DOCKER_IMAGE_REGISTRY=$DOCKER_IMAGE_REGISTRY" >> "$ENV_FILE"
echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG" >> "$ENV_FILE"
echo " ✓ Created/updated .env file with image tag: $DOCKER_IMAGE_TAG"
else
# Update existing .env file
if [[ "$PLATFORM" == "Darwin" ]]; then
sed -i '' "s|^DOCKER_IMAGE_TAG=.*|DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG|" "$ENV_FILE"
sed -i '' "s|^DOCKER_IMAGE_REGISTRY=.*|DOCKER_IMAGE_REGISTRY=$DOCKER_IMAGE_REGISTRY|" "$ENV_FILE"
else
sed -i "s|^DOCKER_IMAGE_TAG=.*|DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG|" "$ENV_FILE"
sed -i "s|^DOCKER_IMAGE_REGISTRY=.*|DOCKER_IMAGE_REGISTRY=$DOCKER_IMAGE_REGISTRY|" "$ENV_FILE"
fi
echo " ✓ Updated .env file with image tag: $DOCKER_IMAGE_TAG"
fi
# Set permissions (container runs as UID 1000)
echo ""
echo "Setting permissions..."