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/.editorconfig b/.editorconfig new file mode 100644 index 0000000..77e3fe3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +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 diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..cb88ba5 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,77 @@ +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: + - 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 + + + # =====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 + + 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 ] 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..8840167 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +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/ + +RUN cargo build \ + --release + + +FROM alpine:3.13 + +COPY --from=builder /src/target/release/hilde /usr/local/bin/hilde + +ENTRYPOINT [ "/usr/local/bin/hilde" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..be507fd --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +# 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 . +.PHONY: image