mirror of
https://github.com/balena-io/open-balena.git
synced 2025-03-25 05:25:37 +00:00
Improve configuration quick start script
This commit is contained in:
parent
263dcae857
commit
0e1543004a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.DS_Store
|
||||
.project
|
||||
.vagrant/
|
||||
config/
|
||||
src/
|
||||
|
40
README.md
40
README.md
@ -12,34 +12,42 @@
|
||||
|
||||
Make sure you have the software listed above installed.
|
||||
|
||||
In a terminal, change into the `open-balena` directory and create a new
|
||||
deployment:
|
||||
In a terminal, clone the project with:
|
||||
|
||||
$ ./scripts/start-project
|
||||
$ git clone https://github.com/balena-io/open-balena.git
|
||||
|
||||
This will create a new directory, `demo`, and generate appropriate SSL
|
||||
certificates and configuration for the platform. You can configure the
|
||||
deployment name by passing it as the first argument to the `start-project`
|
||||
command. If you wish to run the platform under a specific domain name,
|
||||
you can specify it as the second argument. The default is `openbalena.local`.
|
||||
For example:
|
||||
Change into the `open-balena` directory and run the configuration script.
|
||||
This will create a new directory, `config`, and generate appropriate SSL
|
||||
certificates and configuration for the instance.
|
||||
|
||||
$ ./scripts/start-project -n mydeployment -d mydomain.com
|
||||
$ ./scripts/quickstart
|
||||
|
||||
You can create as many deployments as needed and switch between them using:
|
||||
You may optionally configure the instance to run under a custom domain name.
|
||||
The default is `openbalena.local`. For example:
|
||||
|
||||
$ ./scripts/select-project -n mydeployment
|
||||
$ ./scripts/quickstart -d mydomain.com
|
||||
|
||||
Remove all traces of a project by deleting its folder.
|
||||
For more available options, see the script's help:
|
||||
|
||||
Start the platform with:
|
||||
$ ./scripts/quickstart -h
|
||||
|
||||
$ ./scripts/compose up
|
||||
Start the instance with:
|
||||
|
||||
Stop the platform with:
|
||||
$ ./scripts/compose up -d
|
||||
|
||||
Stop the instance with:
|
||||
|
||||
$ ./scripts/compose stop
|
||||
|
||||
To remove all traces of the instance, run the following commands and finally
|
||||
delete the configuration folder.
|
||||
|
||||
**WARNING**: This will remove *all* data.
|
||||
|
||||
$ ./scripts/compose kill
|
||||
$ ./scripts/compose down
|
||||
$ docker volume rm openbalena_s3 openbalena_redis openbalena_db openbalena_registry
|
||||
|
||||
### macOS & Windows
|
||||
|
||||
On macOS and Windows you need Vagrant. `open-balena` is not being tested with
|
||||
|
11
Vagrantfile
vendored
11
Vagrantfile
vendored
@ -13,7 +13,7 @@ Vagrant.configure('2') do |config|
|
||||
|
||||
config.vm.synced_folder '.', '/vagrant', disabled: true
|
||||
config.vm.synced_folder '.', '/home/vagrant/open-balena'
|
||||
config.vm.network 'public_network', bridge: ENV.fetch('OPENBALENA_BRIDGE', true)
|
||||
config.vm.network 'public_network', bridge: ENV.fetch('OPENBALENA_BRIDGE', '')
|
||||
|
||||
config.ssh.forward_agent = true
|
||||
|
||||
@ -23,13 +23,6 @@ Vagrant.configure('2') do |config|
|
||||
# FIXME: remove node
|
||||
config.vm.provision :shell, inline: 'apt-get update && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/*'
|
||||
|
||||
# FIXME: remove `docker login`
|
||||
config.vm.provision :shell, privileged: false, inline: "docker login --username resindev --password #{ENV.fetch('DOCKERHUB_PASSWORD')}"
|
||||
|
||||
config.vm.provision :shell, privileged: false,
|
||||
# FIXME: -n/-d should only be passed if the relevant ENV var is set
|
||||
inline: "cd /home/vagrant/open-balena && ./scripts/start-project -p -n #{ENV.fetch('OPENBALENA_PROJECT_NAME', 'demo')} -d #{ENV.fetch('OPENBALENA_DOMAIN', 'openbalena.local')}"
|
||||
config.vm.provision :shell, privileged: false,
|
||||
inline: 'cd /home/vagrant/open-balena && ./scripts/compose up -d || true',
|
||||
run: 'always'
|
||||
inline: "cd /home/vagrant/open-balena && ./scripts/quickstart -p -d #{ENV.fetch('OPENBALENA_DOMAIN', 'openbalena.local')}"
|
||||
end
|
||||
|
@ -1,30 +1,24 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
CMD="$0"
|
||||
DIR="$(dirname "$CMD")"
|
||||
BASE_DIR="$(dirname "$DIR")"
|
||||
CMD="$(realpath "$0")"
|
||||
DIR="$(dirname "${CMD}")"
|
||||
BASE_DIR="$(dirname "${DIR}")"
|
||||
CONFIG_DIR="${BASE_DIR}/config"
|
||||
|
||||
echo_bold() {
|
||||
printf "\\033[1m%s\\033[0m\\n" "$@"
|
||||
}
|
||||
|
||||
PROJECT_FILE="${BASE_DIR}/.project"
|
||||
if [ ! -f "$PROJECT_FILE" ]; then
|
||||
echo_bold 'No project activated. Please create or select an existing one first.'
|
||||
ENV_FILE="${CONFIG_DIR}/activate"
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
echo_bold 'No configuration found; please create one first with: ./scripts/quickstart'
|
||||
echo_bold 'See README.md for help.'
|
||||
exit 1
|
||||
fi
|
||||
PROJECT="$(cat "$PROJECT_FILE")"
|
||||
if [ ! -f "${PROJECT}/activate" ]; then
|
||||
echo_bold 'No project activated. Please create or select an existing one first.'
|
||||
echo_bold 'See README.md for help.'
|
||||
exit 1
|
||||
fi
|
||||
PROJECT_NAME="$(basename "$PROJECT")"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "${PROJECT}/activate"; docker-compose \
|
||||
--project-name "${PROJECT_NAME}" \
|
||||
source "${ENV_FILE}"; docker-compose \
|
||||
--project-name 'openbalena' \
|
||||
-f "${BASE_DIR}/compose/services.yml" \
|
||||
-f "${PROJECT}/docker-compose.yml" \
|
||||
-f "${CONFIG_DIR}/docker-compose.yml" \
|
||||
"$@"
|
||||
|
@ -1,21 +1,34 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 USERNAME EMAIL PASSWORD"
|
||||
echo "usage: $0 EMAIL PASSWORD"
|
||||
echo
|
||||
echo 'Create the superuser account with the given email and password.'
|
||||
echo
|
||||
echo 'The instance must already be running in the background. You can '
|
||||
echo 'start it with: ./scripts/compose up -d'
|
||||
}
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
if [[ -z "$1" || -z "$2" ]]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo_bold() {
|
||||
printf "\\033[1m%s\\033[0m\\n" "${@}"
|
||||
}
|
||||
|
||||
CMD="$(realpath "$0")"
|
||||
DIR="$(dirname "${CMD}")"
|
||||
|
||||
FIG="${DIR}/compose"
|
||||
|
||||
USERNAME="$1"
|
||||
EMAIL="$2"
|
||||
PASSWORD="$3"
|
||||
EMAIL="$1"
|
||||
PASSWORD="$2"
|
||||
|
||||
"${FIG}" exec api /bin/bash -c 'export $(grep -v "^#" config/env | xargs -d "\n"); node index.js create-superuser '${USERNAME}' '${EMAIL}' '${PASSWORD}''
|
||||
"${FIG}" exec api /bin/bash -c \
|
||||
'export $(grep -v "^#" config/env | xargs -d "\n"); node index.js create-superuser root '${EMAIL}' '${PASSWORD}'' \
|
||||
>/dev/null \
|
||||
|| (echo 'Failed to create superuser; please ensure the instance is running and that no superuser has been created before.' && exit 1)
|
||||
|
||||
echo_bold "==> Success! Superuser created with email: ${EMAIL}"
|
||||
echo " - You may now login with: balena login --credentials --email ${EMAIL}"
|
||||
|
@ -1,28 +1,27 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
CMD="$0"
|
||||
DIR=$(dirname "${CMD}")
|
||||
BASE_DIR=$(dirname "${DIR}")
|
||||
CMD="$(realpath "$0")"
|
||||
DIR="$(dirname "${CMD}")"
|
||||
BASE_DIR="$(dirname "${DIR}")"
|
||||
CONFIG_DIR="${BASE_DIR}/config"
|
||||
CERTS_DIR="${CONFIG_DIR}/certs"
|
||||
|
||||
PROJECT_NAME=demo
|
||||
DOMAIN=openbalena.local
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [-h] [-p] [-n PROJECT_NAME] [-d DOMAIN]"
|
||||
echo "usage: $0 [-h] [-p] [-d DOMAIN]"
|
||||
echo
|
||||
echo " -p patch hosts - patch the host /etc/hosts file"
|
||||
echo " -n PROJECT_NAME a name for the deployment, eg. staging. Default is 'demo'"
|
||||
echo " -d DOMAIN the domain name this deployment will run as, eg. example.com. Default is 'openbalena.local'"
|
||||
echo " -p patch hosts - patch the host /etc/hosts file"
|
||||
echo " -d DOMAIN the domain name this deployment will run as, eg. example.com. Default is 'openbalena.local'"
|
||||
echo
|
||||
}
|
||||
|
||||
show_help=false
|
||||
patch_hosts=false
|
||||
while getopts ":hpn:d:" opt; do
|
||||
while getopts ":hpd:" opt; do
|
||||
case "${opt}" in
|
||||
h) show_help=true;;
|
||||
p) patch_hosts=true;;
|
||||
n) PROJECT_NAME="${OPTARG}";;
|
||||
d) DOMAIN="${OPTARG}";;
|
||||
*)
|
||||
echo "Invalid argument: -${OPTARG}"
|
||||
@ -33,9 +32,6 @@ while getopts ":hpn:d:" opt; do
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
PROJECT_DIR="$(pwd)/${PROJECT_NAME}"
|
||||
CERTS_DIR="${PROJECT_DIR}/certs"
|
||||
|
||||
if [ "$show_help" = "true" ]; then
|
||||
usage
|
||||
exit 1
|
||||
@ -45,13 +41,13 @@ echo_bold() {
|
||||
printf "\\033[1m%s\\033[0m\\n" "${@}"
|
||||
}
|
||||
|
||||
if [ -d "$PROJECT_DIR" ]; then
|
||||
echo 'Project directory already exists. Please remove it or specify another project name.'
|
||||
if [ -d "$CONFIG_DIR" ]; then
|
||||
echo 'Configuration directory already exists; please remove it first.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo_bold "==> Creating new project at: $PROJECT_DIR"
|
||||
mkdir -p "$PROJECT_DIR" "$CERTS_DIR"
|
||||
echo_bold "==> Creating new configuration at: $CONFIG_DIR"
|
||||
mkdir -p "$CONFIG_DIR" "$CERTS_DIR"
|
||||
|
||||
echo_bold "==> Generating root CA cert..."
|
||||
# shellcheck source=scripts/gen-root-ca
|
||||
@ -71,10 +67,10 @@ source "${DIR}/gen-vpn-certs" "${DOMAIN}" "${CERTS_DIR}"
|
||||
|
||||
echo_bold "==> Setting up environment..."
|
||||
# shellcheck source=scripts/make-env
|
||||
cat >"${PROJECT_DIR}/activate" <(source "${DIR}/make-env")
|
||||
cat >"${CONFIG_DIR}/activate" <(source "${DIR}/make-env")
|
||||
|
||||
echo_bold "==> Adding default compose file..."
|
||||
cp "${BASE_DIR}/compose/template.yml" "${PROJECT_DIR}/docker-compose.yml"
|
||||
cp "${BASE_DIR}/compose/template.yml" "${CONFIG_DIR}/docker-compose.yml"
|
||||
|
||||
if [ "${patch_hosts}" = "true" ]; then
|
||||
echo_bold "==> Patching /etc/hosts..."
|
||||
@ -82,5 +78,8 @@ if [ "${patch_hosts}" = "true" ]; then
|
||||
source "${DIR}/patch-hosts" "${DOMAIN}"
|
||||
fi
|
||||
|
||||
echo_bold "==> Activating project..."
|
||||
"${DIR}/select-project" "${PROJECT_DIR}"
|
||||
echo_bold "==> Success!"
|
||||
echo ' - Start the instance with: ./scripts/compose up -d'
|
||||
echo ' - Stop the instance with: ./scripts/compose stop'
|
||||
echo ' - To create the superuser, see: ./scripts/create-superuser -h'
|
||||
echo " - Use the following certificate with Balena CLI: ${CONFIG_DIR}/root/ca.crt"
|
@ -1,32 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 PROJECT_PATH"
|
||||
echo
|
||||
echo " PROJECT_PATH path to the project; can be relative to open-balena root."
|
||||
echo
|
||||
}
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CMD="$0"
|
||||
DIR="$(dirname "${CMD}")"
|
||||
BASE_DIR="$(dirname "${DIR}")"
|
||||
|
||||
PROJECT_PATH="$1"
|
||||
PROJECT_DIR="$(realpath "${PROJECT_PATH}")"
|
||||
|
||||
if [ ! -d "$PROJECT_DIR" ]; then
|
||||
echo 'Project path refers to a directory that does not exist.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "${PROJECT_DIR}/activate" ]; then
|
||||
echo 'Project path refers to a directory that is not a valid project.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "${PROJECT_DIR}" >"${BASE_DIR}/.project"
|
Loading…
x
Reference in New Issue
Block a user