mikeymicrophone / commissulator

Commissulator is a set of tools that help Real Estate Agents working with Citi Pads in Manhattan streamline their paperwork.
Other
3 stars 4 forks source link

Establish pattern for creating personalized development environment. #3

Open mikeymicrophone opened 5 years ago

mikeymicrophone commented 5 years ago

Commissulator uses the gem rails-env-credentials to enable storage of auth tokens in per-environment encrypted files which are committed to the repo. To decrypt a set of credentials, a master key for that environment would have to be shared (NOT via the repo).

It would, most likely, be plausible to share the development environment's key. One reason for not doing so is that the data set of clients, deals, and agents is expected to be mirrored in both Commissulator and Follow Up Boss. If that account was shared with 5 developers, then each one might have local agents and clients the others didn't have. Those would be pushed to Follow Up Boss, and then the other developers would be accessing a FUB account that included data not in their local environments. That might not cause any actual problems, and it might actually carry lots of benefits for expedient development, but at this juncture we're going to experiment with using separate development environments, mostly to see how well it will work.

Begin by copying the file config/environments/development.rb into a new file in that same directory (you could name it development-cire.rb or something such as that). This can be committed to the repo although in the future it might be pertinent to use gitignore on such files. You will then use rails-env-credentials to generate your credential file and its master key as described here. https://github.com/sinsoku/rails-env-credentials#other-environments-support

Edit the credentials file so it looks like so.

aws:
  access_key_id: t
  secret_access_key: t

sending_email:
  username: commissulator.development
  password: t

follow_up_boss:
  api_key: t
  subdomain: t

google:
  client_id: t.apps.googleusercontent.com
  client_secret: t

contactually:
  application_id: t
  secret: t
  token: t

microsoft:
  application_id: t
  public_key: t
  secret: https://stackoverflow.com/questions/52881340/how-does-one-open-or-view-the-private-key-delivered-from-the-microsoft-applicati
  password: t

rollbar:
  access_token: t

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: t

Then commit the environment file and the credential file to a branch on your fork of the repo. Send me the master key via iMessage and I'll update the file with the credentials you'll need to get the app running.

mikeymicrophone commented 5 years ago

Follow these steps to prepare your development environment.

  1. Choose a code word for your environment. It should be fun, motivating, simple to type, possible to say, and not personal. You might end up typing it a lot or using it as a tag for your tickets. Other developers might need to access it, and will probably see it in the repo. A random word is fine as long as you like it. Contact me if you need help picking a code word. It's an important step.
  2. Create an environment file by copying config/environments/development.rb into a file named development_ENV_CODE_WORD.rb, where you use your environment code word as that second part. So, for instance, a possible filename would be developent_orchard.rb.
  3. Generate a credentials file and a master encryption key for your environment with this command.
    EDITOR=vi rails env_credentials:edit -e development_orchard

    In place of 'orchard', use your code word. This will create config/credentials-development_orchard.yml.enc and /config/master-development_orchard.key, while adding the latter to .gitignore. You should replace the contents of the file you are editing with the credentials shown in the comment above this.

  4. Edit config/database.yml and add a db configuration for your environment. Postgresql is strongly recommended. If that platform isn't plausible for you, be aware that it may interfere with your ability to contribute. However, you are welcome to try.
  5. Prepare your database by specifying your environment in the commands
    RAILS_ENV=development_orchard rails db:create
    RAILS_ENV=development_orchard rails db:migrate

    where, again, 'orchard' should be replaced with your code word.

  6. You may want to set the value of RAILS_ENV in a durable way so that it doesn't need to be explicitly typed while performing command-line processes or starting Rails. Expedient ways to do so can be discussed below.
  7. Commit the .yml.enc file and push to GitHub so I can add credentials to it. You will also provide some of the credentials yourself, as shown below.
  8. Deliver the master key to me in a secure way such as iMessage or a Facebook message in Secret mode.
mikeymicrophone commented 5 years ago

One way to select the environment would be to use a local .bashrc file that only sets the value while you are in that directory (I am assuming you don't want to use this Rails env systemwide because you probably have other Rails projects that you'd just run in development mode).

Here's one way to do so. It adds a rule to your systemwide .bashrc that repeatedly scans your other directories for local .bashrcs when you move into a new directory. https://superuser.com/questions/915703/is-there-a-folder-specific-bashrc-or-bash-profile/915761#915761 Here's another way. https://www.pmg.com/blog/how-to-set-up-directory-specific-bash-or-other-shell-environments/

Another option would be to set a systemwide environment variable for COMMISSULATOR_ENVIRONMENT and then make Rails load from that, or copy its value to RAILS_ENV.

mikeymicrophone commented 5 years ago

In terms of credentials that are really necessary, I'm not seeing much. I think Rollbar will be important if we want to view our own errors instead of theirs. I tentatively like the idea of using Rollbar in development so I can jump into the details of the ongoing dev process.

mikeymicrophone commented 5 years ago

I used AWS to create a policy that has access to just one bucket. We'll see if that worked.