|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -eu |
| 3 | + |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | +generated_dir="$SCRIPT_DIR/../.generated" |
| 6 | +output_file="$generated_dir/docker-compose.local.override.yml" |
| 7 | +repo_root="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 8 | + |
| 9 | +environment_entries="" |
| 10 | +mounts="" |
| 11 | + |
| 12 | +escape_yaml_double_quoted() { |
| 13 | + value=$1 |
| 14 | + value=${value//\\/\\\\} |
| 15 | + value=${value//\"/\\\"} |
| 16 | + value=${value//$'\n'/\\n} |
| 17 | + printf '%s' "$value" |
| 18 | +} |
| 19 | + |
| 20 | +add_env() { |
| 21 | + env_name=$1 |
| 22 | + env_value=$2 |
| 23 | + escaped_env_value=$(escape_yaml_double_quoted "$env_value") |
| 24 | + |
| 25 | + if [ -n "$environment_entries" ]; then |
| 26 | + environment_entries="${environment_entries} ${env_name}: \"${escaped_env_value}\"\n" |
| 27 | + else |
| 28 | + environment_entries=" ${env_name}: \"${escaped_env_value}\"\n" |
| 29 | + fi |
| 30 | +} |
| 31 | + |
| 32 | +add_mount() { |
| 33 | + host_path=$1 |
| 34 | + target_path=$2 |
| 35 | + |
| 36 | + if [ -e "$host_path" ]; then |
| 37 | + escaped_host_path=$(escape_yaml_double_quoted "$host_path") |
| 38 | + escaped_target_path=$(escape_yaml_double_quoted "$target_path") |
| 39 | + mounts="${mounts} - type: bind\n source: \"${escaped_host_path}\"\n target: \"${escaped_target_path}\"\n" |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +add_ro_mount() { |
| 44 | + host_path=$1 |
| 45 | + target_path=$2 |
| 46 | + |
| 47 | + if [ -e "$host_path" ]; then |
| 48 | + escaped_host_path=$(escape_yaml_double_quoted "$host_path") |
| 49 | + escaped_target_path=$(escape_yaml_double_quoted "$target_path") |
| 50 | + mounts="${mounts} - type: bind\n source: \"${escaped_host_path}\"\n target: \"${escaped_target_path}\"\n read_only: true\n" |
| 51 | + fi |
| 52 | +} |
| 53 | + |
| 54 | +add_env "HOST_WORKSPACE_FOLDER" "$repo_root" |
| 55 | + |
| 56 | +if [ -n "${DISPLAY:-}" ]; then |
| 57 | + add_env "DISPLAY" "$DISPLAY" |
| 58 | +fi |
| 59 | +if [ -n "${HTTP_PROXY:-}" ]; then |
| 60 | + add_env "HTTP_PROXY" "$HTTP_PROXY" |
| 61 | +fi |
| 62 | +if [ -n "${HTTPS_PROXY:-}" ]; then |
| 63 | + add_env "HTTPS_PROXY" "$HTTPS_PROXY" |
| 64 | +fi |
| 65 | +if [ -n "${NO_PROXY:-}" ]; then |
| 66 | + add_env "NO_PROXY" "$NO_PROXY" |
| 67 | +fi |
| 68 | +if [ -n "${http_proxy:-}" ]; then |
| 69 | + add_env "http_proxy" "$http_proxy" |
| 70 | +fi |
| 71 | +if [ -n "${https_proxy:-}" ]; then |
| 72 | + add_env "https_proxy" "$https_proxy" |
| 73 | +fi |
| 74 | +if [ -n "${no_proxy:-}" ]; then |
| 75 | + add_env "no_proxy" "$no_proxy" |
| 76 | +fi |
| 77 | + |
| 78 | +add_mount "$HOME/.codex" "/home/ubuntu/.codex" |
| 79 | +add_mount "$HOME/.claude" "/home/ubuntu/.claude" |
| 80 | +add_mount "$HOME/.claude.json" "/home/ubuntu/.claude.json" |
| 81 | +add_mount "$HOME/.lark-cli" "/home/ubuntu/.lark-cli" |
| 82 | +add_mount "$HOME/.config/opencode" "/home/ubuntu/.config/opencode" |
| 83 | +add_mount "$HOME/.local/share/lark-cli" "/home/ubuntu/.local/share/lark-cli" |
| 84 | +add_mount "$HOME/.local/share/opencode" "/home/ubuntu/.local/share/opencode" |
| 85 | +add_ro_mount "$HOME/.agents/skills" "/home/ubuntu/.agents/skills" |
| 86 | + |
| 87 | +mkdir -p "$generated_dir" |
| 88 | + |
| 89 | +{ |
| 90 | + printf '%s\n' '# Generated by generate-local-override.sh - do not commit' |
| 91 | + printf '%s\n' 'services:' |
| 92 | + printf '%s\n' ' rmcs-develop:' |
| 93 | + printf '%s\n' ' environment:' |
| 94 | + if [ -n "$environment_entries" ]; then |
| 95 | + printf '%b' "$environment_entries" |
| 96 | + else |
| 97 | + printf '%s\n' ' {}' |
| 98 | + fi |
| 99 | + printf '%s\n' ' volumes:' |
| 100 | + if [ -n "$mounts" ]; then |
| 101 | + printf '%b' "$mounts" |
| 102 | + else |
| 103 | + printf '%s\n' ' []' |
| 104 | + fi |
| 105 | +} > "$output_file" |
0 commit comments