diff --git a/.env b/.env index 9a061ee77..345803b0d 100644 --- a/.env +++ b/.env @@ -1,6 +1,7 @@ # This top-level .env file under AirStack/ defines variables that are propagated through docker-compose.yaml PROJECT_NAME="airstack" -PROJECT_VERSION="0.13.1" +# auto-generated from git commit hash +DOCKER_IMAGE_TAG="3f238b1" # can replace with your docker hub username PROJECT_DOCKER_REGISTRY="airlab-storage.andrew.cmu.edu:5001/shared" DEFAULT_ISAAC_SCENE="omniverse://airlab-storage.andrew.cmu.edu:8443/Projects/AirStack/AFCA/fire_academy_faro_with_sky.scene.usd" diff --git a/docker-compose.yaml b/docker-compose.yaml index 4f7aa45a4..8e1198836 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,8 @@ # top-level docker-compose file for the autonomy stack +# This file includes all component docker-compose files +# Each component has its own docker-compose.yaml file +# Components are organized by functionality +# This allows for modular development and deployment include: - simulation/isaac-sim/docker/docker-compose.yaml - robot/docker/docker-compose.yaml diff --git a/docs/docker/docker-compose.yaml b/docs/docker/docker-compose.yaml index c8c8ae3ab..f0ee2856f 100644 --- a/docs/docker/docker-compose.yaml +++ b/docs/docker/docker-compose.yaml @@ -5,7 +5,7 @@ services: - "" - sitl - hitl - image: &image_tag ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${PROJECT_VERSION}_mkdocs + image: &image_tag ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${DOCKER_IMAGE_TAG}_mkdocs build: dockerfile: ./Dockerfile tags: diff --git a/git-hooks/README.md b/git-hooks/README.md new file mode 100644 index 000000000..b046c0f1b --- /dev/null +++ b/git-hooks/README.md @@ -0,0 +1,33 @@ +# Git Hooks + +This directory contains git hooks used in the AirStack repository. + +## Available Hooks + +### Docker Versioning Hook + +The `update-docker-image-tag.pre-commit` hook automatically updates the `DOCKER_IMAGE_TAG` in the `.env` file with the current git commit hash whenever Docker-related files (Dockerfile or docker-compose.yaml) are modified. It also adds a comment above the variable indicating that the value is auto-generated from the git commit hash. + +This ensures that Docker images are always tagged with the exact commit they were built from, eliminating version conflicts between parallel branches. + +### Installation + +To install the hooks: + +1. Copy the hook to your local .git/hooks directory: + ```bash + cp git-hooks/docker-versioning/update-docker-image-tag.pre-commit .git/hooks/pre-commit + ``` + +2. Make sure the hook file is executable: + ```bash + chmod +x .git/hooks/pre-commit + ``` + +## How the Docker Versioning Hook Works + +1. When you commit changes, the hook checks if any Dockerfile or docker-compose.yaml files are being committed +2. If Docker-related files are detected, it updates the DOCKER_IMAGE_TAG in the .env file with the current git commit hash and adds a comment above the variable +3. The modified .env file is automatically added to the commit + +This approach eliminates version conflicts between parallel branches by ensuring Docker images are tagged with the exact commit they were built from. \ No newline at end of file diff --git a/git-hooks/docker-versioning/README.md b/git-hooks/docker-versioning/README.md new file mode 100644 index 000000000..bbfe7521b --- /dev/null +++ b/git-hooks/docker-versioning/README.md @@ -0,0 +1,35 @@ +# Docker Versioning Git Hook + +This directory contains a git hook that automatically updates the Docker image tag with the current git commit hash. + +## Hook: update-docker-image-tag.pre-commit + +This pre-commit hook automatically updates the `DOCKER_IMAGE_TAG` in the `.env` file with the current git commit hash whenever Docker-related files (Dockerfile or docker-compose.yaml) are modified. + +### Features + +- Automatically updates `DOCKER_IMAGE_TAG` with the git commit hash +- Adds a comment above the variable indicating it's auto-generated +- Only triggers when Docker-related files are modified +- Automatically stages the modified .env file for commit + +### Installation + +To install the hook: + +1. Copy the hook to your local .git/hooks directory: + ```bash + cp update-docker-image-tag.pre-commit ../../.git/hooks/pre-commit + ``` + +2. Make sure the hook file is executable: + ```bash + chmod +x ../../.git/hooks/pre-commit + ``` + +### Benefits + +- Eliminates version conflicts between parallel branches +- Ensures Docker images are tagged with the exact commit they were built from +- Simplifies tracking which version of the code is running in Docker containers +- Provides a consistent and automated versioning system for Docker images \ No newline at end of file diff --git a/git-hooks/docker-versioning/update-docker-image-tag.pre-commit b/git-hooks/docker-versioning/update-docker-image-tag.pre-commit new file mode 100755 index 000000000..3165c91fd --- /dev/null +++ b/git-hooks/docker-versioning/update-docker-image-tag.pre-commit @@ -0,0 +1,40 @@ +#!/bin/bash + +# Pre-commit hook to update DOCKER_IMAGE_TAG in .env file with git commit hash +# when Dockerfile or docker-compose.yaml files are modified + +# Check if any Dockerfile or docker-compose.yaml files are staged for commit +DOCKER_FILES_CHANGED=$(git diff --cached --name-only | grep -E 'Dockerfile|docker-compose\.yaml$') + +if [ -n "$DOCKER_FILES_CHANGED" ]; then + echo "Docker-related files changed. Updating DOCKER_IMAGE_TAG in .env file..." + + # Get the current commit hash (short version) + COMMIT_HASH=$(git rev-parse --short HEAD) + + # Update the DOCKER_IMAGE_TAG in .env file + if [ -f ".env" ]; then + # Check if DOCKER_IMAGE_TAG line exists + if grep -q "^DOCKER_IMAGE_TAG=" .env; then + # Replace the existing DOCKER_IMAGE_TAG line and ensure comment is above it + # First, remove any existing auto-generated comment + sed -i '/^# auto-generated from git commit hash$/d' .env + # Add the comment above the DOCKER_IMAGE_TAG line + sed -i '/^DOCKER_IMAGE_TAG=/i\# auto-generated from git commit hash' .env + # Update the DOCKER_IMAGE_TAG value + sed -i "s/^DOCKER_IMAGE_TAG=.*$/DOCKER_IMAGE_TAG=\"$COMMIT_HASH\"/" .env + echo "Updated DOCKER_IMAGE_TAG to $COMMIT_HASH in .env file" + + # Stage the modified .env file for commit + git add .env + else + echo "Error: DOCKER_IMAGE_TAG line not found in .env file" + exit 1 + fi + else + echo "Error: .env file not found" + exit 1 + fi +fi + +exit 0 \ No newline at end of file diff --git a/ground_control_station/docker/ground-control-station-base-docker-compose.yaml b/ground_control_station/docker/ground-control-station-base-docker-compose.yaml index c6783cf41..7abdb6618 100644 --- a/ground_control_station/docker/ground-control-station-base-docker-compose.yaml +++ b/ground_control_station/docker/ground-control-station-base-docker-compose.yaml @@ -1,7 +1,7 @@ # docker compose file services: ground-control-station-base: - image: &gcs_image ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${PROJECT_VERSION}_gcs + image: &gcs_image ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${DOCKER_IMAGE_TAG}_gcs build: context: ../ dockerfile: docker/Dockerfile.gcs diff --git a/robot/docker/docker-compose.yaml b/robot/docker/docker-compose.yaml index a52b25f2b..01d7ab6db 100644 --- a/robot/docker/docker-compose.yaml +++ b/robot/docker/docker-compose.yaml @@ -10,7 +10,7 @@ services: extends: file: ./robot-base-docker-compose.yaml service: robot_base - image: &desktop_image ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${PROJECT_VERSION}_robot-x86-64 + image: &desktop_image ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${DOCKER_IMAGE_TAG}_robot-x86-64 build: dockerfile: ./Dockerfile.robot args: @@ -42,7 +42,7 @@ services: extends: file: ./robot-base-docker-compose.yaml service: robot_base - image: &l4t_image ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${PROJECT_VERSION}_robot-l4t + image: &l4t_image ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${DOCKER_IMAGE_TAG}_robot-l4t build: dockerfile: ./Dockerfile.robot args: diff --git a/simulation/isaac-sim/docker/docker-compose.yaml b/simulation/isaac-sim/docker/docker-compose.yaml index bd4c7b9e7..b926c2565 100644 --- a/simulation/isaac-sim/docker/docker-compose.yaml +++ b/simulation/isaac-sim/docker/docker-compose.yaml @@ -1,6 +1,6 @@ services: isaac-sim: - image: &image_tag ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${PROJECT_VERSION}_isaac-sim + image: &image_tag ${PROJECT_DOCKER_REGISTRY}/${PROJECT_NAME}:v${DOCKER_IMAGE_TAG}_isaac-sim build: context: ../ dockerfile: docker/Dockerfile.isaac-ros @@ -58,7 +58,7 @@ services: # developer stuff - .dev:/root/.dev:rw # developer config - .bashrc:/root/.bashrc:rw # bash config - - ../../common/inputrc:/etc/inputrc:rw # for using page up/down to search through command history + - ../../common/inputrc:/etc/inputrc:rw # for using page up/down to search through command history # code - ../sitl_integration/kit-app-template/source/extensions/:/root/Documents/Kit/shared/exts/ - ../sitl_integration:/sitl_integration:rw