From acc057e4cb6f775b57466ea0d0c1e8d6c84c691c Mon Sep 17 00:00:00 2001 From: rm-dr <96270320+rm-dr@users.noreply.github.com> Date: Mon, 3 Nov 2025 23:16:05 -0800 Subject: [PATCH] CI --- .editorconfig | 4 + .gitea/workflows/ci.yml | 188 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 37 ++++++++ docker-compose.yml | 9 ++ 4 files changed, 238 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.editorconfig b/.editorconfig index 1b83267..52a8381 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,7 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..2c97613 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,188 @@ +name: CI + +on: + pull_request: + workflow_dispatch: + push: + branches: + - main + schedule: + - cron: "0 0 */5 * *" + +jobs: + typos: + name: "Check typos" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check typos + uses: crate-ci/typos@master + with: + config: ./typos.toml + + lychee: + name: "Check links" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Takes too long + #- name: Restore lychee cache + # uses: actions/cache@v3 + # with: + # path: .lycheecache + # key: lychee-cache + # restore-keys: lychee-cache + #key: cache-lychee-${{ github.sha }} + #restore-keys: cache-lychee- + - name: Check links + id: lychee + uses: lycheeverse/lychee-action@v1 + with: + args: --config ./lychee.toml . + fail: true + + clippy: + name: "Clippy" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: "Install Rust" + run: | + sudo apt update + DEBIAN_FRONTEND=noninteractive \ + sudo apt install --yes rustup + rustup default 1.91.0 + + - name: Run clippy + run: cargo clippy --all-targets --all-features + + #check-version: + # name: Check version + # runs-on: ubuntu-latest + # # Skip this job on push to main + # # if: github.event_name != 'push' || github.ref != 'refs/heads/main' + # steps: + # - uses: actions/checkout@v4 + # with: + # fetch-depth: 0 + # + # - name: check version + # run: | + # # Get base branch (usually main) + # BASE_REF="${{ github.base_ref }}" + # if [ -z "$BASE_REF" ]; then + # BASE_REF="main" + # fi + # + # # Get current version + # CURRENT_VERSION=$(grep -m 1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/') + # echo "Current version: $CURRENT_VERSION" + # + # # Get version from base branch + # git fetch origin $BASE_REF + # BASE_VERSION=$(git show origin/$BASE_REF:Cargo.toml | grep -m 1 '^version = ' | sed 's/version = "\(.*\)"/\1/') + # echo "Base version: $BASE_VERSION" + # + # # Check if version changed + # if [ "$CURRENT_VERSION" = "$BASE_VERSION" ]; then + # echo "::error::Version in Cargo.toml has not been changed." + # exit 1 + # else + # echo "Version has been updated from $BASE_VERSION to $CURRENT_VERSION" + # fi + + buildandtest: + name: "Build and test" + runs-on: ubuntu-latest + needs: + # - check-version + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + + - name: "Install Rust" + run: | + sudo apt update + DEBIAN_FRONTEND=noninteractive \ + sudo apt install --yes rustup + rustup default 1.91.0 + + - name: Build + run: cargo build --release --package webpage + + - name: Test + run: cargo test --release --workspace + + - uses: actions/upload-artifact@v3 + with: + name: webpage + path: "target/release/webpage" + retention-days: 10 + + + docker: + name: "Build container" + runs-on: ubuntu-latest + # Only run on push to main or workflow_dispatch + if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' + needs: + - typos + - clippy + - buildandtest + # - check-version + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - name: Log in to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ github.server_url }} + username: mark + password: ${{ secrets.API_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: git.betalupi.com/mark/betalupi-webpage + tags: | + type=ref,event=branch + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # Tags looks like ghcr.io/user/app:latest + +# - name: Setup SSH +# if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' }} +# run: | +# mkdir -p ~/.ssh +# echo "${{ secrets.DEPLOY_SSH_PRIV_KEY }}" > ~/.ssh/id_ed25519 +# chmod 600 ~/.ssh/id_ed25519 +# eval "$(ssh-agent -s)" +# ssh-add ~/.ssh/id_ed25519 +# ssh-keyscan -p 5342 waypoint.betalupi.com >> ~/.ssh/known_hosts + +# - name: Deploy +# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} +# run: | +# cat "site.tar.gz" | \ +# ssh mark@waypoint.betalupi.com -p 5342 \ +# " +# cat > /home/mark/site.tar.gz; \ +# rm -dfr /var/www/site/public; \ +# tar -xf site.tar.gz --directory=/var/www/site; +# " diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2a2f60f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM rust:1.91-bookworm AS base + +# +# MARK: Build +# +FROM base AS build + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates wget unzip \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app/rust +COPY . . +RUN cargo build --release --workspace +RUN cargo test --release --workspace + +# +# MARK: Release +# +FROM debian:bookworm@sha256:00cd074b40c4d99ff0c24540bdde0533ca3791edcdac0de36d6b9fb3260d89e2 AS deploy + +WORKDIR /app + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=build \ + /app/rust/target/release/webpage \ + /app/bin/ + +ENV PATH="/app/bin:$PATH" +ENV RUST_BACKTRACE=full + +ENTRYPOINT ["webpage", "--help"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6a8de00 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + betalupi: + image: git.betalupi.com/mark/betalupi-webpage:latest + container_name: betalupi + restart: unless-stopped + command: 'webpage serve 0.0.0.0:3000' + + ports: + - '8256:8256'