From 6a1a78cb2a5adcae12e64c7b4e8ba8b2ba391bdf Mon Sep 17 00:00:00 2001 From: agessaman Date: Sat, 17 Jan 2026 10:40:25 -0800 Subject: [PATCH] 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. --- .env.example | 12 ++++++++++++ docker-compose.yml | 15 +++++++++------ docker-setup.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d60cc16 --- /dev/null +++ b/.env.example @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index e0416bf..2ecba03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/docker-setup.sh b/docker-setup.sh index 68179fc..245cbee 100755 --- a/docker-setup.sh +++ b/docker-setup.sh @@ -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..."