diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0351d88 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: CI +on: + pull_request: + push: + branches: "main" + +jobs: + build-binary: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Set up Bun + uses: oven-sh/setup-bun@v1 + + - name: Install deps + run: cd web && bun install + + - name: Build + run: ./build.sh cargo build --verbose + + build-image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64 + push: false + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 6d8f8a5..1ae7dd9 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,46 +1,48 @@ name: Nightly Release on: - push: - branches: main + workflow_dispatch: jobs: - build-binary: - strategy: - matrix: - platform: - - release_for: linux-aarch64 - os: ubuntu-latest - target: aarch64-unknown-linux-musl - bin: cup - name: cup-linux-aarch64 - command: build - - - release_for: linux-x86_64 - os: ubuntu-latest - target: x86_64-unknown-linux-musl - bin: cup - name: cup-linux-x86_64 - command: build - - runs-on: ${{ matrix.platform.os }} + build-binaries: + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup rust + - name: Set up Rust uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Install cross run: cargo install cross --git https://github.com/cross-rs/cross - - name: Build binary - run: cross ${{ matrix.platform.command }} --target ${{ matrix.platform.target }} + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Set up Bun + uses: oven-sh/setup-bun@v1 - - name: Upload CLI + - name: Install deps + run: cd web && bun install + + - name: Build amd64 binary + run: | + ./build.sh cross build --target x86_x64-unknown-linux-musl --release + mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64 + + - name: Build arm64 binary + run: | + ./build.sh cross build --target aarch64-unknown-linux-musl --release + mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64 + + - name: Upload binaries uses: actions/upload-artifact@v4 with: - name: ${{ matrix.platform.name }} - path: target/${{ matrix.platform.target }}/debug/${{ matrix.platform.bin }} + name: binaries + path: | + cup-linux-amd64 + cup-linux-arm64 build-image: runs-on: ubuntu-latest @@ -69,4 +71,21 @@ jobs: push: true tags: ghcr.io/sergi0g/cup:nightly cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + cache-to: type=gha,mode=max + + nightly-release: + runs-on: ubuntu-latest + needs: build-binaries + steps: + - name: Download binaries + uses: actions/download-artifact@v4 + with: + name: binaries + path: binaries + + - uses: pyTooling/Actions/releaser@r0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag: nightly + rm: true + files: binaries/* diff --git a/.github/workflows/build.yml b/.github/workflows/release.yml similarity index 61% rename from .github/workflows/build.yml rename to .github/workflows/release.yml index 2dcd01d..5ca6fae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,6 @@ name: Release on: - push: - tags: ["v*.*.*"] + workflow_dispatch: jobs: get-tag: @@ -12,34 +11,50 @@ jobs: - name: Get current tag id: tag run: | - TAG=$(echo "$GITHUB_REF" | sed 's/^refs\/tags\///') + TAG=v$(head -n 4 Cargo.toml | grep version | awk '{print $3}' | tr -d '"') echo "Current tag: $TAG" echo "tag=$TAG" >> $GITHUB_OUTPUT - build-binary: - strategy: - matrix: - arch: - - aarch64 - - x86_64 + + build-binaries: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup rust + - name: Set up Rust uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Install cross run: cargo install cross --git https://github.com/cross-rs/cross - - name: Build binary - run: cross build --target ${{ matrix.arch }}-unknown-linux-musl --release + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 - - name: Upload binary + - name: Set up Bun + uses: oven-sh/setup-bun@v1 + + - name: Install deps + run: cd web && bun install + + - name: Build amd64 binary + run: | + ./build.sh cross build --target x86_x64-unknown-linux-musl --release + mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64 + + - name: Build arm64 binary + run: | + ./build.sh cross build --target aarch64-unknown-linux-musl --release + mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64 + + - name: Upload binaries uses: actions/upload-artifact@v4 with: - name: cup-linux-${{ matrix.arch }} - path: target/${{ matrix.arch }}-unknown-linux-musl/release/cup + name: binaries + path: | + cup-linux-amd64 + cup-linux-arm64 build-image: needs: get-tag @@ -73,24 +88,13 @@ jobs: release: runs-on: ubuntu-latest - needs: [get-tag, build-image, build-binary] + needs: [get-tag, build-image, build-binaries] steps: - - name: Download arm64 binary + - name: Download binaries uses: actions/download-artifact@v4 with: - name: cup-linux-aarch64 - path: cup-linux-aarch64 - - - name: Download x86 binary - uses: actions/download-artifact@v4 - with: - name: cup-linux-x86_64 - path: cup-linux-x86_64 - - # - name: Extract and rename binaries - # run: | - # unzip /home/runner/work/cup/cup/cup-linux-aarch64 && mv /home/runner/work/cup/cup/cup cup-linux-aarch64 - # unzip /home/runner/work/cup/cup/cup-linux-x86_64 && mv /home/runner/work/cup/cup/cup cup-linux-x86_64 + name: binaries + path: binaries - name: Create release uses: softprops/action-gh-release@v2 @@ -100,6 +104,4 @@ jobs: prerelease: true tag_name: ${{ needs.get-tag.outputs.tag }} name: ${{ needs.get-tag.outputs.tag }} - files: | - cup-linux-aarch64 - cup-linux-x86_64 + files: binaries/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c47cd04..fb4126e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,42 @@ -FROM rust:alpine AS build -WORKDIR / +### Build UI ### +FROM node:20 AS web +# Install bun +RUN curl -fsSL https://bun.sh/install | bash + +# Copy web folder +COPY ./web /web +WORKDIR /web + +# Install requirements +RUN ~/.bun/bin/bun install + +# Build frontend +RUN ~/.bun/bin/bun run build + +### Build Cup ### +FROM rust:1.80.1-alpine AS build + +# Requirements RUN apk add musl-dev -RUN USER=root cargo new --bin cup +# Copy files WORKDIR /cup -COPY Cargo.toml Cargo.lock . -RUN cargo build --release -RUN rm -rf src/ +COPY Cargo.toml . +COPY Cargo.lock . +COPY ./src ./src -COPY src src -# This is a very bad workaround, but cargo only triggers a rebuild this way for some reason -RUN printf "\n" >> src/main.rs +# Copy UI from web builder +COPY --from=web /web/dist src/static + +# Build RUN cargo build --release +### Main ### FROM scratch + +# Copy binary COPY --from=build /cup/target/release/cup /cup + ENTRYPOINT ["/cup"] \ No newline at end of file diff --git a/build.sh b/build.sh index f4688a3..7a8710b 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,16 @@ #!/bin/sh -rm -rf src/static +# This is kind of like a shim that makes sure the frontend is rebuilt when running a build. For example you can run `./build.sh cargo build --release` + +# Frontend cd web/ + +# Build bun run build + +# Copy UI to src folder cp -r dist/ ../src/static -cargo build $@ \ No newline at end of file + +# Run command from argv + +$@ \ No newline at end of file diff --git a/src/static/apple-touch-icon.png b/src/static/apple-touch-icon.png deleted file mode 100644 index ac6ec92..0000000 Binary files a/src/static/apple-touch-icon.png and /dev/null differ diff --git a/src/static/favicon.ico b/src/static/favicon.ico deleted file mode 100644 index 3ee81b1..0000000 Binary files a/src/static/favicon.ico and /dev/null differ diff --git a/src/static/favicon.svg b/src/static/favicon.svg deleted file mode 100644 index 4fe8396..0000000 --- a/src/static/favicon.svg +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - -