fix: devcontainer paths/logs (#19236)

This commit is contained in:
Min Idzelis 2025-06-17 16:52:57 -04:00 committed by GitHub
parent 91cbd56c1c
commit c6641d4859
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 59 additions and 25 deletions

View File

@ -55,7 +55,7 @@
"userEnvProbe": "loginInteractiveShell", "userEnvProbe": "loginInteractiveShell",
"remoteEnv": { "remoteEnv": {
// The location where your uploaded files are stored // 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 // 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 // Please use only the characters `A-Za-z0-9`, without special characters or spaces
"DB_PASSWORD": "${localEnv:DB_PASSWORD:postgres}", "DB_PASSWORD": "${localEnv:DB_PASSWORD:postgres}",

View File

@ -7,12 +7,34 @@ export DEV_PORT="${DEV_PORT:-3000}"
# Devcontainer: Clone [repository|pull request] in container volumne # Devcontainer: Clone [repository|pull request] in container volumne
WORKSPACES_DIR="/workspaces" WORKSPACES_DIR="/workspaces"
IMMICH_DIR="$WORKSPACES_DIR/immich" 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 # Find directories excluding /workspaces/immich
mapfile -t other_dirs < <(find "$WORKSPACES_DIR" -mindepth 1 -maxdepth 1 -type d ! -path "$IMMICH_DIR" ! -name ".*") mapfile -t other_dirs < <(find "$WORKSPACES_DIR" -mindepth 1 -maxdepth 1 -type d ! -path "$IMMICH_DIR" ! -name ".*")
if [ ${#other_dirs[@]} -gt 1 ]; then 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 exit 1
elif [ ${#other_dirs[@]} -eq 1 ]; then elif [ ${#other_dirs[@]} -eq 1 ]; then
export IMMICH_WORKSPACE="${other_dirs[0]}" export IMMICH_WORKSPACE="${other_dirs[0]}"
@ -20,16 +42,12 @@ else
export IMMICH_WORKSPACE="$IMMICH_DIR" export IMMICH_WORKSPACE="$IMMICH_DIR"
fi fi
echo "Found immich workspace in $IMMICH_WORKSPACE" log "Found immich workspace in $IMMICH_WORKSPACE"
log ""
run_cmd() {
echo "$@"
"$@"
}
fix_permissions() { 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 {} + 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}/server/dist" \
"${IMMICH_WORKSPACE}/web/node_modules" \ "${IMMICH_WORKSPACE}/web/node_modules" \
"${IMMICH_WORKSPACE}/web/dist" "${IMMICH_WORKSPACE}/web/dist"
log ""
} }
install_dependencies() { install_dependencies() {
echo "Installing dependencies" log "Installing dependencies"
( (
cd "${IMMICH_WORKSPACE}" || exit 1 cd "${IMMICH_WORKSPACE}" || exit 1
run_cmd make install-server run_cmd make install-server
run_cmd make install-open-api run_cmd make install-sdk
run_cmd make build-open-api run_cmd make build-sdk
run_cmd make install-web run_cmd make install-web
) )
log ""
} }

View File

@ -42,3 +42,4 @@ volumes:
open_api_node_modules: open_api_node_modules:
server_node_modules: server_node_modules:
web_node_modules: web_node_modules:
upload-devcontainer-volume:

View File

@ -3,15 +3,15 @@
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source /immich-devcontainer/container-common.sh source /immich-devcontainer/container-common.sh
echo "Starting Nest API Server" log "Starting Nest API Server"
log ""
cd "${IMMICH_WORKSPACE}/server" || ( cd "${IMMICH_WORKSPACE}/server" || (
echo workspace not found log "Immich workspace not found"
exit 1 exit 1
) )
while true; do while true; do
node ./node_modules/.bin/nest start --debug "0.0.0.0:9230" --watch run_cmd node ./node_modules/.bin/nest start --debug "0.0.0.0:9230" --watch
echo " Nest API Server crashed with exit code $?. Respawning in 3s ..." log "Nest API Server crashed with exit code $?. Respawning in 3s ..."
sleep 3 sleep 3
done done

View File

@ -3,20 +3,20 @@
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source /immich-devcontainer/container-common.sh source /immich-devcontainer/container-common.sh
echo "Starting Immich Web Frontend" log "Starting Immich Web Frontend"
log ""
cd "${IMMICH_WORKSPACE}/web" || ( cd "${IMMICH_WORKSPACE}/web" || (
echo Workspace not found log "Immich Workspace not found"
exit 1 exit 1
) )
until curl --output /dev/null --silent --head --fail "http://127.0.0.1:${IMMICH_PORT}/api/server/config"; do 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 sleep 1
done done
while true; do while true; do
node ./node_modules/.bin/vite dev --host 0.0.0.0 --port "${DEV_PORT}" run_cmd node ./node_modules/.bin/vite dev --host 0.0.0.0 --port "${DEV_PORT}"
echo "Web crashed with exit code $?. Respawning in 3s ..." log "Web crashed with exit code $?. Respawning in 3s ..."
sleep 3 sleep 3
done done

View File

@ -3,5 +3,18 @@
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source /immich-devcontainer/container-common.sh source /immich-devcontainer/container-common.sh
log "Setting up Immich dev container..."
fix_permissions fix_permissions
log "Installing npm dependencies (node_modules)..."
install_dependencies 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"