diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..9ed97a5b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,7 @@ +# apt install gcc-arm-linux-gnueabihf +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" + +# apt install gcc-aarch64-linux-gnu +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" diff --git a/.github/actions/toolchain/action.yml b/.github/actions/toolchain/action.yml index 7a5feaa0..94811c89 100644 --- a/.github/actions/toolchain/action.yml +++ b/.github/actions/toolchain/action.yml @@ -2,58 +2,36 @@ name: toolchain description: "Install toolchain" -inputs: - bin-cache: - description: 'Where to keep cached bins' - required: false - default: /home/runner/.bin-cache - runs: using: "composite" steps: - - name: Setup mise - uses: jdx/mise-action@v2 - with: - # version: TODO: - install: true - cache: true - experimental: true - - name: Setup rust caching uses: Swatinem/rust-cache@v2 with: - shared-key: toolchain - cache-directories: ${{ inputs.bin-cache }} + shared-key: toolchains - name: "Set environment variables used by toolchain" + shell: bash run: | echo CARGO_TERM_COLOR=always >> $GITHUB_ENV echo CARGO_INCREMENTAL=0 >> $GITHUB_ENV echo RUST_BACKTRACE=1 >> $GITHUB_ENV - shell: bash - - - name: "Install rust toolchain" - shell: bash - run: | - # Make sure bin-cache dir exists with something in it - mkdir -p ${{ inputs.bin-cache }} - touch ${{ inputs.bin-cache }}/empty - cp ${{ inputs.bin-cache }}/* /home/runner/.cargo/bin - - # Install everything needed - mise run setup:toolchain - - # Install dependencies - cargo install sqlx-cli@0.8.0 # TODO: - cargo install cargo-tarpaulin@0.31.0 # TODO: + - name: Install rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: | + x86_64-unknown-linux-gnu, + armv7-unknown-linux-gnueabihf, + aarch64-unknown-linux-gnu - # Cache these binaries - for f in sqlx cargo-tarpaulin; do - cp -f "/home/runner/.cargo/bin/$f" "${{ inputs.bin-cache }}" - done + - name: Install cross compilation dependencies + uses: eth-pkg/apt-deb-cache@v0.2.6 + with: + packages: gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu - - name: "Setup DB" + - name: Install cargo dependencies shell: bash run: | - mise run setup:db + cargo install sqlx-cli@0.8.0 # TODO: + cargo install cargo-tarpaulin@0.31.0 # TODO: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7460dc6..1662b7c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI on: workflow_call: - pull_request: + # pull_request: FIX: push: branches: - main @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - target: ["lint:fmt", "lint:clippy", "test"] + target: ["lint-fmt", "lint-clippy", "test"] steps: - name: Checkout @@ -29,12 +29,10 @@ jobs: uses: ./.github/actions/toolchain - name: Run ${{ matrix.target }} - run: mise run ${{ matrix.target }} + run: make ${{ matrix.target }} - name: Upload test coverage uses: codecov/codecov-action@v4 if: matrix.target == 'test' - continue-on-error: true with: token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1aa168d7..f63a165e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,13 +2,12 @@ name: Release on: - release: - types: [published] + pull_request: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} - VERSION: ${{ github.ref_name }} + VERSION: v0.7.0 DATABASE_URL: sqlite:data/spis.db jobs: @@ -35,22 +34,9 @@ jobs: - name: Install rust toolchain uses: ./.github/actions/toolchain - - name: Docker pulls images. - uses: ScribeMD/docker-cache@0.5.0 - with: - key: docker-${{ runner.os }} - - - name: Build binary - uses: houseabsolute/actions-rust-cross@v0 - with: - target: ${{ matrix.target }} - args: "--locked --release" - cross-version: v0.2.5 - - - name: Move to release dir + - name: Build spis release run: | - mkdir release - mv target/${{ matrix.target }}/release/spis release/spis-${{ matrix.target }} + make release/spis-${{ matrix.target }} - name: Store artifact uses: actions/upload-artifact@v4 @@ -95,7 +81,7 @@ jobs: with: context: . file: docker/Dockerfile - push: true + push: false tags: | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} @@ -103,9 +89,9 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - - name: Upload artifacts to release - uses: AButler/upload-release-assets@v3.0 - with: - files: 'release/*' - repo-token: ${{ secrets.GITHUB_TOKEN }} - release-tag: ${{ env.VERSION }} + # - name: Upload artifacts to release + # uses: AButler/upload-release-assets@v3.0 + # with: + # files: 'release/*' + # repo-token: ${{ secrets.GITHUB_TOKEN }} + # release-tag: ${{ env.VERSION }} diff --git a/.mise.toml b/.mise.toml index 1856c449..b2a3c168 100644 --- a/.mise.toml +++ b/.mise.toml @@ -1,42 +1,3 @@ -##### SETUP / CLEANUP ##### - -[tasks."setup:folders"] -run = ["mkdir -p data/media", "mkdir -p data/thumbnails"] -outputs = ["data/media", "data/thumbnails"] - -[tasks."setup:db"] -run = ["sqlx database create", "sqlx migrate run --source migrations"] -sources = ["migrations/*.sql"] -outputs = ["data/spis.db"] -depends = ["setup:folders"] - -[tasks."setup:toolchain"] -run = "rustup show" - -[tasks.setup] -depends = ["setup:*"] - -[tasks."clean:cargo"] -run = ["cargo clean", "rm -rf target"] - -[tasks."clean:state"] -run = ["rm -f data/spis.db"] - -[tasks."clean:thumbnails"] -run = ["rm -rf data/thumbnails"] - -[tasks.clean] -depends = ["clean:*"] - -##### DEV ##### - - -[tasks."dev:clippy"] -run = """ -watchexec --stop-timeout=0 -r -e rs,toml,html,css -- cargo clippy -F dev -- --no-deps -D warnings -""" -depends = ["setup:db"] - [tasks."dev:nginx"] run = """ cat << EOF > /tmp/nginx.conf @@ -65,63 +26,7 @@ nginx -c /tmp/nginx.conf > /dev/null """ [tasks."dev:spis"] -run = "watchexec --stop-timeout=0 -r -e rs,toml,html,css -- cargo run --color always -F dev" -depends = ["setup:db", "setup:folders"] - -[tasks."dev:process"] -run = "cargo run -- -t" -depends = ["setup:db", "setup:folders"] +run = "make dev-spis" [tasks."dev"] depends = ["dev:nginx", "dev:spis"] - -##### CI ##### - -[tasks."lint:clippy"] -run = """ -cargo clippy -F dev -- --no-deps -D warnings -""" -depends = ["setup:db"] - -[tasks."lint:fmt"] -run = "cargo fmt -- --check" - -[tasks."lint:audit"] -run = "cargo audit" - -[tasks.lint] -depends = ["lint:*"] - -[tasks.test] -run = "cargo tarpaulin --ignore-tests --workspace --timeout 120 --skip-clean --out Xml" -depends = ["setup:db"] - -[tasks.ci] -depends = ["lint", "test"] - -##### RELEASE ##### - -[tasks.release] -depends = ["setup:db"] -sources = ["src/**", "templates/**", "assets/**", "migrations/**"] -outputs = ["release/spis-x86_64-unknown-linux-gnu"] -run = """ -mkdir -p release -cargo build --locked --release -cp target/release/spis release/spis-x86_64-unknown-linux-gnu -""" - -[tasks."docker:build"] -run = "docker build -t spis-local -f docker/Dockerfile ." -depends = ["release"] - -[tasks."docker:run"] -raw = true -depends = ["docker:build"] -run = """ -docker run -it --rm \ - -p 8080:8080 \ - -v ${PWD}/data/media:/var/lib/spis/media \ - -e SPIS_PROCESSING_RUN_ON_START=true \ - spis-local -""" diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..bab96b4a --- /dev/null +++ b/Makefile @@ -0,0 +1,78 @@ +X86_64:=x86_64-unknown-linux-gnu +ARMV7:=armv7-unknown-linux-gnueabihf +AARCH64:=aarch64-unknown-linux-gnu + +DATABASE:=$(shell echo ${DATABASE_URL} | awk -F':' '{print $$2}') +MEDIA_DIR:=data/media +THUMBNAIL_DIR:=data/thumbnails + +${DATABASE}: + mkdir -p $(shell dirname ${DATABASE}) + sqlx database create + sqlx migrate run --source migrations + +${MEDIA_DIR}: + mkdir -p ${MEDIA_DIR} + +${THUMBNAIL_DIR}: + mkdir -p ${THUMBNAIL_DIR} + +_release: ${DATABASE} + cargo build --locked --release --target ${TARGET} + mkdir -p release + cp target/${TARGET}/release/spis release/spis-${TARGET} + +release/spis-${X86_64}: + TARGET=${X86_64} $(MAKE) --no-print-directory _release + +release/spis-${ARMV7}: + TARGET=${ARMV7} $(MAKE) --no-print-directory _release + +release/spis-${AARCH64}: + TARGET=${AARCH64} $(MAKE) --no-print-directory _release + +.PHONY: toolchain +toolchain: + rustup show + +.PHONY: dev-clippy +dev-clippy: ${DATABASE} + watchexec --stop-timeout=0 -r -e rs,toml,html,css -- \ + cargo clippy -F dev -- --no-deps -D warnings + +.PHONY: dev-spis +dev-spis: ${DATABASE} ${MEDIA_DIR} ${THUMBNAIL_DIR} + watchexec --stop-timeout=0 -r -e rs,toml,html,css -- \ + cargo run --color always -F dev + +.PHONY: lint-fmt +lint-fmt: + cargo fmt -- --check + +.PHONY: lint-clippy +lint-clippy: ${DATABASE} + cargo clippy -F dev -- --no-deps -D warnings + +.PHONY: lint +lint: lint-fmt lint-clippy + +.PHONY: test +test: ${DATABASE} ${MEDIA_DIR} ${THUMBNAIL_DIR} + cargo tarpaulin --ignore-tests --workspace --timeout 120 --skip-clean --out Xml + +.PHONY: docker-build +docker-build: release/spis-${X86_64} + docker build -t spis-local -f docker/Dockerfile . + +.PHONY: docker-run +docker-run: docker-build + docker run -it --rm \ + -p 8080:8080 \ + -v ${PWD}/data/media:/var/lib/spis/media \ + -e SPIS_PROCESSING_RUN_ON_START=true \ + spis-local + +.PHONY: clean +clean: + rm -rf target release data/spis.db data/thumbnails + cargo clean diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4c688a8b..cb3c1142 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,9 @@ [toolchain] channel = "1.80.0" components = ["rustfmt", "rust-src", "rust-std", "clippy"] -targets = ["x86_64-unknown-linux-gnu"] +targets = [ + "x86_64-unknown-linux-gnu", + "armv7-unknown-linux-gnueabihf", + "aarch64-unknown-linux-gnu", +] profile = "minimal"