Skip to content

Commit 8804f0d

Browse files
Copilotrrrutledge
andcommitted
Add debugging and improve Codespaces environment detection
Co-authored-by: rrrutledge <9609562+rrrutledge@users.noreply.github.com>
1 parent b409214 commit 8804f0d

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

.devcontainer/debug-codespaces.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
# Debug script to check Codespaces environment
4+
echo "=== Codespaces Environment Debug ==="
5+
echo "CODESPACE_NAME: ${CODESPACE_NAME:-NOT SET}"
6+
echo "GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN: ${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-NOT SET}"
7+
echo ""
8+
9+
if [ -n "$CODESPACE_NAME" ]; then
10+
if [ -n "$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" ]; then
11+
CONSTRUCTED_URL="https://${CODESPACE_NAME}-1313.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
12+
else
13+
CONSTRUCTED_URL="https://${CODESPACE_NAME}-1313.app.github.dev"
14+
fi
15+
echo "Constructed Codespaces URL: $CONSTRUCTED_URL"
16+
else
17+
echo "Not running in Codespaces (CODESPACE_NAME not set)"
18+
fi
19+
20+
echo ""
21+
echo "=== Hugo Binary Location ==="
22+
which hugo
23+
ls -la $(which hugo) 2>/dev/null || echo "Hugo not found"
24+
25+
echo ""
26+
echo "=== Hugo Version ==="
27+
hugo version 2>/dev/null || echo "Hugo command failed"
28+
29+
if [ -f "/usr/local/bin/hugo-real" ]; then
30+
echo ""
31+
echo "=== Hugo-real found ==="
32+
ls -la /usr/local/bin/hugo-real
33+
/usr/local/bin/hugo-real version
34+
fi

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
}
3333
},
3434
"remoteUser": "vscode",
35-
"postCreateCommand": "npm install; cd /tmp && wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.133.1/hugo_extended_0.133.1_linux-amd64.deb && sudo dpkg -i hugo.deb && rm hugo.deb && npm init -y && npm install hugo-bin@latest && sudo mv /usr/local/bin/hugo /usr/local/bin/hugo-real && sudo cp ${containerWorkspaceFolder}/.devcontainer/hugo-wrapper.sh /usr/local/bin/hugo && sudo chmod +x /usr/local/bin/hugo && hugo version && echo 'Hugo server ready! You can now run: hugo server'"
35+
"postCreateCommand": "npm install && cd /tmp && wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.133.1/hugo_extended_0.133.1_linux-amd64.deb && sudo dpkg -i hugo.deb && rm hugo.deb && npm init -y && npm install hugo-bin@latest && sudo mv /usr/local/bin/hugo /usr/local/bin/hugo-real && sudo cp /workspaces/innersourcecommons.org/.devcontainer/hugo-wrapper.sh /usr/local/bin/hugo && sudo chmod +x /usr/local/bin/hugo && hugo version && echo 'Hugo server ready! You can now run: hugo server'"
3636
}

.vscode/start-hugo.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55

66
if [ -n "$CODESPACE_NAME" ]; then
77
# Running in GitHub Codespaces
8-
BASE_URL="https://${CODESPACE_NAME}-1313.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
8+
# Construct the Codespaces URL using the CODESPACE_NAME and port forwarding domain
9+
if [ -n "$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" ]; then
10+
BASE_URL="https://${CODESPACE_NAME}-1313.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
11+
else
12+
# Fallback: construct using the standard pattern
13+
BASE_URL="https://${CODESPACE_NAME}-1313.app.github.dev"
14+
fi
915
echo "🚀 Starting Hugo in Codespaces mode"
1016
echo "📍 Base URL: $BASE_URL"
17+
echo "📍 CODESPACE_NAME: $CODESPACE_NAME"
18+
echo "📍 GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN: ${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-not set, using default}"
1119
else
1220
# Running locally
1321
BASE_URL="http://localhost:1313"
@@ -16,7 +24,19 @@ else
1624
fi
1725

1826
# Start Hugo server with the appropriate configuration
19-
exec hugo server \
27+
# Use the actual hugo binary path to ensure we're not calling a wrapper
28+
HUGO_CMD="hugo"
29+
30+
# Check if hugo-real exists (wrapper might be installed)
31+
if [ -x "/usr/local/bin/hugo-real" ]; then
32+
HUGO_CMD="/usr/local/bin/hugo-real"
33+
echo "📍 Using hugo-real binary"
34+
elif command -v hugo &> /dev/null; then
35+
HUGO_CMD="hugo"
36+
echo "📍 Using standard hugo binary"
37+
fi
38+
39+
exec $HUGO_CMD server \
2040
--bind=0.0.0.0 \
2141
--baseURL="$BASE_URL" \
2242
--appendPort=false \

CODESPACES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ When the Hugo server starts:
8888

8989
If you encounter any issues:
9090

91+
- **CSS not loading (assets loading from localhost:1313)**: This means the Codespace environment wasn't detected properly. Try these steps:
92+
1. Stop the Hugo server (Ctrl+C in the terminal or stop debugging)
93+
2. Run `.devcontainer/debug-codespaces.sh` in the terminal to check your environment
94+
3. Make sure you see the "Running in Codespaces mode" message when starting Hugo
95+
4. If the environment variables are not set, try rebuilding the container (see below)
9196
- **Hugo server not starting**: Try restarting the Codespace by clicking on the menu in the bottom left corner and selecting "Codespaces: Stop Current Codespace" and then restarting it.
9297
- **Changes not showing**: Make sure you've saved your files and that the Hugo server is running.
9398
- **Port not forwarding**: Click the "Ports" tab at the bottom of the Codespace and make sure port 1313 is forwarded.

0 commit comments

Comments
 (0)