From 6e19ac5a639a0ea0e845a42a771848d1f22a054d Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sat, 19 Jun 2021 11:54:46 +0200 Subject: [PATCH 1/8] 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" ] -- 2.40.1 From a696888e110670331fb62c149bf77b8ac22ad08e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sat, 19 Jun 2021 12:14:57 +0200 Subject: [PATCH 2/8] 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 ] -- 2.40.1 From 0eeea1e59314fe15c27048a3024037c90f9fe28b Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 11:32:50 +0200 Subject: [PATCH 3/8] 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/ -- 2.40.1 From fa5ee06a04f10b13c55248024c07c65860b3ecce Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 11:37:45 +0200 Subject: [PATCH 4/8] 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 -- 2.40.1 From 89bc9b91e15523f151e8ad67251b497e9839865f Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 12:07:33 +0200 Subject: [PATCH 5/8] 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 ] -- 2.40.1 From 68a19258d499bb248448145e6d11181878413183 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 12:48:45 +0200 Subject: [PATCH 6/8] 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 . -- 2.40.1 From 49007e7a8f0685c6faad0d2383401b6ee0737951 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 12:51:17 +0200 Subject: [PATCH 7/8] 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 -- 2.40.1 From ad522107362a6309c26a6c05134e66fa31bd4024 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 25 Jun 2021 13:00:57 +0200 Subject: [PATCH 8/8] 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 -- 2.40.1