From 6e19ac5a639a0ea0e845a42a771848d1f22a054d Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sat, 19 Jun 2021 11:54:46 +0200 Subject: [PATCH 01/17] Started Dockerfile --- .dockerignore | 5 +++++ Cargo.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 ++- Dockerfile | 16 ++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1917669 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* + +!Cargo.toml +!Cargo.lock +!src/ diff --git a/Cargo.lock b/Cargo.lock index 905d09f..267150d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,6 +84,12 @@ version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.0.1" @@ -170,6 +176,29 @@ dependencies = [ "syn", ] +[[package]] +name = "diesel" +version = "1.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba51ca66f57261fd17cadf8b73e4775cc307d0521d855de3f5de91a8f074e0e" +dependencies = [ + "bitflags", + "byteorder", + "diesel_derives", + "pq-sys", +] + +[[package]] +name = "diesel_derives" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "discard" version = "1.0.4" @@ -373,6 +402,7 @@ dependencies = [ name = "hilde" version = "0.1.0" dependencies = [ + "diesel", "rocket", ] @@ -661,6 +691,15 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "pq-sys" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda" +dependencies = [ + "vcpkg", +] + [[package]] name = "proc-macro-hack" version = "0.5.19" @@ -1262,6 +1301,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "vcpkg" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70455df2fdf4e9bf580a92e443f1eb0303c390d682e2ea817312c9e81f8c3399" + [[package]] name = "version_check" version = "0.9.3" diff --git a/Cargo.toml b/Cargo.toml index 2e688d4..906e147 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,11 @@ [package] name = "hilde" version = "0.1.0" -authors = ["jjr "] +authors = ["Jef Roosens "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] rocket = "0.5.0-rc.1" +diesel = { version = "1.4.7", features = ["postgres"] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2e886dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM rust:1.52-alpine3.13 AS builder + +WORKDIR /src + +COPY Cargo.toml Cargo.lock ./ +COPY src ./src/ + +RUN cargo build \ + --release + + +FROM alpine:3.13 + +COPY --from=builder /src/target/release/hilde /usr/local/bin/hilde + +ENTRYPOINT [ "/usr/local/bin/hilde" ] From a696888e110670331fb62c149bf77b8ac22ad08e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sat, 19 Jun 2021 12:14:57 +0200 Subject: [PATCH 02/17] Added Woodpecker CI config --- .woodpecker.yml | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .woodpecker.yml diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..6d66ebc --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,73 @@ +pipeline: + # Download the cache from S3 + restore-cache: + image: plugins/s3-cache + pull: true + + endpoint: https://s3.roosens.me + root: build-cache/ + restore: true + + secrets: [ cache_s3_access_key, cache_s3_secret_key ] + + + # =====BUILDING===== + build-backend: + image: rust:1.53-alpine + pull: true + group: build + environment: + - CARGO_HOME=.cargo + commands: + - cargo build + + + # =====TESTING===== + test-backend: + image: rust:1.53-alpine + environment: + - CARGO_HOME=.cargo + commands: + - cargo test + + + # =====LINTING===== + lint-backend: + image: rust:1.53-alpine + group: lint + environment: + - CARGO_HOME=.cargo + commands: + - cargo fmt -- --check + # This is run here because it requires compilation + - cargo clippy --all-targets -- -D warnings + + + # =====REBUILD & FLUSH CACHE===== + rebuild-cache: + image: plugins/s3-cache + + endpoint: https://s3.roosens.me + root: build-cache/ + rebuild: true + mount: + - target + - .cargo + + secrets: [ cache_s3_access_key, cache_s3_secret_key ] + # Push the cache, even on failure + when: + status: [ success, failure ] + + flush-cache: + image: plugins/s3-cache + + endpoint: https://s3.roosens.me + root: build-cache/ + flush: true + flush_age: 14 + + secrets: [ cache_s3_access_key, cache_s3_secret_key ] + # Push the cache, even on failure + when: + status: [ success, failure ] From 0eeea1e59314fe15c27048a3024037c90f9fe28b Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 11:32:50 +0200 Subject: [PATCH 03/17] Added build dependencies to CI and Dockerfile --- .woodpecker.yml | 3 +++ Dockerfile | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/.woodpecker.yml b/.woodpecker.yml index 6d66ebc..9e26d74 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -19,6 +19,7 @@ pipeline: environment: - CARGO_HOME=.cargo commands: + - apk add musl-dev postgresql-dev - cargo build @@ -28,6 +29,7 @@ pipeline: environment: - CARGO_HOME=.cargo commands: + - apk add musl-dev postgresql-dev - cargo test @@ -38,6 +40,7 @@ pipeline: environment: - CARGO_HOME=.cargo commands: + - apk add musl-dev postgresql-dev - cargo fmt -- --check # This is run here because it requires compilation - cargo clippy --all-targets -- -D warnings diff --git a/Dockerfile b/Dockerfile index 2e886dd..8840167 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,12 @@ FROM rust:1.52-alpine3.13 AS builder WORKDIR /src +# Install build dependencies +RUN apk add --no-cache \ + musl-dev \ + postgresql-dev + +# Copy over source code COPY Cargo.toml Cargo.lock ./ COPY src ./src/ From fa5ee06a04f10b13c55248024c07c65860b3ecce Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 11:37:45 +0200 Subject: [PATCH 04/17] Added linting deps to ci --- .woodpecker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.woodpecker.yml b/.woodpecker.yml index 9e26d74..49e99a8 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -41,6 +41,7 @@ pipeline: - CARGO_HOME=.cargo commands: - apk add musl-dev postgresql-dev + - rustup component add rustfmt clippy - cargo fmt -- --check # This is run here because it requires compilation - cargo clippy --all-targets -- -D warnings From 89bc9b91e15523f151e8ad67251b497e9839865f Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 12:07:33 +0200 Subject: [PATCH 05/17] Added editorconfig file --- .editorconfig | 9 ++++ .gitignore | 2 +- .woodpecker.yml | 124 ++++++++++++++++++++++++------------------------ 3 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ecfd732 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = false +indent_size = 4 + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.gitignore b/.gitignore index 7a184b0..e9d365b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -# Cargo.lock +Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk diff --git a/.woodpecker.yml b/.woodpecker.yml index 49e99a8..cb88ba5 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,77 +1,77 @@ pipeline: - # Download the cache from S3 - restore-cache: - image: plugins/s3-cache - pull: true + # Download the cache from S3 + restore-cache: + image: plugins/s3-cache + pull: true - endpoint: https://s3.roosens.me - root: build-cache/ - restore: true + endpoint: https://s3.roosens.me + root: build-cache/ + restore: true - secrets: [ cache_s3_access_key, cache_s3_secret_key ] + secrets: [ cache_s3_access_key, cache_s3_secret_key ] - # =====BUILDING===== - build-backend: - image: rust:1.53-alpine - pull: true - group: build - environment: - - CARGO_HOME=.cargo - commands: - - apk add musl-dev postgresql-dev - - cargo build + # =====BUILDING===== + build-backend: + image: rust:1.53-alpine + pull: true + group: build + environment: + - CARGO_HOME=.cargo + commands: + - apk add musl-dev postgresql-dev + - cargo build - # =====TESTING===== - test-backend: - image: rust:1.53-alpine - environment: - - CARGO_HOME=.cargo - commands: - - apk add musl-dev postgresql-dev - - cargo test + # =====TESTING===== + test-backend: + image: rust:1.53-alpine + environment: + - CARGO_HOME=.cargo + commands: + - apk add musl-dev postgresql-dev + - cargo test - # =====LINTING===== - lint-backend: - image: rust:1.53-alpine - group: lint - environment: - - CARGO_HOME=.cargo - commands: - - apk add musl-dev postgresql-dev - - rustup component add rustfmt clippy - - cargo fmt -- --check - # This is run here because it requires compilation - - cargo clippy --all-targets -- -D warnings - + # =====LINTING===== + lint-backend: + image: rust:1.53-alpine + group: lint + environment: + - CARGO_HOME=.cargo + commands: + - apk add musl-dev postgresql-dev + - rustup component add rustfmt clippy + - cargo fmt -- --check + # This is run here because it requires compilation + - cargo clippy --all-targets -- -D warnings + - # =====REBUILD & FLUSH CACHE===== - rebuild-cache: - image: plugins/s3-cache + # =====REBUILD & FLUSH CACHE===== + rebuild-cache: + image: plugins/s3-cache - endpoint: https://s3.roosens.me - root: build-cache/ - rebuild: true - mount: - - target - - .cargo + endpoint: https://s3.roosens.me + root: build-cache/ + rebuild: true + mount: + - target + - .cargo - secrets: [ cache_s3_access_key, cache_s3_secret_key ] - # Push the cache, even on failure - when: - status: [ success, failure ] + secrets: [ cache_s3_access_key, cache_s3_secret_key ] + # Push the cache, even on failure + when: + status: [ success, failure ] - flush-cache: - image: plugins/s3-cache + flush-cache: + image: plugins/s3-cache - endpoint: https://s3.roosens.me - root: build-cache/ - flush: true - flush_age: 14 + endpoint: https://s3.roosens.me + root: build-cache/ + flush: true + flush_age: 14 - secrets: [ cache_s3_access_key, cache_s3_secret_key ] - # Push the cache, even on failure - when: - status: [ success, failure ] + secrets: [ cache_s3_access_key, cache_s3_secret_key ] + # Push the cache, even on failure + when: + status: [ success, failure ] From 68a19258d499bb248448145e6d11181878413183 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 12:48:45 +0200 Subject: [PATCH 06/17] Added Makefile for setting up db --- .gitignore | 2 +- Makefile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index e9d365b..7a184b0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock +# Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ead8de6 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +# The main usecase for this Makefile is to simplify database management + + +all: build +.PHONY: all + + +# =====CARGO STUFF===== +build: + @ cargo build +.PHONY: build + +run: + @ cargo run +.PHONY: run + +test: + @ cargo test +.PHONY: test + +lint: + @ cargo fmt -- --check + @ cargo clippy --all-targets -- -D warnings +.PHONY: lint + + +# =====DATABASE STUFF===== +db: + @ docker run \ + --rm \ + -itd \ + -v hilde_db-data:/var/lib/postgresql/data \ + -e POSTGRES_USER=hilde \ + -e POSTGRES_PASSWORD=hilde \ + --name hilde_db \ + -p 5432:5432 \ + postgres:13-alpine +.PHONY: db + +psql: + @ docker exec \ + -it hilde_db \ + psql -U hilde +.PHONY: psql + +stop-db: + @ docker stop hilde_db +.PHONY: stop-db + + +# =====DOCKER STUFF===== +image: + @ docker build -t hilde:latest . From 49007e7a8f0685c6faad0d2383401b6ee0737951 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 12:51:17 +0200 Subject: [PATCH 07/17] Added missing .PHONY [CI SKIP] --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ead8de6..be507fd 100644 --- a/Makefile +++ b/Makefile @@ -51,3 +51,4 @@ stop-db: # =====DOCKER STUFF===== image: @ docker build -t hilde:latest . +.PHONY: image From ad522107362a6309c26a6c05134e66fa31bd4024 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 13:00:57 +0200 Subject: [PATCH 08/17] Added Makefile-specific editorconfig --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index ecfd732..77e3fe3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,6 +4,10 @@ root = true end_of_line = lf insert_final_newline = false indent_size = 4 +indent_style = space [*.{yml,yaml}] indent_size = 2 + +[Makefile] +indent_style = tab From 1c7ae8cf413771d07bc6536fccf8b62b0a544b42 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 25 Jun 2021 12:00:41 +0000 Subject: [PATCH 09/17] Update rust Docker tag to v1.53 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8840167..6b28746 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.52-alpine3.13 AS builder +FROM rust:1.53-alpine3.13 AS builder WORKDIR /src From 72c7be055a20aa38a82aa204ea92b2a9ec3840da Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 27 Jun 2021 11:11:01 +0200 Subject: [PATCH 10/17] Initialized Diesel in project --- .env | 2 ++ Makefile | 1 + diesel.toml | 5 +++ migrations/.gitkeep | 0 .../down.sql | 6 ++++ .../up.sql | 36 +++++++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 .env create mode 100644 diesel.toml create mode 100644 migrations/.gitkeep create mode 100644 migrations/00000000000000_diesel_initial_setup/down.sql create mode 100644 migrations/00000000000000_diesel_initial_setup/up.sql diff --git a/.env b/.env new file mode 100644 index 0000000..d966102 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +# This file is solely used by Diesel +DATABASE_URL=postgres://hilde:hilde@localhost/hilde diff --git a/Makefile b/Makefile index be507fd..de8b72f 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ db: -v hilde_db-data:/var/lib/postgresql/data \ -e POSTGRES_USER=hilde \ -e POSTGRES_PASSWORD=hilde \ + -e POSTGRES_DB=hilde \ --name hilde_db \ -p 5432:5432 \ postgres:13-alpine diff --git a/diesel.toml b/diesel.toml new file mode 100644 index 0000000..92267c8 --- /dev/null +++ b/diesel.toml @@ -0,0 +1,5 @@ +# For documentation on how to configure this file, +# see diesel.rs/guides/configuring-diesel-cli + +[print_schema] +file = "src/schema.rs" diff --git a/migrations/.gitkeep b/migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/migrations/00000000000000_diesel_initial_setup/down.sql b/migrations/00000000000000_diesel_initial_setup/down.sql new file mode 100644 index 0000000..a9f5260 --- /dev/null +++ b/migrations/00000000000000_diesel_initial_setup/down.sql @@ -0,0 +1,6 @@ +-- This file was automatically created by Diesel to setup helper functions +-- and other internal bookkeeping. This file is safe to edit, any future +-- changes will be added to existing projects as new migrations. + +DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); +DROP FUNCTION IF EXISTS diesel_set_updated_at(); diff --git a/migrations/00000000000000_diesel_initial_setup/up.sql b/migrations/00000000000000_diesel_initial_setup/up.sql new file mode 100644 index 0000000..d68895b --- /dev/null +++ b/migrations/00000000000000_diesel_initial_setup/up.sql @@ -0,0 +1,36 @@ +-- This file was automatically created by Diesel to setup helper functions +-- and other internal bookkeeping. This file is safe to edit, any future +-- changes will be added to existing projects as new migrations. + + + + +-- Sets up a trigger for the given table to automatically set a column called +-- `updated_at` whenever the row is modified (unless `updated_at` was included +-- in the modified columns) +-- +-- # Example +-- +-- ```sql +-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); +-- +-- SELECT diesel_manage_updated_at('users'); +-- ``` +CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ +BEGIN + EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s + FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ +BEGIN + IF ( + NEW IS DISTINCT FROM OLD AND + NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at + ) THEN + NEW.updated_at := current_timestamp; + END IF; + RETURN NEW; +END; +$$ LANGUAGE plpgsql; From 0326f6e0fdf063463f42a611d877cccb42ceac6a Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 27 Jun 2021 11:15:58 +0200 Subject: [PATCH 11/17] Updated README --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7753b10..7491eaa 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,19 @@ # hilde -A server implementation of a Debian repository. \ No newline at end of file +A server implementation of a Debian repository. + +## Development + +To develop this project, you'll need a few things: + +* Docker (for setting up the database) +* Cargo & Rust stable (all hail Rocket v0.5) +* The PostgreSQL dev libraries (to compile Diesel) + +That's the ones I can think of right now. If I think of any others, I'll be +sure to add them to the list. + +For ease of development, there's a Makefile wrapper that can do everything you +need to do to work on Hilde. I recommend reading through it (it's not long), +but the important ones are `make` & `make run`, which are just Cargo aliases, +and `make db`, which starts a local PostgreSQL database using Docker. \ No newline at end of file From 569e9c935bd72d8bbbe0b2ea238c7b9c98ba85ca Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 27 Jun 2021 11:36:54 +0200 Subject: [PATCH 12/17] Added deps for using Diesel in Rocket --- Cargo.lock | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +++++ src/main.rs | 11 ++++++-- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 267150d..a78c95b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -186,6 +186,7 @@ dependencies = [ "byteorder", "diesel_derives", "pq-sys", + "r2d2", ] [[package]] @@ -199,6 +200,16 @@ dependencies = [ "syn", ] +[[package]] +name = "diesel_migrations" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf3cde8413353dc7f5d72fa8ce0b99a560a359d2c5ef1e5817ca731cd9008f4c" +dependencies = [ + "migrations_internals", + "migrations_macros", +] + [[package]] name = "discard" version = "1.0.4" @@ -403,7 +414,9 @@ name = "hilde" version = "0.1.0" dependencies = [ "diesel", + "diesel_migrations", "rocket", + "rocket_sync_db_pools", ] [[package]] @@ -545,6 +558,27 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +[[package]] +name = "migrations_internals" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b4fc84e4af020b837029e017966f86a1c2d5e83e64b589963d5047525995860" +dependencies = [ + "diesel", +] + +[[package]] +name = "migrations_macros" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c" +dependencies = [ + "migrations_internals", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "mime" version = "0.3.16" @@ -743,6 +777,17 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r2d2" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f" +dependencies = [ + "log", + "parking_lot", + "scheduled-thread-pool", +] + [[package]] name = "rand" version = "0.8.4" @@ -903,6 +948,30 @@ dependencies = [ "uncased", ] +[[package]] +name = "rocket_sync_db_pools" +version = "0.1.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38cfdfebd552d075c368e641c88a5cd6ce1c58c5c710548aeb777abb48830f4b" +dependencies = [ + "diesel", + "r2d2", + "rocket", + "rocket_sync_db_pools_codegen", + "serde", + "tokio", +] + +[[package]] +name = "rocket_sync_db_pools_codegen" +version = "0.1.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267808c094db5366e1d8925aaf9f2ce05ff9b3bd92cb18c7040a1fe219c2e25" +dependencies = [ + "devise", + "quote", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -924,6 +993,15 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "scheduled-thread-pool" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7" +dependencies = [ + "parking_lot", +] + [[package]] name = "scoped-tls" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 906e147..6e66641 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,9 @@ edition = "2018" [dependencies] rocket = "0.5.0-rc.1" diesel = { version = "1.4.7", features = ["postgres"] } +diesel_migrations = "1.4.0" + +[dependencies.rocket_sync_db_pools] +version = "0.1.0-rc.1" +default_features = false +features = ["diesel_postgres_pool"] diff --git a/src/main.rs b/src/main.rs index e7a11a9..00dc52d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,10 @@ -fn main() { - println!("Hello, world!"); +#[macro_use] +extern crate rocket; + +#[macro_use] +extern crate diesel_migrations; + +#[launch] +fn rocket() -> _ { + rocket::build() } From 424e723cd852b51faaa375440e174da7fb2dbd47 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 27 Jun 2021 12:15:54 +0200 Subject: [PATCH 13/17] Migrations now run on startup --- Cargo.lock | 32 ++++++++++++++++---------------- Rocket.toml | 2 ++ src/main.rs | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 Rocket.toml diff --git a/Cargo.lock b/Cargo.lock index a78c95b..9ec71b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,9 +233,9 @@ dependencies = [ [[package]] name = "figment" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca029e813a72b7526d28273d25f3e4a2f365d1b7a1018a6f93ec9053a119763" +checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df" dependencies = [ "atomic", "pear", @@ -402,9 +402,9 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -709,9 +709,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -830,9 +830,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] @@ -1099,9 +1099,9 @@ dependencies = [ [[package]] name = "spin" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b87bbf98cb81332a56c1ee8929845836f85e8ddd693157c30d76660196014478" +checksum = "f5fdd7196b4ae35a111c6dc97f9cc152ca3ea8ad744f7cb46a9f27b3ef8f2f54" [[package]] name = "stable-pattern" @@ -1123,9 +1123,9 @@ dependencies = [ [[package]] name = "state" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b54c22963194db84a59ee48e1fa9ed6c1fa9909ad5db92a700aa6fe956d632b" +checksum = "87cf4f5369e6d3044b5e365c9690f451516ac8f0954084622b49ea3fde2f6de5" dependencies = [ "loom", ] @@ -1244,9 +1244,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79ba603c337335df6ba6dd6afc38c38a7d5e1b0c871678439ea973cd62a118e" +checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2" dependencies = [ "autocfg", "bytes", @@ -1381,9 +1381,9 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "vcpkg" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70455df2fdf4e9bf580a92e443f1eb0303c390d682e2ea817312c9e81f8c3399" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" diff --git a/Rocket.toml b/Rocket.toml new file mode 100644 index 0000000..9390626 --- /dev/null +++ b/Rocket.toml @@ -0,0 +1,2 @@ +[debug.databases] +postgres_hilde = { url = "postgres://hilde:hilde@localhost/hilde" } diff --git a/src/main.rs b/src/main.rs index 00dc52d..e55ff49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,29 @@ extern crate rocket; #[macro_use] extern crate diesel_migrations; +use rocket_sync_db_pools::{diesel, database}; +use rocket::{ + Rocket, + Build, + fairing::AdHoc +}; + +embed_migrations!(); + +#[database("postgres_hilde")] +struct HildeDbConn(diesel::PgConnection); + +async fn run_db_migrations(rocket: Rocket) -> Result, Rocket> { + let conn = HildeDbConn::get_one(&rocket).await.expect("database connection"); + conn.run(|c| match embedded_migrations::run(c) { + Ok(()) => Ok(rocket), + Err(_) => Err(rocket), + }).await +} + #[launch] fn rocket() -> _ { rocket::build() + .attach(HildeDbConn::fairing()) + .attach(AdHoc::try_on_ignite("Run database migrations", run_db_migrations)) } From de38073f71d4bf9bf9d8e3cebf404f1b510ac50e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 27 Jun 2021 15:00:55 +0200 Subject: [PATCH 14/17] Fixed linting errors --- Makefile | 4 ++++ src/main.rs | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index de8b72f..ffd9238 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,10 @@ lint: @ cargo clippy --all-targets -- -D warnings .PHONY: lint +format: + @ cargo fmt +.PHONY: format + # =====DATABASE STUFF===== db: diff --git a/src/main.rs b/src/main.rs index e55ff49..5db0513 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,12 +4,8 @@ extern crate rocket; #[macro_use] extern crate diesel_migrations; -use rocket_sync_db_pools::{diesel, database}; -use rocket::{ - Rocket, - Build, - fairing::AdHoc -}; +use rocket::{fairing::AdHoc, Build, Rocket}; +use rocket_sync_db_pools::{database, diesel}; embed_migrations!(); @@ -17,16 +13,22 @@ embed_migrations!(); struct HildeDbConn(diesel::PgConnection); async fn run_db_migrations(rocket: Rocket) -> Result, Rocket> { - let conn = HildeDbConn::get_one(&rocket).await.expect("database connection"); + let conn = HildeDbConn::get_one(&rocket) + .await + .expect("database connection"); conn.run(|c| match embedded_migrations::run(c) { Ok(()) => Ok(rocket), Err(_) => Err(rocket), - }).await + }) + .await } #[launch] fn rocket() -> _ { rocket::build() .attach(HildeDbConn::fairing()) - .attach(AdHoc::try_on_ignite("Run database migrations", run_db_migrations)) + .attach(AdHoc::try_on_ignite( + "Run database migrations", + run_db_migrations, + )) } From d76a501c355e86a49b0d0df425a81eb36f89efea Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 24 Dec 2021 08:01:59 +0000 Subject: [PATCH 15/17] Update Rust crate diesel to 1.4.8 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ec71b8..1cf7bc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -178,9 +178,9 @@ dependencies = [ [[package]] name = "diesel" -version = "1.4.7" +version = "1.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bba51ca66f57261fd17cadf8b73e4775cc307d0521d855de3f5de91a8f074e0e" +checksum = "b28135ecf6b7d446b43e27e225622a038cc4e2930a1022f51cdb97ada19b8e4d" dependencies = [ "bitflags", "byteorder", diff --git a/Cargo.toml b/Cargo.toml index 6e66641..6375ee6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] rocket = "0.5.0-rc.1" -diesel = { version = "1.4.7", features = ["postgres"] } +diesel = { version = "1.4.8", features = ["postgres"] } diesel_migrations = "1.4.0" [dependencies.rocket_sync_db_pools] From 3311fd2373bc26573e8cb3492bc372472b574b37 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 24 Dec 2021 08:02:01 +0000 Subject: [PATCH 16/17] Update alpine Docker tag to v3.15 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6b28746..c64b43f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN cargo build \ --release -FROM alpine:3.13 +FROM alpine:3.15 COPY --from=builder /src/target/release/hilde /usr/local/bin/hilde From c908dc7e9c433d5f60b86350eb7d99030a99a64b Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 24 Dec 2021 08:02:03 +0000 Subject: [PATCH 17/17] Update rust Docker tag to v1.57 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6b28746..d1ca267 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.53-alpine3.13 AS builder +FROM rust:1.57-alpine3.13 AS builder WORKDIR /src