]> cat aescling's git repositories - mastodon.git/commitdiff
[nanobox] Adjustments for Nanobox development (#3295)
authorDaniel Hunsaker <danhunsaker@gmail.com>
Mon, 29 May 2017 15:59:18 +0000 (09:59 -0600)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 29 May 2017 15:59:18 +0000 (17:59 +0200)
Because Nanobox doesn't run data components in the same container as the code, there are a few tweaks that need to be made in the configuration to get WebPack to work properly in development mode.

The same differences lead to needing to use `DATABASE_URL` by default in the `.env` file for Rails to work correctly.

Limitations of our `.env` loader for Node.js mean the `.env` file needs to be compiled everywhere in order to work, so we compile it in development, now, too. Also, all the `.env.production` tweaks have been consolidated into a single command.

Finally, since Nanobox actually creates the database when it sets up the database server, using the existence of the database alone to determine whether to migrate or setup is insufficient. So we add a condition to `rake db:migrate:setup` to check whether any migrations have run - if the database doesn't exist yet, `db:setup` will be called; if it does, but no migrations have been run, `db:migrate` and `db:seed` are called instead (the same basic idea as what `db:setup` does, but it skips `db:create`, which will only cause problems with an existing DB); otherwise, only `db:migrate` is called.

None of these changes should affect development, and all are designed not to interfere with existing behaviors in other environments.

.env.nanobox
boxfile.yml
config/webpack/configuration.js
config/webpack/development.server.js
lib/tasks/db.rake

index 4a89e0e41fc9a3940f98006d0cd6b9978e8a3ba5..73abefdc657537d627e93f5506aec37004a1faa1 100644 (file)
@@ -11,6 +11,8 @@ DB_NAME=gonano
 DB_PASS=$DATA_DB_PASS
 DB_PORT=5432
 
+DATABASE_URL=postgresql://$DATA_DB_USER:$DATA_DB_PASS@$DATA_DB_HOST/gonano
+
 # Federation
 # Note: Changing LOCAL_DOMAIN or LOCAL_HTTPS at a later time will cause unwanted side effects.
 # LOCAL_DOMAIN should *NOT* contain the protocol part of the domain e.g https://example.com.
index 65f5f6c8cd6e3647f0ecc9a2dce48b71f7dd5ca5..2fa3fb9ffa9c2c0933f4a5772a79a84d389adfb0 100644 (file)
@@ -31,7 +31,7 @@ run.config:
     - yarn.lock
 
   extra_steps:
-    - cp .env.nanobox .env
+    - envsubst < .env.nanobox > .env
     - gem install bundler
     - bundle config build.nokogiri --with-iconv-dir=/data/ --with-zlib-dir=/data/
     - bundle config build.nokogumbo --with-iconv-dir=/data/ --with-zlib-dir=/data/
@@ -43,9 +43,8 @@ run.config:
 deploy.config:
   extra_steps:
     - NODE_ENV=production bundle exec rake assets:precompile
-    - "[ -r /app/.env.production ] || sed 's/LOCAL_HTTPS=.*/LOCAL_HTTPS=true/i' /app/.env.nanobox > /app/.env.production"
   transform:
-    - envsubst < /app/.env.production > /tmp/.env.production && mv /tmp/.env.production /app/.env.production
+    - "sed 's/LOCAL_HTTPS=.*/LOCAL_HTTPS=true/i' /app/.env.nanobox | envsubst > /app/.env.production"
     - |-
         if [ -z "$LOCAL_DOMAIN" ]
         then
index 922e8c517ea5acaa20c2cc5547d72c7fa8848304..2a54080cf948a782a5ca5228db529397603842c0 100644 (file)
@@ -12,7 +12,7 @@ const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml
 
 // Compute public path based on environment and CDN_HOST in production
 const ifHasCDN = env.CDN_HOST !== undefined && env.NODE_ENV === 'production';
-const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`;
+const devServerUrl = `http://${env.LOCAL_DOMAIN || devServer.host}:${devServer.port}/${paths.entry}/`;
 const publicUrl = ifHasCDN ? `${env.CDN_HOST}/${paths.entry}/` : `/${paths.entry}/`;
 const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl;
 
index 296df150467f2452c238a47ba75b37aef05b0813..4e11df4cb3a1ace2b79dade985ac2790ba188760 100644 (file)
@@ -1,13 +1,14 @@
 // Note: You must restart bin/webpack-dev-server for changes to take effect
 
 const { resolve } = require('path');
+const { env } = require('process');
 const merge = require('webpack-merge');
 const devConfig = require('./development.js');
 const { devServer, publicPath, paths } = require('./configuration.js');
 
 module.exports = merge(devConfig, {
   devServer: {
-    host: devServer.host,
+    host: env.LOCAL_DOMAIN ? '0.0.0.0' : devServer.host,
     port: devServer.port,
     headers: { "Access-Control-Allow-Origin": "*" },
     compress: true,
index a1211f0973d8b52398c515d3cdb07d4d505c4fd8..7a055bf2563db8dec8b35d604a2db83483fe5e95 100644 (file)
@@ -5,7 +5,10 @@ namespace :db do
     desc 'Setup the db or migrate depending on state of db'
     task setup: :environment do
       begin
-        ActiveRecord::Base.connection
+        if ActiveRecord::Migrator.current_version.zero?
+          Rake::Task['db:migrate'].invoke
+          Rake::Task['db:seed'].invoke
+        end
       rescue ActiveRecord::NoDatabaseError
         Rake::Task['db:setup'].invoke
       else