From be4fdae4d9bab1bd65b79dbdef47c6c2b7167856 Mon Sep 17 00:00:00 2001 From: obscurity Date: Thu, 22 Sep 2022 21:49:28 +0200 Subject: [PATCH 1/4] feat: support `.env` file --- .env | 5 +++++ .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 1 + Dockerfile | 1 + README.md | 2 ++ src/main.rs | 1 + 7 files changed, 18 insertions(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..83261d0 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +PORT= +HOST= +DISCORD_ID= +DISCORD_SECRET= +JWT_SECRET= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0b453ad..1922c35 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ **/target **/build **.idea +**.vscode **.iml /node_modules /.pnp diff --git a/Cargo.lock b/Cargo.lock index be907c3..975c65c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -774,6 +774,12 @@ dependencies = [ "sha2", ] +[[package]] +name = "kankyo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "325a11231fa70c1d1b562655db757cefb6022876d62f173831f35bd670ae0c40" + [[package]] name = "lazy_static" version = "1.4.0" @@ -1905,6 +1911,7 @@ dependencies = [ "hmac", "include_dir", "jwt", + "kankyo", "lazy_static", "openssl", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index c080952..9c8ea19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ include_dir = "0.7" lazy_static = "1.4" thiserror = "1.0" either = "1.7" +kankyo = "0.3" # Explicit dependency to compile openssl from openssl-src instead as a workaround for cross-compilation openssl = { version = "0.10", features = ["vendored"] } diff --git a/Dockerfile b/Dockerfile index 6ec6a6d..ff48368 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,7 @@ ARG TARGETARCH RUN rustup target add $(echo $TARGETARCH | sed 's/arm64/aarch64/;s/amd64/x86_64/')-unknown-linux-musl ADD build.rs ./ +ADD .env ./ ADD src ./src COPY --from=REACT_BUILD /app/build ./build diff --git a/README.md b/README.md index 44f35ef..34e84cd 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ variable below. Copy the secret and id from the OAuth tab to set as environment ### Environment variables +Can be modified in the [.env](./.env) file. + | PORT | TYPE | Default | Description | |------------------|--------|------------------------------------------------------|------------------------------------------------------------------------------| | `PORT` | u16 | 8000 (unmodifiable in debug) | The port to serve the app on | diff --git a/src/main.rs b/src/main.rs index a342fbe..bdbb6c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ mod database; #[launch] fn rocket() -> Rocket { + kankyo::init().expect("failed to read .env file"); let figment = Config::figment() .merge(("port", *constants::PORT)) .merge(("databases.main.url", &*constants::POSTGRES_URL)) From c3909321e98f99002c98c87ce74a0a554f7e5287 Mon Sep 17 00:00:00 2001 From: obscurity Date: Thu, 22 Sep 2022 22:55:14 +0200 Subject: [PATCH 2/4] chore: ignore .env --- .env => .env.local | 0 .gitignore | 1 + README.md | 3 +++ src/main.rs | 4 +++- 4 files changed, 7 insertions(+), 1 deletion(-) rename .env => .env.local (100%) diff --git a/.env b/.env.local similarity index 100% rename from .env rename to .env.local diff --git a/.gitignore b/.gitignore index 1922c35..f0c39e0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /.pnp .pnp.js pnpm-debug.log* +.env diff --git a/README.md b/README.md index 34e84cd..aadc9e4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,10 @@ Can be modified in the [.env](./.env) file. $ pnpm install $ pnpm build $ cargo build --release +# Set environment variables manually $ export PORT=;DISCORD_ID=;DISCORD_SECRET=;HOST=;JWT_SECRET=POSTGRES_URL=; +# or using .env +$ cp .env.local .env $ ./target/release/timezone_db ``` diff --git a/src/main.rs b/src/main.rs index bdbb6c8..45ea6fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,9 @@ mod database; #[launch] fn rocket() -> Rocket { - kankyo::init().expect("failed to read .env file"); + if let Err(e) = kankyo::init() { + println!("{e}"); + }; let figment = Config::figment() .merge(("port", *constants::PORT)) .merge(("databases.main.url", &*constants::POSTGRES_URL)) From ebabe65b62e3b626bce83072a9ba123dd4462675 Mon Sep 17 00:00:00 2001 From: obscurity Date: Fri, 23 Sep 2022 10:20:28 +0200 Subject: [PATCH 3/4] fix: update dockerfile workflow should be to edit .env.local and let docker deal with the renaming --- Dockerfile | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff48368..5207dd7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,8 +48,8 @@ ARG TARGETARCH RUN rustup target add $(echo $TARGETARCH | sed 's/arm64/aarch64/;s/amd64/x86_64/')-unknown-linux-musl ADD build.rs ./ -ADD .env ./ ADD src ./src +COPY .env.local ./.env COPY --from=REACT_BUILD /app/build ./build RUN cargo build --release --target $(echo $TARGETARCH | sed 's/arm64/aarch64/;s/amd64/x86_64/')-unknown-linux-musl diff --git a/README.md b/README.md index aadc9e4..089e1b8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ $ cargo build --release # Set environment variables manually $ export PORT=;DISCORD_ID=;DISCORD_SECRET=;HOST=;JWT_SECRET=POSTGRES_URL=; # or using .env -$ cp .env.local .env +$ mv .env.local .env $ ./target/release/timezone_db ``` From bba62267da4f0e8de5c6581de31e77e1a56bfc8c Mon Sep 17 00:00:00 2001 From: obscurity Date: Sat, 1 Oct 2022 17:37:07 +0200 Subject: [PATCH 4/4] chore: explode --- .env.local => .env.example | 0 Dockerfile | 2 +- README.md | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename .env.local => .env.example (100%) diff --git a/.env.local b/.env.example similarity index 100% rename from .env.local rename to .env.example diff --git a/Dockerfile b/Dockerfile index 5207dd7..ff48368 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,8 +48,8 @@ ARG TARGETARCH RUN rustup target add $(echo $TARGETARCH | sed 's/arm64/aarch64/;s/amd64/x86_64/')-unknown-linux-musl ADD build.rs ./ +ADD .env ./ ADD src ./src -COPY .env.local ./.env COPY --from=REACT_BUILD /app/build ./build RUN cargo build --release --target $(echo $TARGETARCH | sed 's/arm64/aarch64/;s/amd64/x86_64/')-unknown-linux-musl diff --git a/README.md b/README.md index 089e1b8..1d0bfcd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ variable below. Copy the secret and id from the OAuth tab to set as environment ### Environment variables -Can be modified in the [.env](./.env) file. +Can be modified in the [.env](./.env.example) file. | PORT | TYPE | Default | Description | |------------------|--------|------------------------------------------------------|------------------------------------------------------------------------------| @@ -31,7 +31,7 @@ $ cargo build --release # Set environment variables manually $ export PORT=;DISCORD_ID=;DISCORD_SECRET=;HOST=;JWT_SECRET=POSTGRES_URL=; # or using .env -$ mv .env.local .env +$ mv .env.example .env $ ./target/release/timezone_db ```