automate a bit with bin/setup

This commit is contained in:
Peter Bhat Harkins 2023-12-06 08:50:04 -06:00
parent 35925eb0e1
commit 1f4547d2b9
3 changed files with 25 additions and 31 deletions

View File

@ -27,7 +27,7 @@ jobs:
with: with:
bundler-cache: true bundler-cache: true
- name: Prepare database - name: Prepare database
run: ./bin/rails db:schema:load && ./bin/rails db:migrate run: ./bin/rails db:prepare
- name: Run tests - name: Run tests
run: | run: |
bundle exec rspec bundle exec rspec

View File

@ -20,7 +20,7 @@ Please see the [CONTRIBUTING](https://github.com/lobsters/lobsters/blob/master/C
If you have questions, there is usually someone in [our chat room](https://lobste.rs/chat) who's familiar with the code. If you have questions, there is usually someone in [our chat room](https://lobste.rs/chat) who's familiar with the code.
#### Initial setup #### Development setup
Use the steps below for a local install or Use the steps below for a local install or
[lobsters-ansible](https://github.com/lobsters/lobsters-ansible) for our production deployment config. [lobsters-ansible](https://github.com/lobsters/lobsters-ansible) for our production deployment config.
@ -41,21 +41,7 @@ There's an external project [docker-lobsters](https://github.com/utensils/docker
Ubuntu: sudo apt-get install nodejs Ubuntu: sudo apt-get install nodejs
OSX: brew install nodejs OSX: brew install nodejs
``` ```
* Create a MariaDB (other DBs supported by ActiveRecord may work, only MySQL and
* Run Bundler to install/bundle gems needed by the project:
```sh
lobsters$ bundle
```
* If when installing the `mysql2` gem on macOS, you see
`ld: library not found for -l-lpthread` in the output, see
[this solution](https://stackoverflow.com/a/44790834/204052) for a fix.
You might also see `ld: library not found for -lssl` if you're using
macOS 10.4+ and Homebrew `openssl`, in which case see
[this solution](https://stackoverflow.com/a/39628463/1042144).
* Create a MySQL (other DBs supported by ActiveRecord may work, only MySQL and
MariaDB have been tested) database, username, and password and put them in a MariaDB have been tested) database, username, and password and put them in a
`config/database.yml` file. You will also want a separate database for `config/database.yml` file. You will also want a separate database for
running tests: running tests:
@ -80,27 +66,33 @@ running tests:
password: *test_password* password: *test_password*
``` ```
* Load the schema into the new database: * Run `bin/setup` to install dependencies and set up db
```sh ```sh
lobsters$ rails db:schema:load lobsters$ bin/setup
``` ```
* If when installing the `mysql2` gem on macOS, you see
`ld: library not found for -l-lpthread` in the output, see
[this solution](https://stackoverflow.com/a/44790834/204052) for a fix.
You might also see `ld: library not found for -lssl` if you're using
macOS 10.4+ and Homebrew `openssl`, in which case see
[this solution](https://stackoverflow.com/a/39628463/1042144).
* On your production server, copy `config/initializers/production.rb.sample` * On your production server, copy `config/initializers/production.rb.sample`
to `config/initalizers/production.rb` and customize it with your site's to `config/initalizers/production.rb` and customize it with your site's
`domain` and `name`. (You don't need this on your dev machine). `domain` and `name`. (You don't need this on your dev machine).
* Seed the database to create an initial administrator user, the `inactive-user`, and at least one tag: * On your personal computer, you probably want to add some sample data.
```sh
lobsters$ rails db:seed
```
* On your personal computer, you can add some sample data and run the Rails server in development mode.
You should be able to login to `http://localhost:3000` with your new `test` user:
```sh ```sh
lobsters$ rails fake_data lobsters$ rails fake_data
```
* Run the Rails server in development mode.
You should be able to login to `http://localhost:3000` with your new `test` user:
```sh
lobsters$ rails server lobsters$ rails server
``` ```

View File

@ -22,12 +22,14 @@ FileUtils.chdir APP_ROOT do
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
# end # end
puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
puts "\n== Removing old logs and tempfiles ==" puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear' system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server ==" puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
puts "\n== Restarting application server if running =="
system! 'bin/rails restart' system! 'bin/rails restart'
puts "\n== You probably want to run 'rails fake_data' to have realistic data in dev"
end end