diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4e4285f131..c8a491b4d3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -55,7 +55,7 @@ "userEnvProbe": "loginInteractiveShell", "remoteEnv": { // The location where your uploaded files are stored - "UPLOAD_LOCATION": "${localEnv:UPLOAD_LOCATION:./Library}", + "UPLOAD_LOCATION": "${localEnv:UPLOAD_LOCATION:upload-devcontainer-volume}", // Connection secret for postgres. You should change it to a random password // Please use only the characters `A-Za-z0-9`, without special characters or spaces "DB_PASSWORD": "${localEnv:DB_PASSWORD:postgres}", diff --git a/.devcontainer/server/container-common.sh b/.devcontainer/server/container-common.sh index 95f4e222a1..8fc0038d49 100755 --- a/.devcontainer/server/container-common.sh +++ b/.devcontainer/server/container-common.sh @@ -7,12 +7,34 @@ export DEV_PORT="${DEV_PORT:-3000}" # Devcontainer: Clone [repository|pull request] in container volumne WORKSPACES_DIR="/workspaces" IMMICH_DIR="$WORKSPACES_DIR/immich" +IMMICH_DEVCONTAINER_LOG="$HOME/immich-devcontainer.log" + +log() { + # Display command on console, log with timestamp to file + echo "$*" + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >>"$IMMICH_DEVCONTAINER_LOG" +} + +run_cmd() { + # Ensure log directory exists + mkdir -p "$(dirname "$IMMICH_DEVCONTAINER_LOG")" + + log "$@" + + # Execute command: display normally on console, log with timestamps to file + "$@" 2>&1 | tee >(while IFS= read -r line; do + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $line" >>"$IMMICH_DEVCONTAINER_LOG" + done) + + # Preserve exit status + return "${PIPESTATUS[0]}" +} # Find directories excluding /workspaces/immich mapfile -t other_dirs < <(find "$WORKSPACES_DIR" -mindepth 1 -maxdepth 1 -type d ! -path "$IMMICH_DIR" ! -name ".*") if [ ${#other_dirs[@]} -gt 1 ]; then - echo "Error: More than one directory found in $WORKSPACES_DIR other than $IMMICH_DIR." + log "Error: More than one directory found in $WORKSPACES_DIR other than $IMMICH_DIR." exit 1 elif [ ${#other_dirs[@]} -eq 1 ]; then export IMMICH_WORKSPACE="${other_dirs[0]}" @@ -20,16 +42,12 @@ else export IMMICH_WORKSPACE="$IMMICH_DIR" fi -echo "Found immich workspace in $IMMICH_WORKSPACE" - -run_cmd() { - echo "$@" - "$@" -} +log "Found immich workspace in $IMMICH_WORKSPACE" +log "" fix_permissions() { - echo "Fixing permissions for ${IMMICH_WORKSPACE}" + log "Fixing permissions for ${IMMICH_WORKSPACE}" run_cmd sudo find "${IMMICH_WORKSPACE}/server/upload" -not -path "${IMMICH_WORKSPACE}/server/upload/postgres/*" -not -path "${IMMICH_WORKSPACE}/server/upload/postgres" -exec chown node {} + @@ -41,17 +59,19 @@ fix_permissions() { "${IMMICH_WORKSPACE}/server/dist" \ "${IMMICH_WORKSPACE}/web/node_modules" \ "${IMMICH_WORKSPACE}/web/dist" + + log "" } install_dependencies() { - echo "Installing dependencies" - + log "Installing dependencies" ( cd "${IMMICH_WORKSPACE}" || exit 1 run_cmd make install-server - run_cmd make install-open-api - run_cmd make build-open-api + run_cmd make install-sdk + run_cmd make build-sdk run_cmd make install-web ) -} \ No newline at end of file + log "" +} diff --git a/.devcontainer/server/container-compose-overrides.yml b/.devcontainer/server/container-compose-overrides.yml index 94fbbab8cd..eb36a062a5 100644 --- a/.devcontainer/server/container-compose-overrides.yml +++ b/.devcontainer/server/container-compose-overrides.yml @@ -42,3 +42,4 @@ volumes: open_api_node_modules: server_node_modules: web_node_modules: + upload-devcontainer-volume: diff --git a/.devcontainer/server/container-start-backend.sh b/.devcontainer/server/container-start-backend.sh index 230a1378a2..aeb70df72d 100755 --- a/.devcontainer/server/container-start-backend.sh +++ b/.devcontainer/server/container-start-backend.sh @@ -3,15 +3,15 @@ # shellcheck disable=SC1091 source /immich-devcontainer/container-common.sh -echo "Starting Nest API Server" - +log "Starting Nest API Server" +log "" cd "${IMMICH_WORKSPACE}/server" || ( - echo workspace not found + log "Immich workspace not found" exit 1 ) while true; do - node ./node_modules/.bin/nest start --debug "0.0.0.0:9230" --watch - echo " Nest API Server crashed with exit code $?. Respawning in 3s ..." + run_cmd node ./node_modules/.bin/nest start --debug "0.0.0.0:9230" --watch + log "Nest API Server crashed with exit code $?. Respawning in 3s ..." sleep 3 done diff --git a/.devcontainer/server/container-start-frontend.sh b/.devcontainer/server/container-start-frontend.sh index 43bde2a344..633dcc3a93 100755 --- a/.devcontainer/server/container-start-frontend.sh +++ b/.devcontainer/server/container-start-frontend.sh @@ -3,20 +3,20 @@ # shellcheck disable=SC1091 source /immich-devcontainer/container-common.sh -echo "Starting Immich Web Frontend" - +log "Starting Immich Web Frontend" +log "" cd "${IMMICH_WORKSPACE}/web" || ( - echo Workspace not found + log "Immich Workspace not found" exit 1 ) until curl --output /dev/null --silent --head --fail "http://127.0.0.1:${IMMICH_PORT}/api/server/config"; do - echo 'waiting for api server...' + log "Waiting for api server..." sleep 1 done while true; do - node ./node_modules/.bin/vite dev --host 0.0.0.0 --port "${DEV_PORT}" - echo "Web crashed with exit code $?. Respawning in 3s ..." + run_cmd node ./node_modules/.bin/vite dev --host 0.0.0.0 --port "${DEV_PORT}" + log "Web crashed with exit code $?. Respawning in 3s ..." sleep 3 done diff --git a/.devcontainer/server/container-start.sh b/.devcontainer/server/container-start.sh index ef22db5d72..860b2826b0 100755 --- a/.devcontainer/server/container-start.sh +++ b/.devcontainer/server/container-start.sh @@ -3,5 +3,18 @@ # shellcheck disable=SC1091 source /immich-devcontainer/container-common.sh +log "Setting up Immich dev container..." fix_permissions + +log "Installing npm dependencies (node_modules)..." install_dependencies + +log "Setup complete, please wait while backend and frontend services automatically start" +log +log "If necessary, the services may be manually started using" +log +log "$ /immich-devcontainer/container-start-backend.sh" +log "$ /immich-devcontainer/container-start-frontend.sh" +log +log "From different terminal windows, as these scripts automatically restart the server" +log "on error, and will continuously run in a loop"