From 139828d59402da743c75257ada437474f1148da7 Mon Sep 17 00:00:00 2001 From: Bryan Date: Tue, 25 Jan 2022 11:08:25 -0800 Subject: [PATCH] refactor: 'create_initial_user.sh' helper script (#59) I've been running this `curl` command a bunch of times every day (whenever I restart my dev server) - so moving it to a more convenient place. --- develop.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/develop.sh b/develop.sh index ec2a89c5a6..689b92ebbc 100755 --- a/develop.sh +++ b/develop.sh @@ -2,9 +2,25 @@ set -euo pipefail +EMAIL="${EMAIL:-admin@coder.com}" +USERNAME="${USERNAME:-admin}" +ORGANIZATION="${ORGANIZATION:-ACME-Corp}" +PASSWORD="${PASSWORD:-password}" PROJECT_ROOT="$(git rev-parse --show-toplevel)" cd "${PROJECT_ROOT}" +# Helper to create an initial user +function create_initial_user() { + # TODO: We need to wait for `coderd` to spin up - + # need to replace with a deterministic strategy + sleep 5s + + curl -X POST \ + -d "{\"email\": \"$EMAIL\", \"username\": \"$USERNAME\", \"organization\": \"$ORGANIZATION\", \"password\": \"$PASSWORD\"}" \ + -H 'Content-Type:application/json' \ + http://localhost:3000/api/v2/users +} + # Do initial build - a dev build for coderd. # It's OK that we don't build the front-end before - because the front-end # assets are handled by the `yarn dev` devserver. @@ -13,4 +29,4 @@ make bin/coderd # This is a way to run multiple processes in parallel, and have Ctrl-C work correctly # to kill both at the same time. For more details, see: # https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script -(trap 'kill 0' SIGINT; CODERV2_HOST=http://127.0.0.1:3000 yarn dev & ./bin/coderd) \ No newline at end of file +(trap 'kill 0' SIGINT; create_initial_user & CODERV2_HOST=http://127.0.0.1:3000 yarn dev & ./bin/coderd) \ No newline at end of file