Skip to content

Commit c6641d4

Browse files
authored
fix: devcontainer paths/logs (#19236)
1 parent 91cbd56 commit c6641d4

File tree

6 files changed

+59
-25
lines changed

6 files changed

+59
-25
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"userEnvProbe": "loginInteractiveShell",
5656
"remoteEnv": {
5757
// The location where your uploaded files are stored
58-
"UPLOAD_LOCATION": "${localEnv:UPLOAD_LOCATION:./Library}",
58+
"UPLOAD_LOCATION": "${localEnv:UPLOAD_LOCATION:upload-devcontainer-volume}",
5959
// Connection secret for postgres. You should change it to a random password
6060
// Please use only the characters `A-Za-z0-9`, without special characters or spaces
6161
"DB_PASSWORD": "${localEnv:DB_PASSWORD:postgres}",

.devcontainer/server/container-common.sh

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,47 @@ export DEV_PORT="${DEV_PORT:-3000}"
77
# Devcontainer: Clone [repository|pull request] in container volumne
88
WORKSPACES_DIR="/workspaces"
99
IMMICH_DIR="$WORKSPACES_DIR/immich"
10+
IMMICH_DEVCONTAINER_LOG="$HOME/immich-devcontainer.log"
11+
12+
log() {
13+
# Display command on console, log with timestamp to file
14+
echo "$*"
15+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >>"$IMMICH_DEVCONTAINER_LOG"
16+
}
17+
18+
run_cmd() {
19+
# Ensure log directory exists
20+
mkdir -p "$(dirname "$IMMICH_DEVCONTAINER_LOG")"
21+
22+
log "$@"
23+
24+
# Execute command: display normally on console, log with timestamps to file
25+
"$@" 2>&1 | tee >(while IFS= read -r line; do
26+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $line" >>"$IMMICH_DEVCONTAINER_LOG"
27+
done)
28+
29+
# Preserve exit status
30+
return "${PIPESTATUS[0]}"
31+
}
1032

1133
# Find directories excluding /workspaces/immich
1234
mapfile -t other_dirs < <(find "$WORKSPACES_DIR" -mindepth 1 -maxdepth 1 -type d ! -path "$IMMICH_DIR" ! -name ".*")
1335

1436
if [ ${#other_dirs[@]} -gt 1 ]; then
15-
echo "Error: More than one directory found in $WORKSPACES_DIR other than $IMMICH_DIR."
37+
log "Error: More than one directory found in $WORKSPACES_DIR other than $IMMICH_DIR."
1638
exit 1
1739
elif [ ${#other_dirs[@]} -eq 1 ]; then
1840
export IMMICH_WORKSPACE="${other_dirs[0]}"
1941
else
2042
export IMMICH_WORKSPACE="$IMMICH_DIR"
2143
fi
2244

23-
echo "Found immich workspace in $IMMICH_WORKSPACE"
24-
25-
run_cmd() {
26-
echo "$@"
27-
"$@"
28-
}
45+
log "Found immich workspace in $IMMICH_WORKSPACE"
46+
log ""
2947

3048
fix_permissions() {
3149

32-
echo "Fixing permissions for ${IMMICH_WORKSPACE}"
50+
log "Fixing permissions for ${IMMICH_WORKSPACE}"
3351

3452
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 {} +
3553

@@ -41,17 +59,19 @@ fix_permissions() {
4159
"${IMMICH_WORKSPACE}/server/dist" \
4260
"${IMMICH_WORKSPACE}/web/node_modules" \
4361
"${IMMICH_WORKSPACE}/web/dist"
62+
63+
log ""
4464
}
4565

4666
install_dependencies() {
4767

48-
echo "Installing dependencies"
49-
68+
log "Installing dependencies"
5069
(
5170
cd "${IMMICH_WORKSPACE}" || exit 1
5271
run_cmd make install-server
53-
run_cmd make install-open-api
54-
run_cmd make build-open-api
72+
run_cmd make install-sdk
73+
run_cmd make build-sdk
5574
run_cmd make install-web
5675
)
57-
}
76+
log ""
77+
}

.devcontainer/server/container-compose-overrides.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ volumes:
4242
open_api_node_modules:
4343
server_node_modules:
4444
web_node_modules:
45+
upload-devcontainer-volume:

.devcontainer/server/container-start-backend.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# shellcheck disable=SC1091
44
source /immich-devcontainer/container-common.sh
55

6-
echo "Starting Nest API Server"
7-
6+
log "Starting Nest API Server"
7+
log ""
88
cd "${IMMICH_WORKSPACE}/server" || (
9-
echo workspace not found
9+
log "Immich workspace not found"
1010
exit 1
1111
)
1212

1313
while true; do
14-
node ./node_modules/.bin/nest start --debug "0.0.0.0:9230" --watch
15-
echo " Nest API Server crashed with exit code $?. Respawning in 3s ..."
14+
run_cmd node ./node_modules/.bin/nest start --debug "0.0.0.0:9230" --watch
15+
log "Nest API Server crashed with exit code $?. Respawning in 3s ..."
1616
sleep 3
1717
done

.devcontainer/server/container-start-frontend.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
# shellcheck disable=SC1091
44
source /immich-devcontainer/container-common.sh
55

6-
echo "Starting Immich Web Frontend"
7-
6+
log "Starting Immich Web Frontend"
7+
log ""
88
cd "${IMMICH_WORKSPACE}/web" || (
9-
echo Workspace not found
9+
log "Immich Workspace not found"
1010
exit 1
1111
)
1212

1313
until curl --output /dev/null --silent --head --fail "http://127.0.0.1:${IMMICH_PORT}/api/server/config"; do
14-
echo 'waiting for api server...'
14+
log "Waiting for api server..."
1515
sleep 1
1616
done
1717

1818
while true; do
19-
node ./node_modules/.bin/vite dev --host 0.0.0.0 --port "${DEV_PORT}"
20-
echo "Web crashed with exit code $?. Respawning in 3s ..."
19+
run_cmd node ./node_modules/.bin/vite dev --host 0.0.0.0 --port "${DEV_PORT}"
20+
log "Web crashed with exit code $?. Respawning in 3s ..."
2121
sleep 3
2222
done

.devcontainer/server/container-start.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,18 @@
33
# shellcheck disable=SC1091
44
source /immich-devcontainer/container-common.sh
55

6+
log "Setting up Immich dev container..."
67
fix_permissions
8+
9+
log "Installing npm dependencies (node_modules)..."
710
install_dependencies
11+
12+
log "Setup complete, please wait while backend and frontend services automatically start"
13+
log
14+
log "If necessary, the services may be manually started using"
15+
log
16+
log "$ /immich-devcontainer/container-start-backend.sh"
17+
log "$ /immich-devcontainer/container-start-frontend.sh"
18+
log
19+
log "From different terminal windows, as these scripts automatically restart the server"
20+
log "on error, and will continuously run in a loop"

0 commit comments

Comments
 (0)