-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Environment Variables: Configure variables like PORT, USERNAME, and P…
…ASSWORD when running the container. Persistent Cache: Use npm cache clean and retry settings to address transient download issues. Logs: Examine logs at /root/.npm/_logs/ for further troubleshooting if issues persist.
- Loading branch information
1 parent
c697c89
commit 5b2b86d
Showing
2 changed files
with
43 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,16 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Validate required environment variables | ||
if [ -z "$USERNAME" ] || [ -z "$PORT" ] || [ -z "$PASSWORD" ]; then | ||
echo "Error: USERNAME, PORT, and PASSWORD environment variables are required" | ||
exit 1 | ||
fi | ||
|
||
# Set HOME if not already set | ||
if [ -z "$HOME" ]; then | ||
export HOME="/home/${USERNAME}" | ||
fi | ||
|
||
# Create user if it doesn't exist | ||
if ! id -u ${USERNAME} >/dev/null 2>&1; then | ||
useradd -m -s /bin/bash ${USERNAME} | ||
echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME} | ||
fi | ||
|
||
# Setup directories | ||
mkdir -p ${HOME}/.local/share/code-server/extensions | ||
mkdir -p ${HOME}/.local/share/code-server/User | ||
mkdir -p ${HOME}/.local/share/code-server/Machine | ||
mkdir -p ${HOME}/.local/share/code-server/logs | ||
mkdir -p ${HOME}/.local/share/code-server/User/globalStorage | ||
mkdir -p ${HOME}/.local/share/code-server/User/History | ||
chown -R ${USERNAME}:${USERNAME} ${HOME} | ||
|
||
# Generate SSL certificates if they don't exist | ||
if [ ! -f /etc/code-server/self-signed.crt ]; then | ||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ | ||
-keyout /etc/code-server/self-signed.key \ | ||
-out /etc/code-server/self-signed.crt \ | ||
# Generate SSL certificates if not exist | ||
if [ ! -f /home/${USERNAME}/.ssl/key.pem ]; then | ||
mkdir -p /home/${USERNAME}/.ssl | ||
openssl req -x509 -nodes -days 365 \ | ||
-newkey rsa:2048 \ | ||
-keyout /home/${USERNAME}/.ssl/key.pem \ | ||
-out /home/${USERNAME}/.ssl/cert.pem \ | ||
-subj "/CN=localhost" | ||
chmod -R 600 /home/${USERNAME}/.ssl | ||
fi | ||
|
||
# Configure code-server | ||
mkdir -p ${HOME}/.config/code-server | ||
cat > ${HOME}/.config/code-server/config.yaml << EOF | ||
bind-addr: 0.0.0.0:${PORT} | ||
auth: password | ||
password: ${PASSWORD} | ||
cert: /etc/code-server/self-signed.crt | ||
cert-key: /etc/code-server/self-signed.key | ||
EOF | ||
|
||
chown -R ${USERNAME}:${USERNAME} ${HOME}/.config | ||
|
||
# Switch to the user and start code-server | ||
exec sudo -u ${USERNAME} code-server \ | ||
--bind-addr "0.0.0.0:${PORT}" \ | ||
--user-data-dir "${HOME}/.local/share/code-server" \ | ||
--config "${HOME}/.config/code-server/config.yaml" | ||
# Run code-server with specified environment variables | ||
exec code-server --auth password --cert /home/${USERNAME}/.ssl/cert.pem --port ${PORT:-8443} |