Skip to content

Commit

Permalink
dx: reproducible local env (#257)
Browse files Browse the repository at this point in the history
* fix: run newest debian

Ran into an issue with Debian-10 on macOS M1 (although not clear if the
os/arch has anything to do with this), where the latest version of
Parcel tried to pull in Rust-based components that relied on libc 2.29
or higher. Unfortunately Debian 10 ships with libc 2.28, so this crashed
at runtime.

This should be enough to fix it.

* chore: add phpmyadmin

* chore: startup phpmyadmin with containers

* dx: add reproducible local environment for macOS

* chore: bump to safe mirage-crypto fork of sihl

* dx: all tests passing locally

* chore: format that last one file

* chore: restore setup.sh, hide esy.lock from diffs, and ignore in formatting

* docs: add esy instructions

* fix: use _one/_two prefix for tenant db names

fix(ci): use new env variable for first tenant db
fix(ci): we need both env vars now
fix(ci): move away from TENANT_TEST
  • Loading branch information
leostera authored Nov 17, 2023
1 parent 6112735 commit 9722ebb
Show file tree
Hide file tree
Showing 241 changed files with 17,464 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:lts AS node
FROM hadolint/hadolint:latest-alpine AS hadolint
FROM ocaml/opam:debian-10-ocaml-4.14
FROM ocaml/opam:debian-12-ocaml-4.14

USER root

Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"runServices": [
"dev",
"database-root",
"database-tenant"
// "adminer" // uncomment if adminer should run to see the database
"database-tenant",
"phpmyadmin"
],
"workspaceFolder": "/workspace",
"postCreateCommand": "/bin/bash .devcontainer/wait-for-database.sh -d db-root/test -d db-tenant/dev_zhaw -d db-tenant/test_econ .devcontainer/postCreate.sh",
Expand Down
11 changes: 11 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ services:
depends_on:
- database-root
- database-tenant

phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8082:80
environment:
- PMA_ARBITRARY=1
depends_on:
- database-root
- database-tenant

volumes:
opam:
Expand Down
19 changes: 17 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# all these settings are configured for the DevContainer by default. Use this example file to override the defaults.
ECON_PACKAGE_REGISTRY_READ_TOKEN=1234
DATABASE_URL_TENANT_TEST=mariadb://root:<password>@database-tenant:3306/test_econ
SIHL_ENV=development
VERSION=dev
PUBLIC_URL=http://localhost:3000

ECON_PACKAGE_REGISTRY_READ_TOKEN=<token>

DATABASE_URL=mariadb://root@0.0.0.0:3316/development
DATABASE_URL_TENANT_ONE=mariadb://root@0.0.0.0:3317/test_econ
DATABASE_URL_TENANT_TWO=mariadb://root@0.0.0.0:3317/test_zhaw

DATABASE_SKIP_DEFAULT_POOL_CREATION=true
DATABASE_CHOOSE_POOL=root
OPAMSOLVERTIMEOUT=180
EMAIL_RATE_LIMIT=100
MATCHER_MAX_CAPACITY=80
MATCHER_RUN=false

# Mail intercept
SMTP_SENDER=test@econ.uzh.ch
TEST_EMAIL=test@econ.uzh.ch

# Matcher service
Expand Down
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.sh text eol=lf
*.sh text eol=lf
esy.lock linguist-vendored linguist-generated
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ jobs:
uses: addnab/docker-run-action@v3
env:
DATABASE_URL: mariadb://root:${{ env.MYSQL_ROOT_PASSWORD }}@database-root:3306/${{ env.MYSQL_DATABASE }}
DATABASE_URL_TENANT_TEST: mariadb://root:${{ env.MYSQL_ROOT_PASSWORD }}@database-tenant:3306/${{ env.MYSQL_DATABASE }}
DATABASE_URL_TENANT_ONE: mariadb://root:${{ env.MYSQL_ROOT_PASSWORD }}@database-tenant:3306/${{ env.MYSQL_DATABASE }}
SIHL_ENV: test
SMTP_SENDER: test@econ.uzh.ch
TEST_EMAIL: test@econ.uzh.ch
with:
image: ocaml/opam:debian-10-ocaml-4.14
options: -v ${{ github.workspace }}:/app -w /app -e DATABASE_URL -e DATABASE_URL_TENANT_TEST -e TEST_EMAIL -e SMTP_SENDER -e SIHL_ENV -e EMAIL_RATE_LIMIT -e MATCHER_MAX_CAPACITY
options: -v ${{ github.workspace }}:/app -w /app -e DATABASE_URL -e DATABASE_URL_TENANT_ONE -e TEST_EMAIL -e SMTP_SENDER -e SIHL_ENV -e EMAIL_RATE_LIMIT -e MATCHER_MAX_CAPACITY
run: |
# Reclaim required directory permissions
sudo chown -R opam .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ocamlbuild working directory
_esy/
_build/
public/
guardian/
Expand Down
1 change: 1 addition & 0 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
esy.lock/**/*
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Follow the [Architecture](./doc/ARCHITECTURE.md) documentation.

## Development

A guide how to setup the project with devcontainers can be found [here](./.devcontainer/README.md).
A guide to setup the project with devcontainers can be found
[here](./.devcontainer/README.md). If you prefer to [run the project
locally](#running-locally-with-Esy), you can do that with [esy][esy].

The project executable can be run via command line `make sihl` and shows the information of the executable.

Expand All @@ -18,6 +20,18 @@ The project executable can be run via command line `make sihl` and shows the inf
1. Run development server `make dev`
1. See `pool/database/seed/seed_user.ml` for default users or `make sihl admin.create ...` (see [Application Commands](#application-commands)) to generate one

### Running locally with Esy

Esy is a reproducible package manager for OCaml with heavy emphasis on
usability. You can get it installed with `npm install --global esy`, and then
run `esy` inside the project.

Once `esy` finishes running, you can prefix any command with `esy ...` to
execute it within the project's sandbox, or you can start a new development
shell within it by running `esy shell`.

[esy]: https://esy.sh

### Commands

- `make install` - to install all the dependencies. Under the hood, `dune` is used for package management.
Expand Down
7 changes: 0 additions & 7 deletions default.nix

This file was deleted.

136 changes: 136 additions & 0 deletions esy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"dependencies": {
"@opam/alcotest-lwt": "*",
"@opam/canary": "*",
"@opam/caqti": "*",
"@opam/caqti-driver-mariadb": "*",
"@opam/caqti-lwt": "*",
"@opam/conf-libssl": "3",
"@opam/conformist": "0.8.1",
"@opam/containers": "3.12",
"@opam/containers-data": "3.12",
"@opam/cstruct": "*",
"@opam/dune": "*",
"@opam/guardian": "*",
"@opam/logs": "0.7.0",
"@opam/lwt": "5.7.0",
"@opam/lwt_ppx": "2.1.0",
"@opam/lwt_ssl": "1.2.0",
"@opam/mariadb": "*",
"@opam/ocaml-lsp-server": "*",
"@opam/ocamlformat": "0.26.1",
"@opam/mirage-crypto": "*",
"@opam/mirage-crypto-rng": "*",
"@opam/mirage-crypto-rng-lwt": "*",
"@opam/mirage-crypto-pk": "*",
"@opam/ppx_deriving": "5.2.1",
"@opam/ppx_inline_test": "*",
"@opam/ppx_sexp_conv": "v0.16.0",
"@opam/ppx_variants_conv": "v0.16.0",
"@opam/ppx_yojson_conv": "v0.16.0",
"@opam/sihl": "*",
"@opam/sihl-cache": "*",
"@opam/sihl-email": "*",
"@opam/sihl-queue": "*",
"@opam/sihl-storage": "*",
"@opam/sihl-token": "*",
"@opam/sihl-user": "*",
"esy-cmake": "*",
"esy-mariadb": "*",
"esy-openssl": "*",
"ocaml": "4.14.0"
},
"resolutions": {
"@opam/caqti-lwt": "paurkedal/ocaml-caqti:caqti-lwt.opam#cba1047b9e318bc450be72ab9dfb302aac8e4a78",
"@opam/canary": "uzh/canary#02cf40e029268560e160ca032850426e387aa598",
"@opam/comformist": "oxidizing/conformist#aa7b95d1f39215cdaab8cf96d765d63e41d5f8a6",
"@opam/guardian": "uzh/guardian#f144f2c12459e13365c8d6adc481556223dd87f9",
"@opam/letters": "oxidizing/letters#ab469208d008b32bd44f2385fdbee7bf24141172",
"@opam/sihl": "leostera/sihl:sihl.opam#ef4c89fd3d72fdf51caf30082cc55b7e7430b8f2",
"@opam/sihl-cache": "oxidizing/sihl:sihl-cache.opam#e0b304a4ebd3cb2ac0d21e0f6d151b9db301f9eb",
"@opam/sihl-email": "oxidizing/sihl:sihl-email.opam#e0b304a4ebd3cb2ac0d21e0f6d151b9db301f9eb",
"@opam/sihl-queue": "oxidizing/sihl:sihl-queue.opam#e0b304a4ebd3cb2ac0d21e0f6d151b9db301f9eb",
"@opam/sihl-storage": "oxidizing/sihl:sihl-storage.opam#e0b304a4ebd3cb2ac0d21e0f6d151b9db301f9eb",
"@opam/sihl-token": "oxidizing/sihl:sihl-token.opam#e0b304a4ebd3cb2ac0d21e0f6d151b9db301f9eb",
"@opam/sihl-user": "oxidizing/sihl:sihl-user.opam#e0b304a4ebd3cb2ac0d21e0f6d151b9db301f9eb",
"esy-openssl": "esy-packages/esy-openssl#619ae2d46ca981ec26ab3287487ad98b157a01d1",
"esy-mariadb": {
"source":"https://github.com/mariadb-corporation/mariadb-connector-c/archive/refs/tags/v3.3.7.tar.gz#sha256:029b91473a42f822611e92e01b7af05c3ed8def7ab14665ffbb78947ccf0d6a5",
"override": {
"buildEnv": {
"CFLAGS": "-I#{esy-openssl.install / 'include'} $CFLAGS",
"LDFLAGS": "-L#{esy-openssl.lib} -lcrypto $LDFLAGS"
},
"build": [
"cmake . -DCMAKE_C_FLAGS=-Wno-deprecated-non-prototype",
"make"
],
"buildsInSource": true,
"exportedEnv": {
"PKG_CONFIG_PATH": {
"scope": "global",
"val": "#{self.lib / 'pkgconfig'}"
},
"LDFLAGS": {
"scope": "global",
"val": "-L#{self.lib}"
},
"CPPFLAGS": {
"scope": "global",
"val": "-I#{self.install / 'include'}"
},
"LD_LIBRARY_PATH": {
"scope": "global",
"val": "#{self.lib}:$LD_LIBRARY_PATH"
},
"LIBRARY_PATH": {
"scope": "global",
"val": "#{self.lib}:$LIBRARY_PATH"
},
"CPATH": {
"scope": "global",
"val": "#{self.install / 'include'}:$CPATH"
},
"PATH": {
"scope": "global",
"val": "#{self.bin}:$PATH"
}
},
"dependencies": {
"esy-openssl": "*",
"esy-cmake": "*"
}
}
},
"@opam/mariadb": {
"version": "opam:1.1.6",
"override": {
"buildEnv": {
"C_INCLUDE_PATH": "#{@opam/ctypes.root / 'src' / 'ctypes'}:#{@opam/integers.root / 'src'}:$C_INCLUDE_PATH",
"CFLAGS": "-I#{esy-mariadb.root / 'include'} $CFLAGS",
"LDFLAGS": "-L #{@opam/ctypes.lib} -L#{esy-mariadb.root / 'libmariadb'} $LDFLAGS",
"LIBRARY_PATH": "#{esy-mariadb.root / 'libmariadb'}:$LIBRARY_PATH",
"DYLD_LIBRARY_PATH": "#{@opam/ctypes.lib / 'stublibs'}:$DYLD_LIBRARY_PATH",
"CAML_LD_LIBRARY_PATH": "#{@opam/ctypes.lib / 'stublibs'}:$CAML_LD_LIBRARY_PATH"
},
"build": [
"./configure --enable-lwt --prefix=$cur__install",
"ocaml setup.ml -build -tag thread"
],
"install": "ocaml setup.ml -install",
"dependencies": {
"esy-pkg-config": "*",
"@opam/stdlib-shims": "*",
"@opam/lwt": "5.7.0",
"@opam/ocamlbuild": "*",
"@opam/integers": "*",
"@opam/camlp-streams": "*",
"@opam/ctypes": "0.21.1",
"@opam/ctypes-foreign": "0.21.1",
"@opam/ocamlfind": "*",
"esy-mariadb": "*"
}
}
}
}
}
3 changes: 3 additions & 0 deletions esy.lock/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions esy.lock/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9722ebb

Please sign in to comment.