diff --git a/.cargo-husky/hooks/pre-commit b/.cargo-husky/hooks/pre-commit deleted file mode 100644 index b54392e..0000000 --- a/.cargo-husky/hooks/pre-commit +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -set -e - -echo "Running rustfmt check..." -cargo fmt --all -- - -echo "Running Clippy..." -cargo clippy --all-targets --all-features -- -D warnings - -echo "All checks passed!" \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2d69ca2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +target +.git +.gitignore +node_modules +.cargo-husky +Dockerfile +docker-compose.yml \ No newline at end of file diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..b6f19f0 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + name: Rust CI + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt, clippy + + - name: Cache Cargo registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + # - name: Run tests + # run: cargo test --workspace --verbose + + - name: Run Clippy (linter) + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Run fmt check + run: cargo fmt --all -- --check + + - name: Build project + run: cargo build --workspace --verbose diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..b327092 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,82 @@ +name: Publish & Deploy + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + actions: read + +jobs: + build-and-push: + name: Build and Push to Registry + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Prepare Repo Name + id: repo_name + run: | + echo "REPO_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Login to Gitea Registry + uses: https://github.com/docker/login-action@v3 + with: + registry: https://gitea.iceberg.black + username: docker-bot + password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }} + + - name: Build and Push + uses: https://github.com/docker/build-push-action@v5 + with: + context: . + push: true + tags: | + gitea.iceberg.black/${{ env.REPO_LOWER }}:${{ github.ref_name }} + + - name: Link package to repository + run: | + PKG_NAME=${REPO_LOWER#*/} + OWNER=${REPO_LOWER%/*} + + RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X POST \ + "https://gitea.iceberg.black/api/v1/packages/${OWNER}/container/${PKG_NAME}/-/link/${PKG_NAME}" \ + -H "Authorization: token ${{ secrets.CONTAINER_REGISTRY_TOKEN }}") + echo "Link response: $RESPONSE" + + deploy: + name: Deploy via SSH + needs: build-and-push + runs-on: ubuntu-latest + steps: + - name: Copy docker-compose to server + run: | + scp docker-compose.yml bot@${{ secrets.SSH_HOST }}:/opt/iceberg/docker-compose.yml + - name: Execute remote deployment + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SSH_HOST }} + username: bot + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + scp docker-compose.yml bot@your-server:/opt/iceberg/docker-compose.yml + + REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') + + echo "${{ secrets.CONTAINER_REGISTRY_TOKEN }}" | docker login gitea.iceberg.black -u "docker-bot" --password-stdin + docker pull gitea.iceberg.black/${{ env.REPO_LOWER }}:${{ github.ref_name }} + docker logout gitea.iceberg.black + + docker stop chat || true + docker rm chat || true + + docker compose up -d + + docker image prune -af + diff --git a/.pre-commit-config.yml b/.pre-commit-config.yml new file mode 100644 index 0000000..c71a39b --- /dev/null +++ b/.pre-commit-config.yml @@ -0,0 +1,16 @@ +repos: + - repo: local + hooks: + - id: fmt + name: rustfmt + language: system + entry: cargo fmt -- + types: [rust] + pass_filenames: false + + - id: clippy + name: clippy + language: system + entry: cargo clippy -- -D warnings + types: [rust] + pass_filenames: false \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 97c4fb0..c4d9d26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,12 +113,6 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" -[[package]] -name = "cargo-husky" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad" - [[package]] name = "cc" version = "1.2.59" @@ -154,7 +148,6 @@ name = "chat" version = "0.1.0" dependencies = [ "axum", - "cargo-husky", "dotenvy", "jsonwebtoken", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 72c6e1e..1b70dba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dev-dependencies] -cargo-husky = "1.5.0" +lefthook = "1.0.0" [dependencies] axum = "0.8.8"