diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml deleted file mode 100644 index 44e00e2..0000000 --- a/.github/workflows/cd.yml +++ /dev/null @@ -1,67 +0,0 @@ -# This workflow will create a GitHub release every time a tag is pushed -name: Deploy @onsonr/es to npm - -on: - push: - branches: - - "master" - - "main" - -jobs: - release: - permissions: - contents: write - runs-on: ubuntu-latest - if: contains(github.event.head_commit.modified, 'src/') - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Setup pnpm - uses: pnpm/action-setup@v4 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 18 - - - name: Get pnpm store directory - id: pnpm-cache - run: | - echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT - - - name: Setup pnpm cache - uses: actions/cache@v3 - with: - path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install deps (with cache) - run: pnpm install - - - name: Setup Git Config - run: | - git config user.name "Prad N." - git config user.email "prad@sonr.io" - - - name: Build - run: pnpm run build - - - name: "Automated Version Bump and Release" - run: | - git add . - git commit -m "chore: update build artifacts [skip ci]" || echo "No changes to commit" - pnpm version patch - git push - git push --tags - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - uses: JS-DevTools/npm-publish@v3 - with: - token: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml deleted file mode 100644 index 1241d3b..0000000 --- a/.github/workflows/check-pr.yml +++ /dev/null @@ -1,138 +0,0 @@ -name: Check PR - -on: - pull_request: - merge_group: - -permissions: - contents: read # for TimonVS/pr-labeler-action to read config file - pull-requests: write # for TimonVS/pr-labeler-action to add labels in PR - -jobs: - verify-pr: - name: Test Lints - if: github.event_name == 'pull_request' - permissions: - contents: read # for TimonVS/pr-labeler-action to read config file - pull-requests: write # for TimonVS/pr-labeler-action to add labels in PR - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Required to fetch all history for merging - - - uses: TimonVS/pr-labeler-action@v5 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - configuration-path: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value - - name: Trunk Check - uses: trunk-io/trunk-action@v1 - - test-builds: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - name: Test Builds - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - name: Run Sonrd Build - run: make build - - test-unit: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - name: Test Unit - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - run: make test-unit - - test-race: - runs-on: ubuntu-latest - if: github.event_name == 'merge_group' - name: Test Race - continue-on-error: true - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - run: make test-race - - test-cover: - runs-on: ubuntu-latest - if: github.event_name == 'merge_group' - name: Test Coverage - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - run: make test-cover - - validate-release: - if: github.event_name == 'merge_group' || github.event_name == 'pull_request' - runs-on: ubuntu-latest - name: Test Release - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - - name: Commitizen Dry Run - uses: commitizen-tools/commitizen-action@master - with: - push: false - dry_run: true - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: main - - - name: Check GoReleaser Config - run: make release-check - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: GoReleaser Dry Run - run: make release-dry - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..5804717 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,30 @@ +name: Deploy Worker +on: + push: + workflow_dispatch: + workflow_call: + +jobs: + wrangler: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: current + + - name: Deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + workingDirectory: cmd/vault diff --git a/.github/workflows/new-release.yml b/.github/workflows/new-release.yml deleted file mode 100644 index 5187773..0000000 --- a/.github/workflows/new-release.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: New Release -on: - release: - types: [published] - -permissions: - contents: write - issues: write - -jobs: - buf_push: - name: Publish Protobufs - runs-on: ubuntu-latest - steps: - # Run `git checkout` - - uses: actions/checkout@v4 - # Install the `buf` CLI - - uses: bufbuild/buf-setup-action@v1 - # Push only the Input in `proto` to the BSR - - uses: bufbuild/buf-push-action@v1 - continue-on-error: true - with: - input: proto - buf_token: ${{ secrets.BUF_TOKEN }} - - container-push: - name: Publish Docker Images - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ghcr.io/onsonr/sonr:latest - - docs-push: - runs-on: ubuntu-latest - name: Publish Tech Docs - steps: - - uses: actions/checkout@v4 - - name: Configure Git Credentials - run: | - git config user.name github-actions[bot] - git config user.email 41898282+github-actions[bot]@users.noreply.github.com - - uses: actions/setup-python@v5 - with: - python-version: 3.x - - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV - - uses: actions/cache@v4 - with: - key: mkdocs-material-${{ env.cache_id }} - path: .cache - restore-keys: | - mkdocs-material- - - run: pip install mkdocs-material - - run: mkdocs gh-deploy --force diff --git a/.github/workflows/new-tag.yml b/.github/workflows/new-tag.yml deleted file mode 100644 index 63ce139..0000000 --- a/.github/workflows/new-tag.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: New Tag - -on: - pull_request: - types: [closed] - push: - tags: - - v* - branches: - - main - -permissions: - contents: write - -jobs: - new-release: - name: Create Release - if: startsWith(github.ref, 'refs/tags/') - permissions: write-all - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: onsonr/sonr - fetch-depth: 0 - fetch-tags: true - - - uses: actions/setup-go@v5 - with: - go-version: "1.23" - check-latest: true - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Run GoReleaser - run: make release - env: - GITHUB_TOKEN: ${{ secrets.GH_RELEASER_TOKEN }} - GITHUB_PERSONAL_AUTH_TOKEN: ${{ secrets.GH_RELEASER_TOKEN }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} - REDDIT_APP_ID: ${{ secrets.REDDIT_APP_ID }} - REDDIT_SECRET: ${{ secrets.REDDIT_SECRET }} - REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }} - REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }} diff --git a/.github/workflows/post-merge.yml b/.github/workflows/post-merge.yml deleted file mode 100644 index 44f1cf5..0000000 --- a/.github/workflows/post-merge.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Post Merge -on: - pull_request: - types: [closed] - -permissions: - contents: write - issues: write - -jobs: - bump-version: - name: Version Bump - if: | - github.event.pull_request.merged == true && - github.event.pull_request.user.login != 'dependabot[bot]' && - github.event.pull_request.user.login != 'dependabot-preview[bot]' - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ssh-key: "${{ secrets.COMMIT_KEY }}" - - - name: Create bump and changelog - uses: commitizen-tools/commitizen-action@master - with: - push: false - increment: patch - - - name: Push using ssh - run: | - git push origin main --tags diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f5899d1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: New Release +on: + push: + tags: + - "v*.*.*" + - "*" + +permissions: + contents: write + issues: write + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..6ac05f4 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,43 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj +version: 2 + +before: + hooks: + - go mod tidy + - sqlc generate + - templ generate + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + +archives: + - formats: [tar.gz] + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + format_overrides: + - goos: windows + formats: [zip] + +changelog: + sort: desc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + footer: >- + --- + + Released by [GoReleaser](https://github.com/goreleaser/goreleaser). diff --git a/README.md b/README.md index b04bd6a..d182a54 100644 --- a/README.md +++ b/README.md @@ -33,64 +33,56 @@ docker-compose up -d ## Usage -### Run Using Docker +### Development Setup -The simplest way to run the full Motr system is with Docker Compose: +Motr uses [Task](https://taskfile.dev) for managing development workflows. Here are the primary commands: ```bash -# Start all services -docker-compose up -d +# Clean build artifacts +task clean -# View logs -docker-compose logs -f +# Build all components +task build -# Stop services -docker-compose down +# Deploy all components to Cloudflare +task deploy + +# Start the local development server +task serve ``` -### Run as a Local Server +### Component-specific commands -```go -package main +```bash +# Start the Vault component (Cloudflare Worker) +task start:vault -import ( - "database/sql" - "log" +# Start the Frontend component +task start:front - "github.com/sonr-io/motr/app" - "github.com/sonr-io/motr/pkg/models" - "github.com/sonr-io/motr/pkg/types" -) +# Build specific components +task build:vault +task build:front -func main() { - dbq, err := setupDatabase() - if err != nil { - log.Fatal(err) - } +# Deploy specific components to Cloudflare +task deploy:vault +task deploy:front +``` - config := &types.Config{ - MotrToken: "your-token", - SonrChainID: "sonr-testnet-1", - // Other configuration options - } +### Database operations - vault, err := app.New(config, dbq) - if err != nil { - log.Fatal(err) - } +```bash +# Generate SQL models using sqlc +task gen:sqlc - // Start the server - vault.Start(":8080") -} - -func setupDatabase() (*models.Queries, error) { - // Initialize your database connection - // ... -} +# Migrate the database +task db:migrate ``` ### Compile to WebAssembly +The project uses WebAssembly for cross-platform compatibility. Components are compiled automatically when using the Task commands above, but you can also build manually: + ```sh # Build the signer as WASM GOOS=js GOARCH=wasm go build -o build/signer.wasm ./cmd/signer/main.go @@ -115,6 +107,7 @@ Motr can be integrated into progressive web applications, providing: Motr consists of several components: +- **Vault**: Core component deployed as a Cloudflare Worker with WebAssembly - **Controller**: Manages WebAuthn credential creation and verification - **Resolver**: Handles name resolution and identity lookups - **Signer**: WebAssembly-based cryptographic operations for secure signing @@ -124,27 +117,62 @@ Motr consists of several components: ### Component Details -1. **Controller** +1. **Vault** + - Core component deployed as a Cloudflare Worker + - Manages decentralized identity and authentication + - Integrates with IPFS/Helia for decentralized storage + - Uses WebAssembly plugins for cryptographic operations + - Package located at `cmd/vault/` +2. **Controller** - Manages user credentials and authentication - Integrates with WebAuthn for credential storage - - Containerized for easy deployment - -2. **Resolver** + - Uses SQLite via D1 database for persistent storage +3. **Resolver** - Resolves Sonr names to addresses and profiles - Serves as a gateway to the Sonr network - Implemented as a Cloudflare Worker -3. **Signer** +4. **Signer** - Secure cryptographic operations - WebAssembly-based for cross-platform compatibility - Handles key management and signatures +## Development + +### Build System + +Motr uses the following build tools: + +- **Task**: Task runner for development workflows +- **GoReleaser**: Handles building and releasing Go applications +- **SQLC**: Generates type-safe Go code from SQL +- **Templ**: Template engine for Go HTML templates +- **Air**: Live reload for Go applications during development +- **Bun**: JavaScript runtime and package manager + +### Release Process + +```bash +# Create a new release +task release +``` + +The release process uses GoReleaser with configuration in `.goreleaser.yaml`. + ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. +To contribute: + +1. Fork the repository +2. Create your feature branch (`git checkout -b feature/amazing-feature`) +3. Commit your changes using conventional commits (`git commit -m 'feat: add some amazing feature'`) +4. Push to the branch (`git push origin feature/amazing-feature`) +5. Open a Pull Request + ## License [MIT](LICENSE) diff --git a/Taskfile.yml b/Taskfile.yml index 5b0e9ac..17e27ad 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -13,6 +13,10 @@ tasks: - task: tidy:front - task: tidy:root + serve: + desc: Serve the app with air + cmd: air + deploy: desc: Deploy all cmds: diff --git a/cmd/front/main.go b/cmd/front/main.go index 13c8c30..faddb7c 100644 --- a/cmd/front/main.go +++ b/cmd/front/main.go @@ -4,9 +4,9 @@ package main import ( - "github.com/sonr-io/motr/config" "github.com/sonr-io/motr/middleware" "github.com/sonr-io/motr/routes" + "github.com/sonr-io/motr/sink/config" ) func main() { diff --git a/cmd/vault/main.go b/cmd/vault/main.go index 57c0db6..7277f73 100644 --- a/cmd/vault/main.go +++ b/cmd/vault/main.go @@ -4,9 +4,9 @@ package main import ( - "github.com/sonr-io/motr/config" "github.com/sonr-io/motr/middleware" "github.com/sonr-io/motr/routes" + "github.com/sonr-io/motr/sink/config" ) func main() { diff --git a/components/inputs/input_handle.templ b/components/inputs/input_handle.templ deleted file mode 100644 index a826406..0000000 --- a/components/inputs/input_handle.templ +++ /dev/null @@ -1,33 +0,0 @@ -package inputs - -templ HandleInitial() { -
This is a demo of the Motr web app.
-You can use this app to manage your Motr account.
-This is a demo of the Motr web app.
You can use this app to manage your Motr account.