Skip to content

Commit

Permalink
Add devenv environment for ruby 3.2 and postgres 10
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Feb 3, 2024
1 parent 6e9258a commit e4c7a37
Show file tree
Hide file tree
Showing 6 changed files with 444 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0="

use devenv
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2
119 changes: 119 additions & 0 deletions devenv.README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Purpose

Using a devenv enviroment from https://devenv.sh/ should enable new and seasoned developers to bring up a running local ODDB-webbrowser by typing only a few lines in a command shell.

But downloading all the components and backup of databases will take some times as several gigabytes are shuffled around

2013 and earlier it took new developers a few days to bring up a test environment.

# Decisions

We use the Nixos packages for the various ruby version from https://github.com/bobvanderlinden/nixpkgs-ruby (seen devenv.yaml).

We define the used ruby-version in the file [.ruby-version](./ruby-version) and use an expression like `3.2` to get the latest version in this series, e.g 3.2.3 at the moment

We use the postgreSQL version as running under ch.oddb.org. As postgres 10 is no longer supported in nixos-23.11 we added an input `nixpkgs-old`using
`NixOS/nixpkgs/nixos-22.05`. See file [devenv.yaml](./devenv.yaml), where we also define an pg upgrade shell script `pgupgrade-pg-cluster` if you want to upgrade your database from postgres 10 to the latest postgres version 16.

We document here the devenv environment for the components yus, migel and oddb.org. We assume below here that all stuff is placed under `/opt/path_to_oddb` where you need about GB to run.

We use a separate postgres server for the three databases envolved. Each is listening to a different port. This allows us to test a new postgres version for each of the three databases (we use port 5435 for yus, 5434 for migel and 5433 for oddb.org)

The .ruby-version file in each git checkout defines the Ruby version being used.

A unzipped backup of each of the databases yus, migel and ch_oddb must be placed into `/opt/path_to_oddb`, where they are references in each `devenv.nix`file via a relativ path to `../<name>.backup`.

The applications must be started manually and should be similar to their invocation in their /services/*/run. Eg. converting the relevant line from `/services/yus` is `sudo -u apache bundle-320 exec ruby-320 bin/yusd` and gives us
`bundle exec ruby bin/yusd`

The `bundle install` must be called manually (for unknown reasons sometimes even twice.)

It is your responsability that the port (default 5433) used for the postgres database is in sync between this file (devenv.nix) and [etc/db_connection.rb](./etc/db_connection.rb).

# Setup

## Installing and bringing up a yus server

### Installing
Execute in a command shell the following command
* `mkdir /opt/path_to_oddb` and assure that the user you are has
* `cd /opt/path_to_oddb`
* `git clone [email protected]:zdavatz/yus.git`
* `cd yus`
You will get an error like ``direnv: error /opt/path_to_oddb/yus/.envrc is blocked. Run `direnv allow` to approve its content``
* `direnv allow`
* `devenv up`

### Running unit tests

Now you are able to open a new command window and run there the unit tests for yus by executing the following commands
* `cd /opt/path_to_oddb/yus`
* `devenv shell`
* `bundle install`
* `bundle exec rake test`

### Running the yus server

Now you are confident that the yus server will work in a new command window. Execute the following commands
* `cd /opt/path_to_oddb/yus`
* `bundle install`
* `bundle exec ruby bin/yusd`

## Installing and bringing up a migel server

### Installing

Same as in previous example, but replace all occurrences from yus by migel

### Running unit tests

Same as in under yus, but replace all occurrences from yus by oddb.org. But the command for executing tests is

* `bundle exec rake spec`

### Running the migel server

Now you are confident that the migel server will work in a new command window. Execute the following commands
* `cd /opt/path_to_oddb/migel`
* `bundle install`
* `bundle exec ruby bin/migeld`


## Installing and bringing up a ch-oddb web server

### Installing

Same as in under yus, but replace all occurrences from yus by oddb.org. But be aware that the `devenv up` command will take around 12 minutes to complete (depends heavily on your machine).
Seeing the following `psql:22:00-postgresql_database-ch_oddb-backup:787: ERROR: tables declared WITH OIDS are not supported`

### Running unit tests

Same as in under yus, but replace all occurrences from yus by oddb.org. but the command for executing tests is

* `bundle exec ruby test/suite.rb`

These tests take a long time, about 20 minutes under github.

### Running the ch-oddb web server

Now you are confident that the ch-oddb web server will work in a new command window. Execute the following commands
* `cd /opt/path_to_oddb/oddb.org`
* `bundle install`
* `ulimit -v 10240000; bundle exec rackup --host 127.0.0.1 -p 8012 --quiet # or use --debug to see some more information`

Now you should be able to point your browser to http://127.0.0.1:8012.

# TODO:

The following steps could be intergrated into the devenv.nix
* `bundle install`
* Use the downloaded bz2 backup file directly
* Always use `bundle exec rake test` to execute the tests. Instead of checking always `.github/workflows/ruby.yml`

# Notes

* Niklaus uses the fish shell from https://fishshell.com/
* Niklaus is working on a https://ch.starlabs.systems/pages/starbook laptop having 32 GB of RAM and a 2TB SSD-HD
* Nixos 23.11 from https://nixos.org/ installed
* If you want to drop into the ruby debugger just insert a line `require 'debug'; debugger`
* If you want to reload a database dump, just stop the process up job and call `rm -rfv .devenv/state/postgres`
245 changes: 245 additions & 0 deletions devenv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1706018268,
"narHash": "sha256-d24+re0t8b6HYGzAPZCIJed85n23RUFXQa2yuHoW0uQ=",
"owner": "cachix",
"repo": "devenv",
"rev": "ad0ae333b210e31237e1fc4a7ddab71a01785add",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1703887061,
"narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1706718339,
"narHash": "sha256-S+S97c/HzkO2A/YsU7ZmNF9w2s7Xk6P8dzmfDdckzLs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "53fbe41cf76b6a685004194e38e889bc8857e8c2",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-old": {
"locked": {
"lastModified": 1685573264,
"narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "380be19fbd2d9079f677978361792cb25e8a3635",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-ruby": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1705649692,
"narHash": "sha256-c5zBpn+6DptzX1Gx24G9BRQO2BJykmF9lt1wyL9AbYY=",
"owner": "bobvanderlinden",
"repo": "nixpkgs-ruby",
"rev": "a51f1dd843474eae34f764b1bb5c2e2621cf298f",
"type": "github"
},
"original": {
"owner": "bobvanderlinden",
"repo": "nixpkgs-ruby",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1704874635,
"narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1706424699,
"narHash": "sha256-Q3RBuOpZNH2eFA1e+IHgZLAOqDD9SKhJ/sszrL8bQD4=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "7c54e08a689b53c8a1e5d70169f2ec9e2a68ffaf",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"nixpkgs": "nixpkgs",
"nixpkgs-old": "nixpkgs-old",
"nixpkgs-ruby": "nixpkgs-ruby",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
Loading

0 comments on commit e4c7a37

Please sign in to comment.