mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore: add compose alternative to develop.sh (#22157)
Adds a `compose.dev.yml` intended as a pure-Docker alternative to `develop.sh`. --------- Co-authored-by: Steven Masley <stevenmasley@gmail.com>
This commit is contained in:
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
CODER="go run ./cmd/coder"
|
||||
PASSWORD="${CODER_DEV_ADMIN_PASSWORD:-SomeSecurePassword!}"
|
||||
TOKEN_FILE="/bootstrap/token"
|
||||
TOKEN_NAME="bootstrap"
|
||||
|
||||
echo "=== Coder Dev Environment Init ==="
|
||||
|
||||
if curl -s -o /dev/null -w "%{http_code}" http://coderd:3000/api/v2/users/first | grep -q "200"; then
|
||||
echo "First user already exists, skipping setup"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Step 1: Create first user (idempotent - creates OR logs in)
|
||||
echo "Creating/logging in first user..."
|
||||
$CODER login http://coderd:3000 \
|
||||
--first-user-username=admin \
|
||||
--first-user-email=admin@coder.com \
|
||||
--first-user-password="$PASSWORD" \
|
||||
--first-user-full-name="Admin User" \
|
||||
--first-user-trial=false
|
||||
|
||||
# Step 2: Create or retrieve bootstrap token
|
||||
if [ -f "$TOKEN_FILE" ] && [ -s "$TOKEN_FILE" ]; then
|
||||
echo "Bootstrap token already exists."
|
||||
else
|
||||
echo "Creating bootstrap token..."
|
||||
# Delete existing token if it exists (in case file was lost but token exists)
|
||||
$CODER tokens delete "$TOKEN_NAME" 2>/dev/null || true
|
||||
# Create new token with no expiry
|
||||
TOKEN=$($CODER tokens create --name "$TOKEN_NAME" --lifetime 0)
|
||||
echo "$TOKEN" >"$TOKEN_FILE"
|
||||
echo "Bootstrap token created and saved."
|
||||
fi
|
||||
|
||||
echo "=== Init complete ==="
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
CODER="go run ./enterprise/cmd/coder"
|
||||
TOKEN_FILE="/bootstrap/token"
|
||||
LICENSE_FILE="/license.txt"
|
||||
ORG_NAME="${ORG_NAME:-second-organization}"
|
||||
|
||||
echo "=== Multi-Organization Setup ==="
|
||||
|
||||
# Load bootstrap token
|
||||
CODER_SESSION_TOKEN=$(cat "$TOKEN_FILE")
|
||||
if [ -z "${CODER_SESSION_TOKEN}" ]; then
|
||||
echo "Bootstrap token not found in ${TOKEN_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
export CODER_SESSION_TOKEN
|
||||
|
||||
# Check if a license has not yet been added
|
||||
LICENSES=$($CODER license list | tail -n +2)
|
||||
if [ -z "${LICENSES}" ]; then
|
||||
echo "No existing license found."
|
||||
if [ ! -f "${LICENSE_FILE}" ]; then
|
||||
echo "License required, set CODER_DEV_LICENSE_FILE=path/to/license.txt"
|
||||
exit 1
|
||||
fi
|
||||
echo "Adding license..."
|
||||
$CODER license add --file "${LICENSE_FILE}"
|
||||
fi
|
||||
|
||||
# Create second organization if it doesn't exist.
|
||||
if ! $CODER organizations show "$ORG_NAME" >/dev/null 2>&1; then
|
||||
echo "Creating organization '$ORG_NAME'..."
|
||||
$CODER organizations create -y "$ORG_NAME"
|
||||
else
|
||||
echo "Organization '$ORG_NAME' already exists."
|
||||
fi
|
||||
|
||||
# Add member user to the organization.
|
||||
echo "Adding member user to organization '$ORG_NAME'..."
|
||||
$CODER organizations members add member --org "$ORG_NAME" 2>/dev/null ||
|
||||
echo "Member already in organization or failed to add."
|
||||
|
||||
echo "=== Multi-org setup complete ==="
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
CODER="go run ./cmd/coder"
|
||||
TOKEN_FILE="/bootstrap/token"
|
||||
|
||||
# Accept optional org argument. If not provided, use the user's default org.
|
||||
ORG_NAME="${1:-}"
|
||||
|
||||
echo "=== Setting up docker template ==="
|
||||
|
||||
# Load bootstrap token
|
||||
CODER_SESSION_TOKEN=$(cat "$TOKEN_FILE")
|
||||
if [ -z "${CODER_SESSION_TOKEN}" ]; then
|
||||
echo "Bootstrap token not found in ${TOKEN_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
export CODER_SESSION_TOKEN
|
||||
|
||||
# If no org provided, get user's default org.
|
||||
if [ -z "$ORG_NAME" ]; then
|
||||
ORG_NAME=$($CODER organizations show me -o json | jq -r '.[] | select(.is_default) | .name')
|
||||
fi
|
||||
|
||||
echo "Target organization: $ORG_NAME"
|
||||
|
||||
# Check if template already exists in this org.
|
||||
if $CODER templates versions list docker --org "$ORG_NAME" >/dev/null 2>&1; then
|
||||
echo "Docker template already exists in '$ORG_NAME'."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Create and push docker template.
|
||||
echo "Creating docker template in '$ORG_NAME'..."
|
||||
TEMPLATE_DIR="$(mktemp -d)"
|
||||
$CODER templates init --id docker "$TEMPLATE_DIR"
|
||||
(cd "$TEMPLATE_DIR" && terraform init)
|
||||
|
||||
ARCH="$(go env GOARCH)"
|
||||
printf 'docker_arch: "%s"\ndocker_host: "%s"\n' \
|
||||
"$ARCH" "${DOCKER_HOST:-unix:///var/run/docker.sock}" \
|
||||
>"$TEMPLATE_DIR/params.yaml"
|
||||
|
||||
$CODER templates push docker \
|
||||
--directory "$TEMPLATE_DIR" \
|
||||
--variables-file "$TEMPLATE_DIR/params.yaml" \
|
||||
--yes --org "$ORG_NAME"
|
||||
|
||||
rm -rf "$TEMPLATE_DIR"
|
||||
echo "=== Docker template setup complete ==="
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
CODER="go run ./cmd/coder"
|
||||
PASSWORD="${CODER_DEV_MEMBER_PASSWORD:-SomeSecurePassword!}"
|
||||
TOKEN_FILE="/bootstrap/token"
|
||||
|
||||
echo "=== Setting up users ==="
|
||||
|
||||
# Load bootstrap token
|
||||
CODER_SESSION_TOKEN=$(cat "$TOKEN_FILE")
|
||||
if [ -z "${CODER_SESSION_TOKEN}" ]; then
|
||||
echo "Bootstrap token not found in ${TOKEN_FILE}"
|
||||
exit 1
|
||||
fi
|
||||
export CODER_SESSION_TOKEN
|
||||
|
||||
# Create member user (idempotent)
|
||||
echo "Creating member user..."
|
||||
$CODER users create \
|
||||
--email=member@coder.com \
|
||||
--username=member \
|
||||
--full-name="Regular User" \
|
||||
--password="$PASSWORD" 2>/dev/null || echo "Member user already exists."
|
||||
|
||||
echo "=== Users setup complete ==="
|
||||
Reference in New Issue
Block a user