Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation enhancements. #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.env
data/
docker-compose.override.yml
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The easiest is to use our `docker-compose.yml`.
Make sure you have [docker-compose](http://docs.docker.com/compose/install/) installed. And then:

```
docker network create lb_web
git clone https://github.com/indiehosters/discourse.git
cd discourse
./scripts/install
Expand Down Expand Up @@ -40,3 +41,22 @@ web:
- "80:80"
...
```

##Environment variables

./scripts/install expects certain environment variables to be in place.
You will be asked for these values if they do not already exist.

```
VIRTUAL_HOST=host-domain
DISCOURSE_SMTP_ADDRESS=smtp-host
DISCOURSE_SMTP_USER_NAME=smtp-host-username
DISCOURSE_SMTP_PASSWORD=smtp-host-password
DISCOURSE_DB_PASSWORD=postgres-database-password
POSTGRES_PASSWORD=postgres-database-password
SUBNET=0
POSTGRES_VERSION=10.6
```

You can prepopulate these environment variables by copying example.env to .env and changing the values to suit your environment.

8 changes: 8 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
VIRTUAL_HOST=host-domain
DISCOURSE_SMTP_ADDRESS=smtp-host
DISCOURSE_SMTP_USER_NAME=smtp-host-username
DISCOURSE_SMTP_PASSWORD=smtp-host-password
DISCOURSE_DB_PASSWORD=postgres-database-password
POSTGRES_PASSWORD=postgres-database-password
SUBNET=0
POSTGRES_VERSION=10.6
48 changes: 39 additions & 9 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
#!/bin/bash -eux

PG_PASSWORD=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;`

echo "DISCOURSE_SMTP_ADDRESS=${MAIL_HOST}" > .env
echo "DISCOURSE_SMTP_USER_NAME=${MAIL_USER}" >> .env
echo "DISCOURSE_SMTP_PASSWORD=${MAIL_PASS}" >> .env
echo "DISCOURSE_DB_PASSWORD=${PG_PASSWORD}" >> .env
echo "POSTGRES_PASSWORD=${PG_PASSWORD}" >> .env
# https://stackoverflow.com/questions/19331497/set-environment-variables-from-file-of-key-pair-values#20909045
# clear enviromnet variables listed in .env
unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)
# load .env.
export $(grep -v '^#' .env | xargs -d '\n')
export $(grep -v '^#' .env | xargs -0)
# https://stackoverflow.com/questions/19331497/set-environment-variables-from-file-of-key-pair-values#20909045


if [ -z ${VIRTUAL_HOST+x} ]; then
echo -n "Enter VIRTUAL_HOST: "; read VIRTUAL_HOST ; else
echo "VIRTUAL_HOST is set to '$VIRTUAL_HOST'"; fi

if [ -z ${DISCOURSE_SMTP_ADDRESS+x} ]; then
echo -n "Enter DISCOURSE_SMTP_ADDRESS: "; read DISCOURSE_SMTP_ADDRESS ; else
echo "DISCOURSE_SMTP_ADDRESS is set to '$DISCOURSE_SMTP_ADDRESS'"; fi

if [ -z ${DISCOURSE_SMTP_USER_NAME+x} ]; then
echo -n "Enter DISCOURSE_SMTP_USER_NAME: "; read DISCOURSE_SMTP_USER_NAME ; else
echo "DISCOURSE_SMTP_USER_NAME is set to '$DISCOURSE_SMTP_USER_NAME'"; fi

if [ -z ${DISCOURSE_SMTP_PASSWORD+x} ]; then
echo -n "Enter DISCOURSE_SMTP_PASSWORD: "; read DISCOURSE_SMTP_PASSWORD ; else
echo "DISCOURSE_SMTP_PASSWORD is set to '$DISCOURSE_SMTP_PASSWORD'"; fi

if [ -z ${DISCOURSE_DB_PASSWORD+x} ]; then
# https://unix.stackexchange.com/a/217276/111699 handle tr: Illegal byte sequence on Mac OSX.
DISCOURSE_DB_PASSWORD=$(perl -pe 'binmode(STDIN, ":bytes"); tr/A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+=//dc;' < /dev/urandom | head -c 32 ; echo); else
echo "DISCOURSE_DB_PASSWORD is set to '$DISCOURSE_DB_PASSWORD'"; fi

echo "VIRTUAL_HOST=${VIRTUAL_HOST}" > .env
echo "DISCOURSE_SMTP_ADDRESS=${DISCOURSE_SMTP_ADDRESS}" >> .env
echo "DISCOURSE_SMTP_USER_NAME=${DISCOURSE_SMTP_USER_NAME}" >> .env
echo "DISCOURSE_SMTP_PASSWORD=${DISCOURSE_SMTP_PASSWORD}" >> .env
echo "DISCOURSE_DB_PASSWORD=${DISCOURSE_DB_PASSWORD}" >> .env
echo "POSTGRES_PASSWORD=${DISCOURSE_DB_PASSWORD}" >> .env
echo "SUBNET=${SUBNET:-0}" >> .env
echo "POSTGRES_VERSION=10.6" >> .env

mkdir -p ./data/{assets,uploads,backups,redis,postgres}

chown -R 1000:1000 ./data/
chown -R 1000:1000 ./data || true # || true handles if chown -R 1000:1000 fails on Mac OSX

VIRTUAL_HOST=${URL} docker-compose run app bash -c "sleep 60 && bundle exec rake maxminddb:get db:migrate assets:precompile"
VIRTUAL_HOST=${URL} docker-compose run app bash -c "rake admin:create"
VIRTUAL_HOST=${VIRTUAL_HOST} docker-compose run app bash -c "sleep 60 && bundle exec rake maxminddb:get db:migrate assets:precompile"
VIRTUAL_HOST=${VIRTUAL_HOST} docker-compose run app bash -c "bundle exec rake admin:create"

echo "!!!Configure notification email in discourse settings!!!!!!"