From 7566352327d1430f74f2c8da45930f129b28e48d Mon Sep 17 00:00:00 2001 From: Brittany Greaner Date: Mon, 22 May 2023 15:35:47 -0500 Subject: [PATCH 1/4] Brewfile for dependency management *Summary of changes* We're looking at adding a dependency soon, which could cause some issues with local development for folks if they didn't know they need to manually install it. We thought adding a `Brewfile` and having the setup script run `brew bundle` would help mitigate the difficulties of that change. There's a bonus in that it's self documenting too! It would also: - make initial setup for new developers much more straightforward - make future changes to dependencies easier to manage - prevents a mixture of dependencies installed in different ways (for instance, I think when I initially set things up I ended up with one version of postgres downloaded manually from the doc-linked site, and another via homebrew) Notes: - As pointed out by @pauldoomgov, we use [postgres@13 in production](https://github.com/18F/identity-devops/blob/33ba02736b37f3a79c50479892a03c6f3e920041/terraform/app/rds-variables.tf#L82), so it would be good to encourage use of 13 locally. The method I chose to try and enforce this was using `brew services stop --all` before starting the services we want (where I specify 13). - I tried various combinations of having these dependencies installed / uninstalled before running `make setup` and the script seems to still work. But I don't have a machine without MacOS to test on to make sure it works for everyone. - While making relevant doc changes, I also fixed up some syntax for readability / easy re-ordering of steps --- .gitignore | 1 + Brewfile | 6 ++++ bin/setup | 9 ++++++ docs/local-development.md | 63 ++++++++++++++++++++------------------- 4 files changed, 48 insertions(+), 31 deletions(-) create mode 100644 Brewfile diff --git a/.gitignore b/.gitignore index efcb4365403..18d6f95f197 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,7 @@ Vagrantfile package-lock.json browsers.json +Brewfile.lock.json saml_*.txt saml_*.shr diff --git a/Brewfile b/Brewfile new file mode 100644 index 00000000000..fae834dac18 --- /dev/null +++ b/Brewfile @@ -0,0 +1,6 @@ +brew 'postgresql@13' +brew 'redis' +brew 'node@16' +brew 'yarn' +brew 'openssl@1.1' +cask 'chromedriver' diff --git a/bin/setup b/bin/setup index 0b637303757..f20ed2736ed 100755 --- a/bin/setup +++ b/bin/setup @@ -50,11 +50,20 @@ Dir.chdir APP_ROOT do run "cp pwned_passwords/pwned_passwords.txt.sample pwned_passwords/pwned_passwords.txt" puts "\n== Installing dependencies ==" + brew_installed = system "brew -v 2>&1" + run "brew bundle" if brew_installed run "gem install bundler --conservative" run 'gem install foreman --conservative && gem update foreman' run "bundle check || bundle install --without deploy production" run "yarn install" + puts "\n== Stopping running services to ensure clean start ==" + run "brew services stop --all" + + puts "\n== Starting services ==" + run "brew services start redis" if brew_installed + run "brew services start postgresql@13" if brew_installed + puts "\n== Preparing database ==" run 'make clobber_db' diff --git a/docs/local-development.md b/docs/local-development.md index e3acf25b0d6..e99c86f61f2 100644 --- a/docs/local-development.md +++ b/docs/local-development.md @@ -7,51 +7,52 @@ This installation method is meant for those who are familiar with setting up loc We recommend using [Homebrew](https://brew.sh/), [rbenv](https://github.com/rbenv/rbenv), [nvm](https://github.com/nvm-sh/nvm) or other version management tooling to install the below dependencies; while we don't anticipate changing these frequently, this will ensure that you will be able to easily switch to different versions as needed. ### Dependencies -1. To start, make sure you have the following dependencies installed and a working development environment: -- Ruby ~> 3.2.0 -- [PostgreSQL](http://www.postgresql.org/download/) -- [Redis 7+](http://redis.io/) -- [Node.js v16](https://nodejs.org) -- [Yarn](https://yarnpkg.com/en/) -- [chromedriver](https://formulae.brew.sh/cask/chromedriver) +Installing the packages differs slightly if you're on a macOS or a different OS. -2. You will need to install openssl version 1.1: +If using macOS: -- Run `brew install openssl@1.1` +1. Install [rbenv](https://github.com/rbenv/rbenv) (lets you install and switch between different versions of Ruby) +1. Install Ruby. Choose the version [in the `.ruby-version` file](../.ruby-version) +1. Skip to the [set up local environment section](#set-up-local-environment). Your other dependencies will be installed in that step. -3. Test that you have Postgres and Redis running. +If not using macOS: - For example, if you've installed with Homebrew, you can start the services like this: +1. To start, make sure you have the following dependencies installed and a working development environment: - ``` - $ brew services start redis - $ brew services start postgresql - ``` + - [rbenv](https://github.com/rbenv/rbenv) (lets you install and switch between different versions of Ruby) + - Ruby. Choose the version [in the `.ruby-version` file](../.ruby-version) + - [PostgreSQL](http://www.postgresql.org/download/) + - [Redis 7+](http://redis.io/) + - [Node.js v16](https://nodejs.org) + - [Yarn](https://yarnpkg.com/en/) + - [chromedriver](https://formulae.brew.sh/cask/chromedriver) - To confirm the services are running properly, run: - ``` - $ brew services list - ``` +1. You will need to install openssl version 1.1: -4. Run the following command to set up your local environment: + - Run `brew install openssl@1.1` - ``` - $ make setup - ``` +1. Test that you have Postgres and Redis running. - This command copies sample configuration files, installs required gems - and sets up the database. Check out our Makefile commands to learn more about what this command does: https://github.com/18F/identity-idp/blob/main/Makefile +1. Continue to the [set up local environment section](#set-up-local-environment). - Note: If you didn't explicitly install `openssl@1.1` in Step 2 above and you use a M1 Mac, you may see an error on this step. Homebrew works differently on a M1 Mac, so specifying the version is necessary for the make script to work, but may still work on x86. +### Set up local environment -5. Now that you have you have everything installed, you can run the following command to start your local server: +1. Run the following command to set up your local environment: - ``` - $ make run - ``` + ``` + $ make setup + ``` + + This command copies sample configuration files, installs required gems and brew packages (if using macOS), and sets up the database. Check out our Makefile commands to learn more about what this command does: https://github.com/18F/identity-idp/blob/main/Makefile + +1. Now that you have you have everything installed, you can run the following command to start your local server: + + ``` + $ make run + ``` - You should now be able to go to open up your favorite browser, go to `localhost:3000` and see your local development environment running. + You should now be able to go to open up your favorite browser, go to `localhost:3000` and see your local development environment running. ### Running tests locally From 77f6a4f82ac8caf57d27e364afc83a13042b2aab Mon Sep 17 00:00:00 2001 From: Brittany Greaner Date: Tue, 30 May 2023 11:52:01 -0500 Subject: [PATCH 2/4] changelog: Internal, Developer setup, Brewfile for dependency management From 624081cae555756505124fcbbf32d169cc43a665 Mon Sep 17 00:00:00 2001 From: Brittany Greaner Date: Tue, 30 May 2023 11:58:50 -0500 Subject: [PATCH 3/4] Fixup: suggestion by Zach M that I forgot to apply --- docs/local-development.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/local-development.md b/docs/local-development.md index e99c86f61f2..175d0bd6a86 100644 --- a/docs/local-development.md +++ b/docs/local-development.md @@ -44,7 +44,7 @@ If not using macOS: $ make setup ``` - This command copies sample configuration files, installs required gems and brew packages (if using macOS), and sets up the database. Check out our Makefile commands to learn more about what this command does: https://github.com/18F/identity-idp/blob/main/Makefile + This command copies sample configuration files, installs required gems and brew packages (if using macOS), and sets up the database. Check out our [Makefile commands](../Makefile) to learn more about what this command does. 1. Now that you have you have everything installed, you can run the following command to start your local server: From 46531ebdf20686a969fb33c7b9d8c2cb0d520364 Mon Sep 17 00:00:00 2001 From: Brittany Greaner <35475380+night-jellyfish@users.noreply.github.com> Date: Tue, 30 May 2023 12:54:00 -0500 Subject: [PATCH 4/4] Update bin/setup Co-authored-by: Andrew Duthie --- bin/setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/setup b/bin/setup index f20ed2736ed..e8431e847b2 100755 --- a/bin/setup +++ b/bin/setup @@ -58,7 +58,7 @@ Dir.chdir APP_ROOT do run "yarn install" puts "\n== Stopping running services to ensure clean start ==" - run "brew services stop --all" + run "brew services stop --all" if brew_installed puts "\n== Starting services ==" run "brew services start redis" if brew_installed