From 9c3394e7c029af43dec6f63097b1f228d75d77ad Mon Sep 17 00:00:00 2001 From: itsscb Date: Wed, 28 Aug 2024 19:16:41 +0200 Subject: [PATCH 1/5] chore: update nix flake --- flake.lock | 6 +++--- frontend/flake.lock | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index c9233ca..e81bbfc 100644 --- a/flake.lock +++ b/flake.lock @@ -30,11 +30,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1724293269, - "narHash": "sha256-x/XhOAszT/ejditCHUtGOjQcVg2AQhrC/QVew3i7kTI=", + "lastModified": 1724811750, + "narHash": "sha256-PvhVgQ1rm3gfhK7ts4emprhh/KMkFwXogmgsQ3srR7g=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "6dc6d34a3a217457d7044dcce32b6d537480a6a1", + "rev": "6a1c4915dca7149e7258d8c7f3ac634d8c65f6c6", "type": "github" }, "original": { diff --git a/frontend/flake.lock b/frontend/flake.lock index 3d19717..4aae639 100644 --- a/frontend/flake.lock +++ b/frontend/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1724015816, - "narHash": "sha256-hVESnM7Eiz93+4DeiE0a1TwMeaeph1ytRJ5QtqxYRWg=", + "lastModified": 1724748588, + "narHash": "sha256-NlpGA4+AIf1dKNq76ps90rxowlFXUsV9x7vK/mN37JM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9aa35efbea27d320d0cdc5f922f0890812affb60", + "rev": "a6292e34000dc93d43bccf78338770c1c5ec8a99", "type": "github" }, "original": { @@ -62,11 +62,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1724034091, - "narHash": "sha256-b1g7w0sw+MDAhUAeCoX1vlTghsqcDZkxr+k9OZmxPa8=", + "lastModified": 1724811750, + "narHash": "sha256-PvhVgQ1rm3gfhK7ts4emprhh/KMkFwXogmgsQ3srR7g=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "c7d36e0947826e0751a5214ffe82533fbc909bc0", + "rev": "6a1c4915dca7149e7258d8c7f3ac634d8c65f6c6", "type": "github" }, "original": { From 4fd67f932b4295e749911e9e0f7840236ab9c883 Mon Sep 17 00:00:00 2001 From: itsscb Date: Wed, 28 Aug 2024 19:23:45 +0200 Subject: [PATCH 2/5] feat(nix): improves flake to work with vs code --- flake.lock | 57 ++++++++++++++++++++++++++++++--- flake.nix | 93 ++++++++++++++++++++---------------------------------- 2 files changed, 86 insertions(+), 64 deletions(-) diff --git a/flake.lock b/flake.lock index e81bbfc..4aae639 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,40 @@ { "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { + "locked": { + "lastModified": 1724748588, + "narHash": "sha256-NlpGA4+AIf1dKNq76ps90rxowlFXUsV9x7vK/mN37JM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a6292e34000dc93d43bccf78338770c1c5ec8a99", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1718428119, "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", @@ -18,16 +52,14 @@ }, "root": { "inputs": { - "nixpkgs": [ - "rust-overlay", - "nixpkgs" - ], + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay" } }, "rust-overlay": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs_2" }, "locked": { "lastModified": 1724811750, @@ -42,6 +74,21 @@ "repo": "rust-overlay", "type": "github" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 53359a2..e7a0e0f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,67 +1,42 @@ { description = "Example Rust development environment for Zero to Nix"; - # Flake inputs inputs = { - # nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz"; - rust-overlay.url = "github:oxalica/rust-overlay"; # A helper for Rust + Nix - # cargo2nix.url = "github:cargo2nix/cargo2nix/"; - nixpkgs.follows = "rust-overlay/nixpkgs"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; }; - # Flake outputs - outputs = { self, nixpkgs, rust-overlay}: - let - # Overlays enable you to customize the Nixpkgs attribute set - overlays = [ - # Makes a `rust-bin` attribute available in Nixpkgs - (import rust-overlay) - # Provides a `rustToolchain` attribute for Nixpkgs that we can use to - # create a Rust environment - (self: super: { - rustToolchain = super.rust-bin.stable.latest.default; - }) - ]; - - # Systems supported - allSystems = [ - "x86_64-linux" # 64-bit Intel/AMD Linux - "aarch64-linux" # 64-bit ARM Linux - "x86_64-darwin" # 64-bit Intel macOS - "aarch64-darwin" # 64-bit ARM macOS - ]; - - # rustTarget = nixpkgs.pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override { - # extensions = [ "rust-src" "rustup" "rust-analyzer" "rust-std" ]; - # targets = [ "x86_64-unknown-linux-gnu" "wasm32-unknown-unknown" ]; - # }); - - # Helper to provide system-specific attributes - forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { - pkgs = import nixpkgs { inherit overlays system; }; - }); - in - { - # Development environment output - devShells = forAllSystems ({ pkgs }: { - default = pkgs.mkShell { - buildInputs = [ - pkgs.cargo-shuttle - ]; - # shellHook = '' - # rustup target add wasm32-unknown-unknown - # ''; - # The Nix packages provided in the environment - packages = (with pkgs; [ - # The package provided by our custom overlay. Includes cargo, Clippy, cargo-fmt, - # rustdoc, rustfmt, and other tools. - rust-analyzer - clippy - trunk - tailwindcss - rustToolchain - ]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]); + outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; }; - }); - }; + rustToolchain = pkgs.rust-bin.nightly.latest.default.override { + extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ]; + targets = [ "x86_64-unknown-linux-gnu" "wasm32-unknown-unknown" ]; + }; + in + { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + rustToolchain + trunk + clippy + tailwindcss + cargo-shuttle + ]; + + shellHook = '' + export PATH=${rustToolchain}/bin:$PATH + export RUSTC_VERSION=$(rustc --version) + export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library" + ''; + + packages = pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]); + }; + } + ); } From 6294021cfb92e70135e96fae841b68b1083990b4 Mon Sep 17 00:00:00 2001 From: itsscb Date: Wed, 28 Aug 2024 19:24:44 +0200 Subject: [PATCH 3/5] feat(nix): adds clippy --- frontend/flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/flake.nix b/frontend/flake.nix index 903da15..42df65c 100644 --- a/frontend/flake.nix +++ b/frontend/flake.nix @@ -24,6 +24,7 @@ buildInputs = with pkgs; [ rustToolchain trunk + clippy tailwindcss ]; From c612aa9bac806072c0921b9b32ec82e5d8bf9a21 Mon Sep 17 00:00:00 2001 From: itsscb Date: Wed, 28 Aug 2024 20:05:20 +0200 Subject: [PATCH 4/5] chore: updates dependencies --- Cargo.toml | 6 +++--- flake.nix | 7 +++++++ frontend/Cargo.toml | 4 ++-- frontend/tailwind.config.js | 16 ++++++---------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2f06763..b659d9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,11 +4,11 @@ version = "0.1.0" edition = "2021" [dependencies] -axum = "0.7.4" +axum = "0.7.5" http = "1.1.0" rand = "0.8.5" -shuttle-axum = "0.45.0" -shuttle-runtime = "0.45.0" +shuttle-axum = "0.47.0" +shuttle-runtime = "0.47.0" tower-http = { version = "0.5.2", features = ["fs", "cors"] } tracing = "0.1.40" diff --git a/flake.nix b/flake.nix index e7a0e0f..adf3ea8 100644 --- a/flake.nix +++ b/flake.nix @@ -27,12 +27,19 @@ clippy tailwindcss cargo-shuttle + cargo-edit + + openssl + pkg-config ]; shellHook = '' export PATH=${rustToolchain}/bin:$PATH export RUSTC_VERSION=$(rustc --version) export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library" + export OPENSSL_DIR="${pkgs.openssl.dev}" + export OPENSSL_LIB_DIR="${pkgs.openssl.out}/lib" + export OPENSSL_INCLUDE_DIR="${pkgs.openssl.dev}/include" ''; packages = pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ libiconv ]); diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml index 8a41701..304fff5 100644 --- a/frontend/Cargo.toml +++ b/frontend/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -web-sys = { version = "0.3.69", features = [ +web-sys = { version = "0.3.70", features = [ "HtmlElement", "HtmlInputElement", "KeyboardEvent", @@ -17,4 +17,4 @@ wasm-bindgen-futures = "0.4.43" wasm-bindgen = "0.2.93" yewdux = "0.10.0" gloo-net = "0.6.0" -serde = { version = "1.0.198", features = ["derive"] } \ No newline at end of file +serde = { version = "1.0.209", features = ["derive"] } diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js index dc3cb54..deb6901 100644 --- a/frontend/tailwind.config.js +++ b/frontend/tailwind.config.js @@ -1,14 +1,10 @@ module.exports = { - purge: { - mode: "all", - content: [ - "./src/**/*.rs", - "./src/pages/documents.rs", - "./index.html", - "./src/**/*.html", - "./src/**/*.css", - ], - }, + content: [ + "./src/**/*.rs", + "./index.html", + "./src/**/*.html", + "./src/**/*.css", + ], theme: {}, variants: {}, plugins: [], From ed99f87d621982a3d21c2484de205d18b399e47a Mon Sep 17 00:00:00 2001 From: itsscb Date: Wed, 28 Aug 2024 20:20:09 +0200 Subject: [PATCH 5/5] fix(workflow): frontend build not working properly --- .github/workflows/prod.yml | 43 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 0525fac..c028473 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -7,10 +7,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout + - name: checkout uses: actions/checkout@v4 - - name: Cache dependencies + - name: cache dependencies uses: actions/cache@v4 with: path: | @@ -19,66 +19,61 @@ jobs: ~/.cache/trunk/ target/ node_modules/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock') }} restore-keys: ${{ runner.os }}-cargo-wordl - - name: Install Rust + - name: install rust uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable - - name: Add Rust target wasm32-unknown-unknown + - name: add rust target wasm32-unknown-unknown run: rustup target add wasm32-unknown-unknown - - name: Install Trunk + - name: install trunk run: cargo install trunk - - name: Install Node.js + - name: install node.js uses: actions/setup-node@v4 with: node-version: 20 - - name: Install Tailwind CSS + - name: install tailwindcss run: npm install -g tailwindcss - - name: Build Frontend + - name: build frontend working-directory: ./frontend/ run: | trunk build --release - - name: Commit Frontend Release Build - run: | - git config --global user.name "github-actions" - git config --global user.email "dev@itsscb.de" - git add -A - git commit -m "release: frontend" - git push - - - name: Upload Frontend Artifacts + - name: upload frontend artifacts uses: actions/upload-artifact@v4 with: name: frontend-artifacts path: ./frontend/dist - - - name: Build and test code + - name: run tests run: | - cargo build --verbose --release cargo test --verbose deploy: runs-on: ubuntu-latest needs: build steps: - - name: Download Frontend Artifacts + - name: checkout + uses: actions/checkout@v4 + + - name: download frontend artifacts uses: actions/download-artifact@v4 with: name: frontend-artifacts - - name: Checkout - uses: actions/checkout@v4 + - name: display structure of downloaded files + run: ls -R + working-directory: ./frontend/dist - uses: shuttle-hq/deploy-action@main with: deploy-key: ${{ secrets.SHUTTLE_API_KEY }} + working-directory: .