Procházet zdrojové kódy

Merge main: Docker image tag from current branch

tuanchris před 5 měsíci
rodič
revize
8926298e66
3 změnil soubory, kde provedl 31 přidání a 8 odebrání
  1. 13 2
      .github/workflows/docker-publish.yml
  2. 2 2
      docker-compose.yml
  3. 16 4
      dw

+ 13 - 2
.github/workflows/docker-publish.yml

@@ -10,6 +10,15 @@ on:
       - 'requirements.txt'
       - 'VERSION'
       - '**.py'
+  pull_request:
+    branches: [ "main" ]
+    paths:
+      - 'Dockerfile'
+      - 'frontend/Dockerfile'
+      - 'frontend/**'
+      - 'requirements.txt'
+      - 'VERSION'
+      - '**.py'
   # Allow manual trigger on any branch
   workflow_dispatch:
     inputs:
@@ -23,6 +32,7 @@ env:
 
 jobs:
   build-backend:
+    if: github.event_name != 'pull_request' || github.actor == 'tuanchris'
     runs-on: ubuntu-latest
     permissions:
       contents: read
@@ -53,7 +63,7 @@ jobs:
         uses: docker/build-push-action@v5
         with:
           context: .
-          push: true
+          push: ${{ github.event_name != 'pull_request' }}
           tags: ${{ steps.meta.outputs.tags }}
           labels: ${{ steps.meta.outputs.labels }}
           platforms: linux/amd64,linux/arm64
@@ -61,6 +71,7 @@ jobs:
           cache-to: type=gha,mode=max,scope=backend
 
   build-frontend:
+    if: github.event_name != 'pull_request' || github.actor == 'tuanchris'
     runs-on: ubuntu-latest
     permissions:
       contents: read
@@ -92,7 +103,7 @@ jobs:
         with:
           context: ./frontend
           file: ./frontend/Dockerfile
-          push: true
+          push: ${{ github.event_name != 'pull_request' }}
           tags: ${{ steps.meta.outputs.tags }}
           labels: ${{ steps.meta.outputs.labels }}
           platforms: linux/amd64,linux/arm64

+ 2 - 2
docker-compose.yml

@@ -3,7 +3,7 @@ services:
     build:
       context: ./frontend
       dockerfile: Dockerfile
-    image: ghcr.io/tuanchris/dune-weaver-frontend:main
+    image: ghcr.io/tuanchris/dune-weaver-frontend:${IMAGE_TAG:-main}
     restart: always
     ports:
       - "${FRONTEND_PORT:-80}:80"
@@ -15,7 +15,7 @@ services:
 
   backend:
     build: .
-    image: ghcr.io/tuanchris/dune-weaver:main
+    image: ghcr.io/tuanchris/dune-weaver:${IMAGE_TAG:-main}
     restart: always
     # Pin motion-critical backend to cores 0-2 (Raspberry Pi 4/5 has cores 0-3)
     # This prevents CPU contention from touch app blocking I/O calls

+ 16 - 4
dw

@@ -46,6 +46,13 @@ is_docker_mode() {
     [[ -f "$INSTALL_DIR/docker-compose.yml" ]] && command -v docker &> /dev/null
 }
 
+# Set IMAGE_TAG from current git branch (e.g. feature/foo -> feature-foo)
+set_image_tag() {
+    local branch
+    branch=$(git -C "$INSTALL_DIR" rev-parse --abbrev-ref HEAD)
+    export IMAGE_TAG="${branch//\//-}"
+}
+
 INSTALL_DIR=$(find_install_dir)
 
 # Check if installed
@@ -87,7 +94,8 @@ cmd_start() {
     cd "$INSTALL_DIR"
 
     if is_docker_mode; then
-        sudo docker compose up -d
+        set_image_tag
+        sudo -E docker compose up -d
     else
         sudo systemctl start dune-weaver
     fi
@@ -115,7 +123,8 @@ cmd_restart() {
     cd "$INSTALL_DIR"
 
     if is_docker_mode; then
-        sudo docker compose restart
+        set_image_tag
+        sudo -E docker compose restart
     else
         sudo systemctl restart dune-weaver
     fi
@@ -144,14 +153,17 @@ cmd_update() {
     fi
 
     if is_docker_mode; then
+        set_image_tag
+        echo -e "Image tag: ${BLUE}${IMAGE_TAG}${NC}"
+
         echo "Pulling latest Docker image..."
-        sudo docker compose pull
+        sudo -E docker compose pull
 
         echo "Stopping current container..."
         sudo docker compose down
 
         echo "Starting with new version..."
-        sudo docker compose up -d --remove-orphans
+        sudo -E docker compose up -d --remove-orphans
 
         echo "Cleaning up unused Docker resources..."
         sudo docker image prune -f