Skip to content
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
15 changes: 14 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ Our Docker setup supports custom build configurations for the uwsgi container vi

To use a custom build config, change the `CLIENT_DOCKERFILE` variable in the .env file that is automatically created by [local-setup.sh](/docker/local-setup.sh) in the project root.

### Environment

The following lists environment variables specific to deploying QPixel via Docker:

| Name | Value | Required? | Default | Description |
| -------------------------- | ---------- | --------- | ------- | ----------------------------------------------------------------------------------- |
| `COMMUNITY_ADMIN_USERNAME` | `<string>` | yes* | - | Username of the admin user on the default community. Only required on database init |
| `COMMUNITY_ADMIN_PASSWORD` | `<string>` | yes* | - | Password of the admin user on the default community. Only required on database init |
| `COMMUNITY_ADMIN_EMAIL` | `<string>` | yes* | - | Email of the admin user on the default community. Only required on database init |
| `COMMUNITY_NAME` | `<string>` | yes* | - | Name of the default community to create. Only required on database init |
| `LOCAL_DEV_PORT` | `<string>` | no | `3000` | Port or port range on the host to map the server's port `3000` in the container to |

## 2. Database File
Ensure `config/database.yml` has the username and password as defined in [docker/env](docker/env) file. The `config/database.yml` should already be gitignored.

Expand Down Expand Up @@ -96,7 +108,8 @@ and see the interface.

![img/interface.png](../img/interface.png)

You can then click "Sign in" to login with what you defined for `$COMMUNITY_ADMIN_EMAIL` and `$COMMUNITY_ADMIN_PASSWORD`. Importantly, your password must be 6 characters or longer, otherwise the user won't be created.
You can then click "Sign in" to login with what you defined for `COMMUNITY_ADMIN_EMAIL` and `COMMUNITY_ADMIN_PASSWORD`.
Importantly, your password must be 6 characters or longer, otherwise the user won't be created.

### Custom build configs

Expand Down
30 changes: 22 additions & 8 deletions docker/create_admin_and_community.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
community_name = ENV.fetch('COMMUNITY_NAME', nil)
username = ENV.fetch('COMMUNITY_ADMIN_USERNAME', nil)
password = ENV.fetch('COMMUNITY_ADMIN_PASSWORD', nil)
email = ENV.fetch('COMMUNITY_ADMIN_EMAIL', nil)
port = ENV.fetch('LOCAL_DEV_PORT', '3000')

unless [community_name, username, password, email].all?(&:present?)
puts 'COMMUNITY_NAME is required' unless community_name.present?
puts 'COMMUNITY_ADMIN_USERNAME is required' unless username.present?
puts 'COMMUNITY_ADMIN_PASSWORD is required' unless password.present?
puts 'COMMUNITY_ADMIN_EMAIL is required' unless email.present?
exit 1
end

# 1. Create the community
community_name = ENV['COMMUNITY_NAME'] || 'Dinosaur Community'
Community.create(name: community_name, host: "localhost:#{ENV.fetch('LOCAL_DEV_PORT', nil)}")
Community.create!(name: community_name, host: "localhost:#{port}")
Rails.cache.clear

# 2. Create the admin user, ensure doesn't require confirmation
username = ENV['COMMUNITY_ADMIN_USERNAME'] || 'admin'
password = ENV['COMMUNITY_ADMIN_PASSWORD'] || 'password'
email = ENV['COMMUNITY_ADMIN_EMAIL'] || 'codadict@noreply.com'

User.create(username: username, password: password, email: email, is_global_admin: true, is_global_moderator: true,
staff: true, confirmed_at: DateTime.now)
User.create!(username: username,
password: password,
Comment thread
Oaphi marked this conversation as resolved.
Dismissed
email: email,
is_global_admin: true,
is_global_moderator: true,
staff: true,
confirmed_at: DateTime.now)
3 changes: 0 additions & 3 deletions docker/dummy.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ MYSQL_ROOT_PASSWORD=qpixel
MYSQL_DATABASE=qpixel
MYSQL_USER=qpixel
MYSQL_PASSWORD=qpixel
COMMUNITY_ADMIN_USERNAME=admin
COMMUNITY_ADMIN_PASSWORD=password
COMMUNITY_ADMIN_EMAIL=admin@noreply.com
Loading