diff --git a/.dockerignore b/.dockerignore index 3ae4abc41..7618ef07d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,10 +5,9 @@ dist static apps/server/client target -*.lock -*-lock.* *.log *.db +.git # ignore contents in excess directories, some are kept only so cargo # doesn't yell at me diff --git a/.github/actions/build-desktop/action.yml b/.github/actions/build-desktop/action.yml new file mode 100644 index 000000000..615d3cb8e --- /dev/null +++ b/.github/actions/build-desktop/action.yml @@ -0,0 +1,37 @@ +name: 'Build Stump desktop app' +description: 'Compile the Stump desktop app' + +inputs: + platform: + description: 'The plaform of the runner' + required: true + +runs: + using: composite + steps: + - name: Checkout project + uses: actions/checkout@v3 + + # - name: Configure environment + # run: | + # if [[ ${{ inputs.platform }} == 'linux' || ${{ inputs.platform }} == 'windows' ]]; then + # echo "RUN_SETUP=false" >> $GITHUB_ENV + # else + # echo "RUN_SETUP=true" >> $GITHUB_ENV + # fi + + - name: Setup rust + uses: ./.github/actions/setup-cargo + + - name: Generate Prisma client + uses: ./.github/actions/setup-prisma + + - name: Copy bundled web app + uses: actions/download-artifact@v3 + with: + name: webapp + path: ./apps/desktop/dist + + - name: Compile desktop app + shell: bash + run: cargo build --package stump_desktop --release diff --git a/.github/actions/build-docker/action.yml b/.github/actions/build-docker/action.yml new file mode 100644 index 000000000..a0728c16f --- /dev/null +++ b/.github/actions/build-docker/action.yml @@ -0,0 +1,97 @@ +name: 'Build docker image' +description: 'Build and load or push a tagged docker image for stump' + +inputs: + username: + description: 'Username for docker login' + required: true + password: + description: 'Token for docker login' + required: true + load: + description: 'Set output-type to docker' + default: true + push: + description: 'Set output-type to registry' + default: false + tags: + description: 'List of tags to assigned to the image' + default: 'nightly' + platforms: + description: 'List of platforms to build' + required: true + +runs: + using: composite + steps: + - name: Get commit short sha + run: echo "GIT_REV=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV + shell: bash + + - name: Format tags + run: | + echo "TAGS=$(echo ${{ inputs.tags }} | sed -e 's/,/,aaronleopold\/stump:/g' | sed -e 's/^/aaronleopold\/stump:/')" >> $GITHUB_ENV + shell: bash + + - name: Setup rust + uses: ./.github/actions/setup-cargo + + - name: Generate Prisma client + uses: ./.github/actions/setup-prisma + + # TODO: uncomment once cache stuff is resolved... + # - name: Setup Docker layers cache + # uses: actions/cache@v3 + # with: + # path: /tmp/.buildx-cache + # key: ${{ runner.os }}-buildx-${{ github.sha }} + # restore-keys: | + # ${{ runner.os }}-buildx- + + # We only need QEMU when an arm* platform is targeted + - name: Check QEMU requirement + id: check-qemu + run: | + if [[ ${{ inputs.platforms }} == *"arm"* ]]; then + echo "SETUP_QEMU=1" >> $GITHUB_OUTPUT + else + echo "SETUP_QEMU=0" >> $GITHUB_OUTPUT + fi + shell: bash + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + if: ${{ steps.check-qemu.outputs.SETUP_QEMU == '1' }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ inputs.username }} + password: ${{ inputs.password }} + + - name: Run buildx build + uses: docker/build-push-action@v4 + with: + context: . + build-args: | + "GIT_REV=${{ env.GIT_REV }}" + file: scripts/release/Dockerfile + platforms: ${{ inputs.platforms }} + load: ${{ inputs.load }} + push: ${{ inputs.push }} + tags: ${{ env.TAGS }} + # TODO: uncomment once cache stuff is resolved... + # cache-from: type=local,src=/tmp/.buildx-cache + # cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + # https://github.com/docker/build-push-action/issues/252 + # TODO: https://github.com/moby/buildkit/issues/1896 + # TODO: uncomment once cache stuff is resolved... + # - name: Move buildx cache + # run: | + # rm -rf /tmp/.buildx-cache + # mv /tmp/.buildx-cache-new /tmp/.buildx-cache + # shell: bash diff --git a/.github/actions/build-server/action.yml b/.github/actions/build-server/action.yml index d8d944b43..f8a96739a 100644 --- a/.github/actions/build-server/action.yml +++ b/.github/actions/build-server/action.yml @@ -1,9 +1,9 @@ -name: 'Compile rust' -description: 'Compile stump rust server' +name: 'Build Stump server' +description: 'Compile the Stump Rust server' inputs: platform: - description: 'runner plaform' + description: 'The plaform of the runner' required: true runs: @@ -12,21 +12,26 @@ runs: - name: Checkout project uses: actions/checkout@v3 + # - name: Configure environment + # run: | + # if [[ ${{ inputs.platform }} == 'linux' || ${{ inputs.platform }} == 'windows' ]]; then + # echo "RUN_SETUP=false" >> $GITHUB_ENV + # else + # echo "RUN_SETUP=true" >> $GITHUB_ENV + # fi + - name: Setup rust - uses: ./.github/actions/setup-system + uses: ./.github/actions/setup-cargo - name: Generate Prisma client uses: ./.github/actions/setup-prisma - - name: Download frontend + + - name: Copy bundled web app uses: actions/download-artifact@v3 with: - name: web + name: webapp path: ./apps/server/dist - - name: Copy web app to tauri - run: cp -r ./apps/server/dist apps/desktop/dist - shell: bash - - - name: Build server + - name: Compile server shell: bash - run: cargo build --release + run: cargo build --package stump_server --release diff --git a/.github/actions/build-web/action.yml b/.github/actions/build-web/action.yml index a72795a25..9a39f4517 100644 --- a/.github/actions/build-web/action.yml +++ b/.github/actions/build-web/action.yml @@ -1,14 +1,27 @@ -name: 'Build Web Application' -description: "Build web application and upload it's artifacts" +name: 'Compile Web Application' +description: 'Compile stump web' runs: - using: 'composite' + using: composite steps: - - name: Build - uses: ./.github/actions/compile-web + - name: Checkout project + uses: actions/checkout@v3 - - name: Upload + - name: Setup pnpm + uses: ./.github/actions/setup-pnpm + + - name: Install dependencies + shell: bash + run: pnpm install + working-directory: apps/web + + - name: Build app + shell: bash + run: pnpm run build + working-directory: apps/web + + - name: Upload bundle uses: ./.github/actions/upload-artifact with: - upload-name: web + upload-name: webapp upload-path: apps/web/dist diff --git a/.github/actions/compile-web/action.yml b/.github/actions/compile-web/action.yml deleted file mode 100644 index efcf33345..000000000 --- a/.github/actions/compile-web/action.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: 'Compile Web Application' -description: 'Compile stump web' - -runs: - using: composite - steps: - - name: Checkout project - uses: actions/checkout@v3 - - - uses: ./.github/actions/setup-pnpm - - - name: Install dependencies - shell: bash - run: pnpm install - working-directory: apps/web - - - name: Build app - shell: bash - run: pnpm run build - working-directory: apps/web diff --git a/.github/actions/setup-cargo/action.yml b/.github/actions/setup-cargo/action.yml index b67987b2e..84bf59567 100644 --- a/.github/actions/setup-cargo/action.yml +++ b/.github/actions/setup-cargo/action.yml @@ -4,7 +4,17 @@ description: 'Install system dependencies and setup cache' runs: using: 'composite' steps: + - name: Configure environment + run: | + if [[ ${{ runner.name }} == 'manjaro-az' || ${{ runner.os }} == 'Windows' ]]; then + echo "RUN_SETUP=false" >> $GITHUB_ENV + else + echo "RUN_SETUP=true" >> $GITHUB_ENV + fi + shell: bash + - name: System setup + if: ${{ env.RUN_SETUP == 'true' }} shell: bash run: CHECK_NODE=0 CHECK_CARGO=0 DEV_SETUP=0 ./scripts/system-setup.sh diff --git a/.github/actions/setup-prisma/action.yaml b/.github/actions/setup-prisma/action.yaml index 7e1470e33..1f9d7ded9 100644 --- a/.github/actions/setup-prisma/action.yaml +++ b/.github/actions/setup-prisma/action.yaml @@ -11,7 +11,7 @@ runs: key: ${{ runner.os }}-prisma-${{ hashFiles('**/schema.prisma') }} - name: Generate Prisma client - working-directory: core + # working-directory: core if: steps.cache-prisma.outputs.cache-hit != 'true' shell: bash - run: cargo run -p prisma --release -- generate + run: cargo prisma generate --schema=./core/prisma/schema.prisma diff --git a/.github/actions/upload-artifact/action.yml b/.github/actions/upload-artifact/action.yml index 1073af517..c7a0beb51 100644 --- a/.github/actions/upload-artifact/action.yml +++ b/.github/actions/upload-artifact/action.yml @@ -2,7 +2,6 @@ name: 'Upload Local' description: 'Upload artifact to local action' inputs: - # Upload upload-name: required: true description: 'Name of the upload' diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml index f09910002..af420f537 100644 --- a/.github/workflows/build_nix.yml +++ b/.github/workflows/build_nix.yml @@ -1,4 +1,4 @@ -name: "Build legacy Nix package on Ubuntu" +name: 'Stump Nix CI' on: push: @@ -15,5 +15,5 @@ jobs: - uses: cachix/install-nix-action@v17 - name: test run: nix develop --command "pkg-config" "--libs" "--cflags" "gdk-3.0" "gdk-3.0 >= 3.22" - # - name: Building package + # - name: Building package # run: nix develop --command pnpm core run setup && cargo check diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 07fc8a2ae..24a022a70 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: Stump-CI +name: 'Stump Checks CI' on: pull_request: @@ -6,12 +6,11 @@ on: branches: - main +# TODO: figure out how to use moon here. jobs: check-rust: name: Rust checks - runs-on: ubuntu-latest - # TODO: remove this once I have my own, hosted runner... - if: github.ref == 'refs/heads/main' + runs-on: [self-hosted] steps: - name: Checkout repository uses: actions/checkout@v3 @@ -26,52 +25,23 @@ jobs: run: | cargo fmt --all -- --check cargo clippy -- -D warnings - - name: Run tests - run: | - cargo integration-tests + # TODO: fix the tests, then uncomment this + # - name: Run tests + # run: | + # cargo integration-tests check-typescript: name: TypeScript checks - runs-on: ubuntu-latest + runs-on: [self-hosted] steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Setup pnpm and typescript + - name: Setup PNPM and TypeScript uses: ./.github/actions/setup-pnpm - - name: lint + - name: Run TypeScript lints run: pnpm lint # - name: typecheck # run: pnpm moon run :typecheck - - # release: - # name: Release (${{ matrix.platform }}) - # runs-on: ${{ matrix.platform }} - # # Release only runs on push to main. TODO: can I make this trigger on tag? - # if: github.event_name != 'pull_request' - # strategy: - # fail-fast: true - # matrix: - # platform: [ubuntu-latest, macos-latest, windows-latest] - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 - - # - name: Install Rust - # uses: actions-rs/toolchain@v1 - # with: - # toolchain: stable - # profile: minimal - # override: true - # # TODO: clippy?? - # components: rustfmt, rust-src - - # # TODO: figure out caching for rust deps - - # - name: Generate Prisma client - # uses: ./.github/actions/generate-prisma-client - - # TODO: pnpm setup - # TODO: docker builds -> maybe this helps? https://github.com/devture/matrix-corporal/blob/master/.gitlab-ci.yml diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d83a24d59..e49c7655c 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,24 +1,65 @@ -name: Stump-nightly - -# on: -# schedule: -# # * is a special character in YAML so you have to quote this string -# - cron: '0 1 * * *' -# workflow_dispatch: +name: 'Stump Nightly CI' on: pull_request: branches: - - 'nightly' + - develop + - main + push: + branches: + - develop + +# TODO: should I push nightly on main pushes? then on tag, an actual tagged release? + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }} jobs: + docker-build: + name: Build docker image + runs-on: [self-hosted] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # On PRs, we will only load the image into docker for the quickest platform + # (i.e. linux/amd64). This is mostly a smoke test, just rather ignorant verification + # that the image can be built. On pushes, we will actually build and push for + # all supported platforms. + - name: Configure environment + run: | + echo "LOAD=${{ github.event_name == 'pull_request' }}" >> $GITHUB_ENV + echo "PUSH=${{ github.event_name == 'push' }}" >> $GITHUB_ENV + + if [[ ${{ github.event_name }} == 'pull_request' ]]; then + echo "PLATFORMS=${{ vars.SUPPORTED_PR_DOCKER_PLATFORMS }}" >> $GITHUB_ENV + else + echo "PLATFORMS=${{ vars.SUPPORTED_DOCKER_PLATFORMS }}" >> $GITHUB_ENV + fi + + - name: Setup and build docker image + uses: ./.github/actions/build-docker + with: + username: ${{ env.DOCKER_USERNAME }} + password: ${{ env.DOCKER_PASSWORD }} + tags: 'nightly' + load: ${{ env.LOAD }} + push: ${{ env.PUSH }} + platforms: ${{ env.PLATFORMS }} + + # TODO: build executables for apple(x86_64,darwin?),linux(x86_64,arm64?), and windows(x86_64) + # These should be uploaded to the nightly release as artifacts. Old artifacts should be deleted + # before uploading new ones. + build-web: - strategy: - fail-fast: true - matrix: - plaform: [ubuntu-20.04] - name: Build web application - runs-on: ${{ matrix.plaform }} + name: Bundle web app + runs-on: [self-hosted] + if: false # TODO: don't do that steps: - name: Checkout repository uses: actions/checkout@v3 @@ -29,17 +70,38 @@ jobs: - name: Upload web build uses: ./.github/actions/upload-artifact with: - upload-name: web + upload-name: webapp upload-path: apps/web/dist + build-linux-server: + name: Compile server app (self-hosted linux) + needs: build-web + runs-on: [self-hosted] + if: false # TODO: don't do that + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Build server + uses: ./.github/actions/build-server + with: + platform: 'linux' + + - name: Upload stump server + uses: ./.github/actions/upload-artifact + with: + upload-name: stump_server-linux + upload-path: target/release/stump_server + build-server: strategy: fail-fast: true matrix: - plaform: [ubuntu-20.04] # We should probably build for window and macos - name: Build server and desktop - runs-on: ${{ matrix.plaform }} + platform: [macos, windows] + name: Compile server app needs: build-web + runs-on: ${{ matrix.platform }} + if: false # TODO: don't do that steps: - name: Checkout repository uses: actions/checkout@v3 @@ -47,18 +109,64 @@ jobs: - name: Build server uses: ./.github/actions/build-server with: - platform: ${{ matrix.plaform }} + platform: ${{ matrix.platform }} - name: Upload stump server uses: ./.github/actions/upload-artifact with: - upload-name: stump_server + upload-name: stump_server-${{ matrix.platform }} upload-path: target/release/stump_server - - uses: tauri-apps/tauri-action@v0 + # build-linux-desktop: + # name: Compile desktop app (self-hosted linux) + # needs: build-web + # runs-on: [self-hosted] + # if: false # TODO: don't do that + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 - - name: Upload desktop - uses: ./.github/actions/upload-artifact + # - name: Build desktop + # uses: ./.github/actions/build-desktop + # with: + # platform: 'linux' + + # - name: Upload desktop + # uses: ./.github/actions/upload-artifact + # with: + # upload-name: stump-desktop-linux + # upload-path: target/release/bundle + + build-desktop: + strategy: + fail-fast: true + matrix: + platform: [macos, windows] + name: Compile desktop app + needs: build-web + runs-on: ${{ matrix.platform }} + if: false # TODO: don't do that + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Build desktop + uses: ./.github/actions/build-desktop with: - upload-name: stump-desktop - upload-path: target/release/bundle + platform: ${{ matrix.platform }} + + # https://github.com/tauri-apps/tauri-action + # - uses: tauri-apps/tauri-action@v0 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # tagName: stump-desktop-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version + # releaseName: 'Stump Desktop v__VERSION__' + # releaseBody: 'See the assets to download this version and install.' + # releaseDraft: true + # prerelease: true + + # - name: Upload desktop + # uses: ./.github/actions/upload-artifact + # with: + # upload-name: stump-desktop-${{ matrix.platform }} + # upload-path: target/release/bundle diff --git a/.gitignore b/.gitignore index 6a933ccdd..f08f63794 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,8 @@ logs/ build/ coverage/ cjs/ -dist/ +**/*/dist/**/* +!**/*/dist/.placeholder dts/ esm/ lib/ diff --git a/.vscode/.todo b/.vscode/.todo index ca4ef7813..ea96ecb86 100644 --- a/.vscode/.todo +++ b/.vscode/.todo @@ -76,3 +76,5 @@ - [ ] Make light mode look not disgusting lmao - [ ] ~Fix poor performance of EditLibraryModal~ - [ ] Just replace the modals with dedicated pages for editing and creating libraries +- [ ] `local-ip-address` check if release yoinked comes back okay +- [ ] cargo report future-incompatibilities --id 4 --package rustc-serialize@0.3.24 diff --git a/Cargo.lock b/Cargo.lock index 24f7a3bf4..4beb62177 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2544,8 +2544,7 @@ dependencies = [ [[package]] name = "local-ip-address" version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faa9d02443a1741e9f51dafdfcbffb3863b2a89c457d762b40337d6c5153ef81" +source = "git+https://github.com/EstebanBorai/local-ip-address.git?tag=v0.5.1#efb3a0b074ea9540bb055f1fe8f0fc5a5591b6bf" dependencies = [ "libc", "neli", diff --git a/Cargo.toml b/Cargo.toml index ac2f92b77..37ed18db0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ members = [ [workspace.package] version = "0.0.0" -rust-version = "1.64.0" +rust-version = "1.68.0" [workspace.dependencies] prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust.git", tag = "0.6.4", features = [ diff --git a/README.md b/README.md index f1b88fa2e..d5b3286a8 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ - - Docker Pulls + + Docker Pulls

@@ -37,7 +37,7 @@ Stump is a free and open source comics, manga and digital book server with OPDS - [Roadmap 🗺](#roadmap-) - [Getting Started 🚀](#getting-started-) - [Developer Guide 💻](#developer-guide-) - - [Where to start?](#where-to-start) + - [Where to start?](#where-to-start) - [Project Structure 📦](#project-structure-) - [/apps](#apps) - [/packages](#packages) @@ -80,7 +80,7 @@ I am very open to suggestions and ideas, so feel free to reach out if you have a Stump isn't ready for normal, non-development usage yet. Once a release has been made, this will be updated. For now, follow the [Developing](#developing-) section to build from source and run locally. -There is a [docker image](https://hub.docker.com/repository/docker/aaronleopold/stump-preview) available for those interested. However, **this is only meant for testing purposes and will not be updated frequently**, so do not expect a fully featured, bug-free experience if you spin up a container. Also keep in mind migrations won't be stacked until a release, so each update until then might require a wipe of the database file. +There is a [docker image](https://hub.docker.com/repository/docker/aaronleopold/stump) available for those interested. However, **this is only meant for testing purposes and will not be updated frequently**, so do not expect a fully featured, bug-free experience if you spin up a container. Also keep in mind migrations won't be stacked until a release, so each update until then might require a wipe of the database file. For more information about getting started, how Stump works and how it manages your library, and much more, please visit [stumpapp.dev](https://stumpapp.dev/guides). diff --git a/apps/server/Cargo.toml b/apps/server/Cargo.toml index 9d8a0e4ef..b5174a2e6 100644 --- a/apps/server/Cargo.toml +++ b/apps/server/Cargo.toml @@ -31,7 +31,10 @@ serde = { workspace = true } axum-sessions = "0.4.1" async-trait = "0.1.53" async-stream = { workspace = true } -local-ip-address = "0.5.1" +# TODO: figure out this super fucking annoying cargo dependency resolution issue. This is the second time +# cargo, in docker, has ignored the workspace version of this dep and instead used the latest version from crates.io +# local-ip-address = "0.5.1" +local-ip-address = { git = "https://github.com/EstebanBorai/local-ip-address.git", tag = "v0.5.1" } ### Dev Utils ### diff --git a/apps/server/src/routers/api/v1/log.rs b/apps/server/src/routers/api/v1/log.rs index b03997cfb..c516e2a0b 100644 --- a/apps/server/src/routers/api/v1/log.rs +++ b/apps/server/src/routers/api/v1/log.rs @@ -50,7 +50,6 @@ async fn get_logs() -> ApiResult<()> { )] /// Get information about the Stump log file, located at STUMP_CONFIG_DIR/Stump.log, or /// ~/.stump/Stump.log by default. Information such as the file size, last modified date, etc. -// #[get("/logs")] async fn get_logfile_info(session: ReadableSession) -> ApiResult> { get_session_admin_user(&session)?; let log_file_path = get_log_file(); diff --git a/apps/web/dist/.placeholder b/apps/web/dist/.placeholder new file mode 100644 index 000000000..32f95c0d1 --- /dev/null +++ b/apps/web/dist/.placeholder @@ -0,0 +1 @@ +hi \ No newline at end of file diff --git a/core/src/db/models/log.rs b/core/src/db/models/log.rs index 1ce04b2f3..0059a0a84 100644 --- a/core/src/db/models/log.rs +++ b/core/src/db/models/log.rs @@ -15,24 +15,19 @@ pub struct LogMetadata { pub modified: String, } -#[derive(Clone, Serialize, Deserialize, Type, ToSchema)] +#[derive(Clone, Default, Serialize, Deserialize, Type, ToSchema)] pub enum LogLevel { #[serde(rename = "ERROR")] Error, #[serde(rename = "WARN")] Warn, #[serde(rename = "INFO")] + #[default] Info, #[serde(rename = "DEBUG")] Debug, } -impl Default for LogLevel { - fn default() -> Self { - LogLevel::Info - } -} - impl std::fmt::Display for LogLevel { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { diff --git a/core/src/prelude/enums.rs b/core/src/prelude/enums.rs index ed25d0422..f081efc6a 100644 --- a/core/src/prelude/enums.rs +++ b/core/src/prelude/enums.rs @@ -4,11 +4,12 @@ use serde::{Deserialize, Serialize}; use specta::Type; use utoipa::ToSchema; -#[derive(Serialize, Deserialize, Type, ToSchema)] +#[derive(Serialize, Deserialize, Type, ToSchema, Default)] pub enum UserRole { #[serde(rename = "SERVER_OWNER")] ServerOwner, #[serde(rename = "MEMBER")] + #[default] Member, } @@ -67,12 +68,6 @@ impl FromStr for FileStatus { } } -impl Default for UserRole { - fn default() -> Self { - UserRole::Member - } -} - impl From for String { fn from(role: UserRole) -> String { match role { diff --git a/core/src/prelude/server/query.rs b/core/src/prelude/server/query.rs index fcebd3905..1358bafe4 100644 --- a/core/src/prelude/server/query.rs +++ b/core/src/prelude/server/query.rs @@ -7,20 +7,15 @@ use crate::{ prisma::{library, media, series}, }; -#[derive(Debug, Serialize, Deserialize, Clone, Type, ToSchema)] +#[derive(Debug, Default, Serialize, Deserialize, Clone, Type, ToSchema)] pub enum Direction { #[serde(rename = "asc")] Asc, #[serde(rename = "desc")] + #[default] Desc, } -impl Default for Direction { - fn default() -> Self { - Direction::Asc - } -} - impl From for prisma_client_rust::Direction { fn from(direction: Direction) -> prisma_client_rust::Direction { match direction { diff --git a/package.json b/package.json index e4378bd4f..0afa3348e 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,6 @@ "build:server": "pnpm run server build", "build:web": "pnpm web build && pnpm build:server", "build:desktop": "pnpm desktop build", - "build:docker": "docker buildx build -f scripts/release/Dockerfile --push --platform=linux/arm64/v8,linux/amd64 -t aaronleopold/stump-preview:latest .", - "cache:docker": "docker buildx build -f scripts/release/Dockerfile --load --platform=linux/arm64/v8,linux/amd64 -t aaronleopold/stump-preview:latest .", - "cache:docker-arm": "docker buildx build -f scripts/release/Dockerfile --load --platform=linux/arm64/v8 -t aaronleopold/stump-preview:latest .", - "build:docker-amd": "docker buildx build -f scripts/release/Dockerfile --push --platform=linux/amd64 -t aaronleopold/stump-preview:latest .", "moon": "moon --color --log trace" }, "devDependencies": { diff --git a/scripts/lib b/scripts/lib new file mode 100644 index 000000000..203e9b69e --- /dev/null +++ b/scripts/lib @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +log_error() { + echo $1 1>&2 + exit 1 +} + +create_dummy_rust_file() { + local path=$1 + echo "Creating dummy Rust file in $path" + mkdir -p $path/src + if [[ $path == "core" ]]; then + echo 'fn foo() { println!("Wow, such empty!"); }' > $path/src/lib.rs + else + echo 'fn main() { println!("Wow, such empty!"); }' > $path/src/main.rs + fi + +} + +# prisma uses some `include_str!` macros that are mapped to locations on the host machine. so +# when we build in docker, we need to correct these paths according to the docker workdir. +# it's a bit of a hack, but it works lol +prisma_sed_correction() { + set -ex; \ + sed -i 's|\/.*\/core\/prisma\/schema.prisma|\/app\/core\/prisma\/schema.prisma|g' core/src/prisma.rs; \ + sed -i 's|\/.*\/core\/prisma\/migrations|\/app\/core\/prisma\/migrations|g' core/src/prisma.rs +} + +workspaces_sed_correction() { + set -ex; \ + sed -i '/core\/integration-tests/d' Cargo.toml; \ + sed -i '/apps\/desktop\/src-tauri/d' Cargo.toml; \ + sed -i '/apps\/tui/d' Cargo.toml; \ + sed -i '/packages\/prisma-cli/d' Cargo.toml +} \ No newline at end of file diff --git a/scripts/prisma-sed.sh b/scripts/prisma-sed.sh deleted file mode 100644 index 7590a9bff..000000000 --- a/scripts/prisma-sed.sh +++ /dev/null @@ -1,4 +0,0 @@ -# TODO: make more dyanimc of a script -set -ex; \ - sed -i 's|\/.*\/core\/prisma\/schema.prisma|\/app\/core\/prisma\/schema.prisma|g' core/src/prisma.rs; \ - sed -i 's|\/.*\/core\/prisma\/migrations|\/app\/core\/prisma\/migrations|g' core/src/prisma.rs \ No newline at end of file diff --git a/scripts/release/Dockerfile b/scripts/release/Dockerfile index b748fc02b..9635a3758 100644 --- a/scripts/release/Dockerfile +++ b/scripts/release/Dockerfile @@ -29,22 +29,46 @@ RUN mv ./apps/web/dist build FROM messense/rust-musl-cross:aarch64-musl AS arm64-backend +ARG GIT_REV +ENV GIT_REV=${GIT_REV} + WORKDIR /app +ENV CARGO_NET_GIT_FETCH_WITH_CLI=true +RUN rustup target add aarch64-unknown-linux-musl + +# TODO: make one-liner COPY .cargo .cargo -COPY . . +COPY scripts scripts +COPY Cargo.toml Cargo.lock ./ -ENV CARGO_NET_GIT_FETCH_WITH_CLI=true +# Run the build utils script to create the dummy rust files for core and server +RUN set -ex; \ + ./scripts/release/build-utils.sh -w; \ + ./scripts/release/build-utils.sh -d './core'; \ + ./scripts/release/build-utils.sh -d './apps/server' -RUN rustup target add aarch64-unknown-linux-musl +# Copy the core and server Cargo.{toml,lock} files +COPY ./apps/server/Cargo.toml ./apps/server/ +COPY ./core/Cargo.toml ./core/ +# This is where the ~magic~ happens. We build the server (which pulls the core as a dependency) with +# the dummy files we created above. This ~should~ allow caching until the dependencies themselves change. RUN set -ex; \ - sed -i 's|\/.*\/core\/prisma\/schema.prisma|\/app\/core\/prisma\/schema.prisma|g' core/src/prisma.rs; \ - sed -i 's|\/.*\/core\/prisma\/migrations|\/app\/core\/prisma\/migrations|g' core/src/prisma.rs + cargo build --release --target aarch64-unknown-linux-musl; \ + rm -rf apps/server/src; \ + rm -rf core/src -RUN cargo build --package stump_server --bin stump_server --release --target aarch64-unknown-linux-musl && \ +# Now we can copy the real source files and build the server +COPY . . +COPY ./core/src/prisma.rs ./core/src/prisma.rs + +RUN set -ex; \ + ./scripts/release/build-utils.sh -p; \ + cargo build --package stump_server --bin stump_server --release --target aarch64-unknown-linux-musl; \ cp target/aarch64-unknown-linux-musl/release/stump_server ./stump +# FIXME: armv7 is currently broken. I have a gut it needs a similar workaround as the arm64 ###################### ### armv7 / arm/v7 ### ###################### @@ -53,16 +77,44 @@ RUN cargo build --package stump_server --bin stump_server --release --target aar # out how to have the name be v7 inclusive so FROM messense/rust-musl-cross:armv7-musleabihf@sha256:3e133558686fd5059ce25749cece40a81d87dad2c7a68727c36a1bcacba6752c AS arm-backend +ARG GIT_REV +ENV GIT_REV=${GIT_REV} + WORKDIR /app +ENV CARGO_NET_GIT_FETCH_WITH_CLI=true + +RUN rustup update && rustup target add armv7-unknown-linux-musleabihf + +# TODO: make one-liner COPY .cargo .cargo -COPY . . +COPY scripts scripts +COPY Cargo.toml Cargo.lock ./ -ENV CARGO_NET_GIT_FETCH_WITH_CLI=true +# Run the build utils script to create the dummy rust files for core and server +RUN set -ex; \ + ./scripts/release/build-utils.sh -w; \ + ./scripts/release/build-utils.sh -d './core'; \ + ./scripts/release/build-utils.sh -d './apps/server' + +# Copy the core and server Cargo.{toml,lock} files +COPY ./apps/server/Cargo.toml ./apps/server/ +COPY ./core/Cargo.toml ./core/ -RUN rustup target add armv7-unknown-linux-musleabihf +# This is where the ~magic~ happens. We build the server (which pulls the core as a dependency) with +# the dummy files we created above. This ~should~ allow caching until the dependencies themselves change. +RUN set -ex; \ + cargo build --release --target armv7-unknown-linux-musleabihf; \ + rm -rf apps/server/src; \ + rm -rf core/src + +# Now we can copy the real source files and build the server +COPY . . +COPY ./core/src/prisma.rs ./core/src/prisma.rs -RUN cargo build --package stump_server --bin stump_server --release --target armv7-unknown-linux-musleabihf && \ +RUN set -ex; \ + ./scripts/release/build-utils.sh -p; \ + cargo build --package stump_server --bin stump_server --release --target armv7-unknown-linux-musleabihf; \ cp target/armv7-unknown-linux-musleabihf/release/stump_server ./stump ###################### @@ -71,23 +123,45 @@ RUN cargo build --package stump_server --bin stump_server --release --target arm FROM messense/rust-musl-cross:x86_64-musl AS amd64-backend +ARG GIT_REV +ENV GIT_REV=${GIT_REV} + + WORKDIR /app ENV CARGO_NET_GIT_FETCH_WITH_CLI=true +RUN rustup update && rustup target add x86_64-unknown-linux-musl + +# TODO: make one-liner COPY .cargo .cargo -COPY . . +COPY scripts scripts +COPY Cargo.toml Cargo.lock ./ -RUN rustup update && rustup target add x86_64-unknown-linux-musl +# Run the build utils script to create the dummy rust files for core and server +RUN set -ex; \ + ./scripts/release/build-utils.sh -w; \ + ./scripts/release/build-utils.sh -d './core'; \ + ./scripts/release/build-utils.sh -d './apps/server' -# prisma uses some `include_str!` macros that are mapped to locations on the host machine. so -# when we build in docker, we need to correct these paths according to the docker workdir. -# it's a bit of a hack, but it works lol +# Copy the core and server Cargo.{toml,lock} files +COPY ./apps/server/Cargo.toml ./apps/server/ +COPY ./core/Cargo.toml ./core/ + +# This is where the ~magic~ happens. We build the server (which pulls the core as a dependency) with +# the dummy files we created above. This ~should~ allow caching until the dependencies themselves change. RUN set -ex; \ - sed -i 's|\/.*\/core\/prisma\/schema.prisma|\/app\/core\/prisma\/schema.prisma|g' core/src/prisma.rs; \ - sed -i 's|\/.*\/core\/prisma\/migrations|\/app\/core\/prisma\/migrations|g' core/src/prisma.rs + cargo build --release --target x86_64-unknown-linux-musl; \ + rm -rf apps/server/src; \ + rm -rf core/src + +# Now we can copy the real source files and build the server +COPY . . +COPY ./core/src/prisma.rs ./core/src/prisma.rs -RUN cargo build --package stump_server --bin stump_server --release --target x86_64-unknown-linux-musl && \ +RUN set -ex; \ + ./scripts/release/build-utils.sh -p; \ + cargo build --package stump_server --bin stump_server --release --target x86_64-unknown-linux-musl; \ cp target/x86_64-unknown-linux-musl/release/stump_server ./stump ###################### diff --git a/scripts/release/build-docker.sh b/scripts/release/build-docker.sh index 2282f7f8c..4ab3651f6 100755 --- a/scripts/release/build-docker.sh +++ b/scripts/release/build-docker.sh @@ -1,7 +1,8 @@ #!/bin/bash FORMAT=${1:-auto} +PLATFORMS=${2:-linux/amd64} +TAG=${3:-nightly} GIT_REV=$(git rev-parse --short HEAD) -set GIT_REV=$GIT_REV -# docker buildx build -f ./scripts/release/Dockerfile --push --platform=linux/arm64/v8,linux/amd64 -t aaronleopold/stump-preview:latest . -docker buildx build -f ./scripts/release/Dockerfile --push --progress=$FORMAT --platform=linux/amd64 -t aaronleopold/stump-preview:latest . \ No newline at end of file + +docker buildx build -f ./scripts/release/Dockerfile --load --progress=$FORMAT --platform=$PLATFORMS -t aaronleopold/stump:$TAG --build-arg GIT_REV=$GIT_REV . \ No newline at end of file diff --git a/scripts/release/build-utils.sh b/scripts/release/build-utils.sh new file mode 100755 index 000000000..14a931b26 --- /dev/null +++ b/scripts/release/build-utils.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +SCRIPTS_DIR="${BASH_SOURCE%/*}/.." +source "${SCRIPTS_DIR}/lib" + +while getopts "pwd:" opt; do + case $opt in + p) + prisma_sed_correction + ;; + w) + workspaces_sed_correction + ;; + d) + path="$OPTARG" + echo "The path provided is $OPTARG" + create_dummy_rust_file $path + ;; + ?) + echo "Invalid option -$OPTARG" >&2 + exit 1 + ;; + esac +done +shift "$(($OPTIND -1))" \ No newline at end of file diff --git a/scripts/release/compile-server.sh b/scripts/release/compile-server.sh new file mode 100755 index 000000000..628346972 --- /dev/null +++ b/scripts/release/compile-server.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +SCRIPTS_DIR="${BASH_SOURCE%/*}/.." +source "${SCRIPTS_DIR}/lib" + +echo "Ensuring targets for apple(x86_64,darwin),linux(x86_64,arm64), and windows(x86_64) are installed..." + +set -ex; \ + rustup target add x86_64-apple-darwin; \ + rustup target add aarch64-apple-darwin; \ + rustup target add x86_64-unknown-linux-gnu; \ + rustup target add aarch64-unknown-linux-gnu; \ + rustup target add x86_64-pc-windows-gnu; \ + set +x + +# https://www.shogan.co.uk/development/rust-cross-compile-linux-to-macos-using-github-actions/ +# https://stackoverflow.com/questions/66849112/how-do-i-cross-compile-a-rust-application-from-macos-x86-to-macos-silicon +# https://gist.github.com/shqld/256e2c4f4b97957fb0ec250cdc6dc463 +# lol, at this point, I think it might just be easier to use GH hosted runners +# for the executable builds... Which would mean instead of this scripting doing it all, +# it would just run a subset of these operations on a per-os basis. E.g. the linux +# build would just run the linux-specific commands, and the macos build would just +# run the macos-specific commands. This would also mean that the build process +# would be a lot more straightforward, and would be a lot easier to maintain? Maybe to start, +# I trim it even further. Don't support both arm+x86, just do vanilla builds for each + +echo "Targets installed." + +CALL_TO_ACTION_LOL="Please consider helping to expand support for your system: https://github.com/aaronleopold/stump/issues" + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + UNSUPPORTED_DISTRO="Your distro '$(lsb_release -s -d)' is not supported by this script. $CALL_TO_ACTION_LOL" + + if which apt-get &> /dev/null; then + # TODO: add support for other distros + log_error "$UNSUPPORTED_DISTRO" + elif which pacman &> /dev/null; then + set -ex; \ + sudo pacman -S --needed mingw-w64-gcc + elif which dnf &> /dev/null; then + # TODO: add support for other distros + log_error "$UNSUPPORTED_DISTRO" + else + log_error "$UNSUPPORTED_DISTRO" + fi +elif [[ "$OSTYPE" == "darwin"* ]]; then + set -ex; \ + set HOMEBREW_NO_AUTO_UPDATE=1; \ + brew tap messense/macos-cross-toolchains; \ + brew install filosottile/musl-cross/musl-cross mingw-w64 x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu; \ + set +x + + if which musl-gcc &> /dev/null; then + echo "musl-gcc installed successfully." + else + # https://github.com/FiloSottile/homebrew-musl-cross + echo "musl-gcc is not detected, attempting symlink workaround..." + DIR="/usr/local/opt/musl-cross/bin/x86_64-linux-musl-gcc" + TARG="/usr/local/bin/musl-gcc" + if ln -s "$DIR" "$TARG"; then + echo "Symlink created successfully." + else + log_error "Symlink creation failed." + fi + fi +else + log_error "Your OS '$OSTYPE' is not supported by this script. $CALL_TO_ACTION_LOL" +fi + +export CC_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-gcc +export CXX_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-g++ +export AR_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-ar +export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc + +cargo build --package stump_server --release \ + --target x86_64-apple-darwin \ + --target aarch64-apple-darwin \ + --target x86_64-unknown-linux-gnu \ + --target x86_64-unknown-linux-musl \ + --target x86_64-pc-windows-gnu diff --git a/scripts/system-setup.sh b/scripts/system-setup.sh index ff1c4820d..81af7195e 100755 --- a/scripts/system-setup.sh +++ b/scripts/system-setup.sh @@ -1,22 +1,18 @@ #!/bin/bash +SCRIPTS_DIR="${BASH_SOURCE%/*}" +source "${SCRIPTS_DIR}/lib" + _DEV_SETUP=${DEV_SETUP:=1} _CHECK_CARGO=${CHECK_CARGO:=1} _CHECK_NODE=${CHECK_NODE:=1} _FORCE_INSTALL_PNPM=${INSTALL_PNPM:=0} dev_setup() { - echo "Installing 'cargo-watch'..." - echo - - cargo install cargo-watch - - echo "Running 'pnpm run setup'..." - echo - - pnpm run setup - - echo + set -ex; \ + cargo install cargo-watch; \ + pnpm run setup; \ + set +x } if [ "$name" == "nix-shell" ]; then @@ -27,8 +23,7 @@ fi if [ ${_CHECK_CARGO} == 1 ]; then which cargo &> /dev/null if [ $? -ne 0 ]; then - echo "Rust could not be found on your system. Visit https://www.rust-lang.org/tools/install" - exit 1 + log_error "Rust could not be found on your system. Visit https://www.rust-lang.org/tools/install" else echo "Rust requirement met!" fi @@ -37,8 +32,7 @@ fi if [ ${_CHECK_NODE} == 1 ]; then which node &> /dev/null if [ $? -eq 1 ]; then - echo "Node could not be found on your system. Visit https://nodejs.org/en/download/" - exit 1 + log_error "Node could not be found on your system. Visit https://nodejs.org/en/download/" else echo "Node requirement met!" fi @@ -63,9 +57,8 @@ if [ ${_CHECK_NODE} == 1 ]; then echo "pnpm installed successfully." can_continue=true else - echo "pnpm could not be installed. Please ensure you have node and npm installed." can_continue=false - exit 1 + log_error "pnpm could not be installed. Please ensure you have node and npm installed." fi ;; n) @@ -88,20 +81,25 @@ if [ ${_CHECK_NODE} == 1 ]; then fi fi +CALL_TO_ACTION_LOL="Please consider helping to expand support for your system: https://github.com/aaronleopold/stump/issues" + +# TODO: group these? so lines aren't so long... +# https://tauri.app/v1/guides/getting-started/prerequisites/#1-system-dependencies if [[ "$OSTYPE" == "linux-gnu"* ]]; then + UNSUPPORTED_DISTRO="Your distro '$(lsb_release -s -d)' is not supported by this script. $CALL_TO_ACTION_LOL" + if which apt-get &> /dev/null; then sudo apt-get -y update - sudo apt-get -y install pkg-config libssl-dev libdbus-1-dev libsoup2.4-dev libwebkit2gtk-4.0-dev curl wget libgtk-3-dev libappindicator3-dev librsvg2-dev build-essential + sudo apt-get -y install pkg-config libssl-dev libdbus-1-dev libsoup2.4-dev libwebkit2gtk-4.0-dev curl wget libgtk-3-dev libappindicator3-dev librsvg2-dev build-essential libayatana-appindicator3-dev elif which pacman &> /dev/null; then sudo pacman -Syu - sudo pacman -S --needed base-devel openssl + sudo pacman -S --needed webkit2gtk base-devel curl wget openssl appmenu-gtk-module gtk3 libappindicator-gtk3 librsvg libvips elif which dnf &> /dev/null; then sudo dnf check-update - sudo dnf install "openssl-devel" + sudo dnf install openssl-devel webkit2gtk4.0-devel curl wget libappindicator-gtk3 librsvg2-devel sudo dnf group install "C Development Tools and Libraries" else - echo "Your distro '$(lsb_release -s -d)' is not supported by this script. Please consider adding support for it: https://github.com/aaronleopold/stump/issues" - exit 1 + log_error $UNSUPPORTED_DISTRO fi if [ {$_DEV_SETUP} == 1 ]; then @@ -116,6 +114,5 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then echo "Setup completed! Run 'pnpm dev:web' or 'pnpm start:web' to get started." else - echo "Your OS '$OSTYPE' is not supported by the pre-setup script. Please consider adding support for it: https://github.com/aaronleopold/stump/issues" - exit 1 + log_error "Your OS '$OSTYPE' is not supported by the pre-setup script. $CALL_TO_ACTION_LOL" fi