diff --git a/.sqlx/query-4d26e92088234552f9159b876c7fdd3bb557a7f918820e289bd39742de553883.json b/.sqlx/query-017b3f73101926a3fe029ed75c412ec902aa74fee334c23fd75fe0cde1e324ca.json similarity index 70% rename from .sqlx/query-4d26e92088234552f9159b876c7fdd3bb557a7f918820e289bd39742de553883.json rename to .sqlx/query-017b3f73101926a3fe029ed75c412ec902aa74fee334c23fd75fe0cde1e324ca.json index 32cb7eb..1d153dc 100644 --- a/.sqlx/query-4d26e92088234552f9159b876c7fdd3bb557a7f918820e289bd39742de553883.json +++ b/.sqlx/query-017b3f73101926a3fe029ed75c412ec902aa74fee334c23fd75fe0cde1e324ca.json @@ -1,6 +1,6 @@ { "db_name": "MySQL", - "query": "\n SELECT id, channel, name, nudge, blacklisted, webhook_id, webhook_token, paused, paused_until\n FROM channels\n WHERE channel = ?\n ", + "query": "\n SELECT id, channel, nudge, webhook_id, webhook_token, paused,\n paused_until\n FROM channels\n WHERE channel = ?\n ", "describe": { "columns": [ { @@ -23,15 +23,6 @@ }, { "ordinal": 2, - "name": "name", - "type_info": { - "type": "VarString", - "flags": "", - "max_size": 400 - } - }, - { - "ordinal": 3, "name": "nudge", "type_info": { "type": "Short", @@ -40,16 +31,7 @@ } }, { - "ordinal": 4, - "name": "blacklisted", - "type_info": { - "type": "Tiny", - "flags": "NOT_NULL", - "max_size": 1 - } - }, - { - "ordinal": 5, + "ordinal": 3, "name": "webhook_id", "type_info": { "type": "LongLong", @@ -58,7 +40,7 @@ } }, { - "ordinal": 6, + "ordinal": 4, "name": "webhook_token", "type_info": { "type": "Blob", @@ -67,7 +49,7 @@ } }, { - "ordinal": 7, + "ordinal": 5, "name": "paused", "type_info": { "type": "Tiny", @@ -76,7 +58,7 @@ } }, { - "ordinal": 8, + "ordinal": 6, "name": "paused_until", "type_info": { "type": "Timestamp", @@ -91,8 +73,6 @@ "nullable": [ false, false, - true, - false, false, true, true, @@ -100,5 +80,5 @@ true ] }, - "hash": "4d26e92088234552f9159b876c7fdd3bb557a7f918820e289bd39742de553883" + "hash": "017b3f73101926a3fe029ed75c412ec902aa74fee334c23fd75fe0cde1e324ca" } diff --git a/.sqlx/query-1bd6f70d57d5e913f97025cf6fc5be795a1302485ef1c07fe13eb246f184a1d1.json b/.sqlx/query-1bd6f70d57d5e913f97025cf6fc5be795a1302485ef1c07fe13eb246f184a1d1.json deleted file mode 100644 index c5be060..0000000 --- a/.sqlx/query-1bd6f70d57d5e913f97025cf6fc5be795a1302485ef1c07fe13eb246f184a1d1.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "db_name": "MySQL", - "query": "\n UPDATE channels\n SET\n name = ?,\n nudge = ?,\n blacklisted = ?,\n webhook_id = ?,\n webhook_token = ?,\n paused = ?,\n paused_until = ?\n WHERE id = ?\n ", - "describe": { - "columns": [], - "parameters": { - "Right": 8 - }, - "nullable": [] - }, - "hash": "1bd6f70d57d5e913f97025cf6fc5be795a1302485ef1c07fe13eb246f184a1d1" -} diff --git a/.sqlx/query-d3e41b7c9df5823c418181f46aa78999159afbd458dcd05ffb9e032182ec493b.json b/.sqlx/query-21b660ecbeffcac31ef283f59e420360a28b344759407024a11dc4a04da9341d.json similarity index 70% rename from .sqlx/query-d3e41b7c9df5823c418181f46aa78999159afbd458dcd05ffb9e032182ec493b.json rename to .sqlx/query-21b660ecbeffcac31ef283f59e420360a28b344759407024a11dc4a04da9341d.json index db69dbb..0314609 100644 --- a/.sqlx/query-d3e41b7c9df5823c418181f46aa78999159afbd458dcd05ffb9e032182ec493b.json +++ b/.sqlx/query-21b660ecbeffcac31ef283f59e420360a28b344759407024a11dc4a04da9341d.json @@ -1,6 +1,6 @@ { "db_name": "MySQL", - "query": "\n SELECT id, channel, name, nudge, blacklisted, webhook_id, webhook_token, paused,\n paused_until\n FROM channels\n WHERE channel = ?\n ", + "query": "\n SELECT id, channel, nudge, webhook_id, webhook_token, paused, paused_until\n FROM channels\n WHERE channel = ?\n ", "describe": { "columns": [ { @@ -23,15 +23,6 @@ }, { "ordinal": 2, - "name": "name", - "type_info": { - "type": "VarString", - "flags": "", - "max_size": 400 - } - }, - { - "ordinal": 3, "name": "nudge", "type_info": { "type": "Short", @@ -40,16 +31,7 @@ } }, { - "ordinal": 4, - "name": "blacklisted", - "type_info": { - "type": "Tiny", - "flags": "NOT_NULL", - "max_size": 1 - } - }, - { - "ordinal": 5, + "ordinal": 3, "name": "webhook_id", "type_info": { "type": "LongLong", @@ -58,7 +40,7 @@ } }, { - "ordinal": 6, + "ordinal": 4, "name": "webhook_token", "type_info": { "type": "Blob", @@ -67,7 +49,7 @@ } }, { - "ordinal": 7, + "ordinal": 5, "name": "paused", "type_info": { "type": "Tiny", @@ -76,7 +58,7 @@ } }, { - "ordinal": 8, + "ordinal": 6, "name": "paused_until", "type_info": { "type": "Timestamp", @@ -91,8 +73,6 @@ "nullable": [ false, false, - true, - false, false, true, true, @@ -100,5 +80,5 @@ true ] }, - "hash": "d3e41b7c9df5823c418181f46aa78999159afbd458dcd05ffb9e032182ec493b" + "hash": "21b660ecbeffcac31ef283f59e420360a28b344759407024a11dc4a04da9341d" } diff --git a/.sqlx/query-5d7a787e3a6f487c3fe00bd39d308c9350c82e58b0ad1aae0b92824375786f02.json b/.sqlx/query-5d7a787e3a6f487c3fe00bd39d308c9350c82e58b0ad1aae0b92824375786f02.json new file mode 100644 index 0000000..c85539d --- /dev/null +++ b/.sqlx/query-5d7a787e3a6f487c3fe00bd39d308c9350c82e58b0ad1aae0b92824375786f02.json @@ -0,0 +1,12 @@ +{ + "db_name": "MySQL", + "query": "INSERT IGNORE INTO channels (channel, guild_id) VALUES (?, (SELECT id FROM guilds WHERE guild = ?))", + "describe": { + "columns": [], + "parameters": { + "Right": 2 + }, + "nullable": [] + }, + "hash": "5d7a787e3a6f487c3fe00bd39d308c9350c82e58b0ad1aae0b92824375786f02" +} diff --git a/.sqlx/query-af08f3524c316f438feb62a24c67b96197e3655a87efe128914ed386be20d900.json b/.sqlx/query-af08f3524c316f438feb62a24c67b96197e3655a87efe128914ed386be20d900.json new file mode 100644 index 0000000..52b5e34 --- /dev/null +++ b/.sqlx/query-af08f3524c316f438feb62a24c67b96197e3655a87efe128914ed386be20d900.json @@ -0,0 +1,12 @@ +{ + "db_name": "MySQL", + "query": "\n UPDATE channels\n SET\n nudge = ?,\n webhook_id = ?,\n webhook_token = ?,\n paused = ?,\n paused_until = ?\n WHERE id = ?\n ", + "describe": { + "columns": [], + "parameters": { + "Right": 6 + }, + "nullable": [] + }, + "hash": "af08f3524c316f438feb62a24c67b96197e3655a87efe128914ed386be20d900" +} diff --git a/.sqlx/query-f8e99a39fb87d47bcdf70f38e00c4dbe4d6832b1b073efddfa79a8cd756d8dc6.json b/.sqlx/query-f8e99a39fb87d47bcdf70f38e00c4dbe4d6832b1b073efddfa79a8cd756d8dc6.json deleted file mode 100644 index 4b8d3b0..0000000 --- a/.sqlx/query-f8e99a39fb87d47bcdf70f38e00c4dbe4d6832b1b073efddfa79a8cd756d8dc6.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "db_name": "MySQL", - "query": "INSERT IGNORE INTO channels (channel, name, guild_id) VALUES (?, ?, (SELECT id FROM guilds WHERE guild = ?))", - "describe": { - "columns": [], - "parameters": { - "Right": 3 - }, - "nullable": [] - }, - "hash": "f8e99a39fb87d47bcdf70f38e00c4dbe4d6832b1b073efddfa79a8cd756d8dc6" -} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..08cb904 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +.DEFAULT_GOAL := build + +CARGO ?= cargo +PODMAN ?= podman +IMAGE ?= reminder-rs + +.PHONY: build prepare test image + +# Keep the stages ordered even when make is run with -j. +build: image + $(PODMAN) run --rm -v "$(CURDIR):/mnt" -w /mnt \ + -e SQLX_OFFLINE=true "$(IMAGE)" cargo deb + +image: test + $(PODMAN) build -t "$(IMAGE)" . + +test: prepare + SQLX_OFFLINE=true $(CARGO) test --locked + +# Include test-only queries in the metadata used by offline compilation. +prepare: + SQLX_OFFLINE=false $(CARGO) sqlx prepare -- --all-targets --locked diff --git a/README.md b/README.md index 61fe92d..d6697e0 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,26 @@ Recommended method. By default, this builds targeting Ubuntu 20.04. Modify the Containerfile if you wish to target a different platform. These instructions are written using `podman`, but `docker` should work too. -1. Install container software: `sudo apt install podman`. +1. Install container software and Make: `sudo apt install podman make`. 2. Install database server: `sudo apt install mysql-server-8.0`. Create a database called `reminders` -3. Install SQLx CLI: `cargo install sqlx-cli` -4. From the source code directory, execute `sqlx migrate run` -5. Build container image: `podman build -t reminder-rs .` -6. Build with podman: - `podman run --rm --network=host -v "$PWD":/mnt -w /mnt -e "DATABASE_URL=mysql://user@localhost/reminders" reminder-rs cargo deb` +3. Install SQLx CLI matching the project's SQLx version: `cargo install sqlx-cli --version 0.8.2 --locked`. +4. Install the local build requirements (Rust, Node.js/npm, GCC, CMake, pkg-config, and OpenSSL + development headers), then install dashboard dependencies: `npm ci --prefix reminder-dashboard`. +5. Export the URL of your build/test database: + `export DATABASE_URL="mysql://user[:password]@localhost/reminders"`. +6. From the source code directory, execute `sqlx migrate run`. +7. Run `make` (or `make build`). This prepares SQLx query metadata in `.sqlx`, runs the Rust tests, + builds the `reminder-rs` container image, and runs `cargo deb` inside it. The resulting package is + written to `target/debian/`. + +Preparation and database-dependent tests use the local database. The container packaging step uses +the prepared `.sqlx` metadata with `SQLX_OFFLINE=true`, so it does not need database access, including +when a `.env` file is present in the mounted source directory. + +The stages can also be run separately: `make prepare`, `make test` (includes preparation), and +`make image` (includes preparation and tests). Override `IMAGE` to change the container image tag, +or `PODMAN` to use another container command, for example `make PODMAN=docker`. ### Compiling for other target