Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Sub domain proxy support #2

Merged
merged 5 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ This script sets up a [Code Server](https://github.com/cdr/code-server) instance
```

4. Access your Coder instance at your domain

## Port Proxy

Add more info here
2 changes: 1 addition & 1 deletion code-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After=network.target
[Service]
Type=exec
User=coder
ExecStart=/usr/bin/code-server
ExecStart=/usr/bin/code-server --proxy-domain mydomain.com
Restart=always

[Install]
Expand Down
55 changes: 48 additions & 7 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,45 @@ echo " https://github.com/alec-hs/coder-cloudflare-setup"
echo
echo "------------------------------------------------------------"
echo
read -s -p "Please enter a password for Coder web GUI: " password
echo
echo
read -p "Please enter your domain: " domain
echo
read -s -p "Please enter your Cloudflare API Token: " token
read -s -p "Enter a password for Coder web GUI: " password
echo
echo
echo "Enter root domain to access Code Server (not a subdomain): "
unset domain
until [[ $domain =~ ^[A-Za-z0-9-]+.([A-Za-z]{3,}|[A-Za-z]{2}.[A-Za-z]{2}|[A-Za-z]{2})$ ]] ; do
read -r domain
done
echo
echo "To allow port proxying, subdomain setup will be used. Please"
echo "enter a number from the below options. For more info:"
echo "https://github.com/alec-hs/coder-cloudflare-setup/#port-proxy"
echo
echo " 0 - wildcard record"
echo " 1 - specific ports"
echo
unset subOption
until [[ $subOption == @(0|1) ]] ; do
read -r -p "Your selection: " subOption
done
echo
echo "Enter your proxy domain, eg: mydomain.com"
read -p "Your domain: " proxyDomain
if [ $subOption == 1 ]
then
echo "Enter a space separated list of all the ports you need."
echo " eg: 80 8080 3000 8443"
read -p "Your ports: " ports
fi
echo
read -s -p "Enter your Cloudflare API Token: " token
echo
echo
echo "------------------------------------------------------------"
echo
echo " Setting up Caddy and Coder services..."
echo
echo "------------------------------------------------------------"
sleep 3

# Hash the password
hash=$(printf $password | sha256sum | cut -d' ' -f1)
Expand All @@ -47,6 +73,9 @@ curl -fsSL https://code-server.dev/install.sh | sh
# Download service file from repo
curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/code-server.service --output /etc/systemd/system/code-server.service

# Update coder file with proxy domain
sed -i.bak "s/mydomain.com/$proxyDomain/" /etc/systemd/system/code-server.service

# Run Coder & run on boot
systemctl enable --now code-server

Expand Down Expand Up @@ -78,8 +107,20 @@ mv caddy /usr/bin
curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/Caddyfile --output /etc/caddy/Caddyfile

# Update Caddyfile
sed -i.bak "s/sub.mydomain.com/$domain/" /etc/caddy/Caddyfile
sed -i.bak "s/API_TOKEN/$token/" /etc/caddy/Caddyfile
if [ $subOption == 0 ]
then
caddyDomains="$domain, *.$proxyDomain"
fi
if [ $subOption == 1 ]
then
proxyPorts="${ports// /.$proxyDomain, }"
proxyPorts="$proxyPorts.$proxyDomain"
caddyDomains="$domain, $proxyPorts"
fi
sed -i.bak "s/sub.mydomain.com/$caddyDomains/" /etc/caddy/Caddyfile



# Update Coder config in /home/coder/.config/code-server/config.yaml
sed -i.bak "s/password: .*/hashed-password: $hash/" /home/coder/.config/code-server/config.yaml
Expand Down