Compare commits
101 Commits
Author | SHA1 | Date | |
---|---|---|---|
e6b378c170 | |||
![]() |
fe05a64eb0 | ||
![]() |
7b3d66886d | ||
![]() |
bc74994ac4 | ||
![]() |
e20a67f7a4 | ||
![]() |
01e2f3eca3 | ||
![]() |
95a2a00cec | ||
![]() |
b6058aa434 | ||
![]() |
0adbbc3f06 | ||
![]() |
46058ae5d6 | ||
![]() |
94b367c2fb | ||
![]() |
548efa254c | ||
68166c8d3a | |||
3a5fa69bf6 | |||
23be247cdb | |||
9a204d3808 | |||
00e36b6c77 | |||
3b34d50120 | |||
13b652d425 | |||
3bdef16173 | |||
968378e8bb | |||
6767df7f91 | |||
f9245c4145 | |||
e20156a2de | |||
4f9dee1e27 | |||
fe8a1376fa | |||
7619be6d11 | |||
1062595d7f | |||
d829c1efb2 | |||
a1f22433a0 | |||
43fc67ded6 | |||
8e7781a346 | |||
68dd90048f | |||
7bf54bbd8c | |||
9fa5818860 | |||
77859b3d94 | |||
9e26479f67 | |||
000797f930 | |||
1e8e06738b | |||
28dbf76789 | |||
93aa1ebd3b | |||
bf13344cbe | |||
62358e100c | |||
7ee1cd94dc | |||
893aa4db51 | |||
6b9da9dc15 | |||
44e08b62fd | |||
3feb35ea7b | |||
849fec6f01 | |||
d27ee1202b | |||
32ac21afd2 | |||
39959f041d | |||
124d702ec4 | |||
2587483733 | |||
575ec574dd | |||
815cf96374 | |||
2b6c24bc86 | |||
632774d051 | |||
1d6b419a15 | |||
2da7526265 | |||
92877b669e | |||
10168843e1 | |||
0889f9c7b1 | |||
084010e38c | |||
8158c195f5 | |||
174d15de5b | |||
56523795d5 | |||
32bdb3d709 | |||
b30d14af9a | |||
1220a37b60 | |||
a3e008c317 | |||
58498c87af | |||
fd9abb948a | |||
2b07f74cc1 | |||
ee4d2984dd | |||
dd80776bb1 | |||
d0e7ae9284 | |||
63433be0bb | |||
1a856e575e | |||
a3e4154fb6 | |||
4839b74bf7 | |||
dcf5a16c3f | |||
932d82c1fc | |||
db509ffa8a | |||
c4392601b1 | |||
ca421b313d | |||
71df7b4711 | |||
106a43aaf1 | |||
5077682fa5 | |||
634bff4411 | |||
bce4d598fb | |||
3fd1e1f4a3 | |||
de1baa4517 | |||
be309409ad | |||
b6ef0cab53 | |||
e8d9a4adff | |||
fc90905dcf | |||
6494d74ab2 | |||
ca313960c4 | |||
0cb262524c | |||
05aff14703 |
21
.actions/init/action.yaml
Normal file
21
.actions/init/action.yaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
name: "Initialize"
|
||||||
|
description: "Install nix & use cachix"
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
token:
|
||||||
|
description: "cachix auth token"
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Install nix
|
||||||
|
uses: cachix/install-nix-action@v31
|
||||||
|
with:
|
||||||
|
nix_path: nixpkgs=channel:nixos-unstable
|
||||||
|
|
||||||
|
- name: Use cachix
|
||||||
|
uses: cachix/cachix-action@v16
|
||||||
|
with:
|
||||||
|
name: trevstack
|
||||||
|
authToken: "${{ inputs.token }}"
|
63
.actions/push/action.yaml
Normal file
63
.actions/push/action.yaml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
name: "Docker Push"
|
||||||
|
description: "Push to docker registry"
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
server_url:
|
||||||
|
required: true
|
||||||
|
repository:
|
||||||
|
required: true
|
||||||
|
tag:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Set env
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
REGISTRY=$(basename ${{ inputs.server_url }})
|
||||||
|
|
||||||
|
NR=${{ inputs.repository }}
|
||||||
|
NAMESPACE="${NR%%/*}"
|
||||||
|
REPOSITORY="${NR##*/}"
|
||||||
|
|
||||||
|
TAG=${{ inputs.tag }}
|
||||||
|
VERSION=${TAG#v}
|
||||||
|
|
||||||
|
echo "REGISTRY=${REGISTRY}" >> $GITHUB_ENV
|
||||||
|
echo "NAMESPACE=${NAMESPACE}" >> $GITHUB_ENV
|
||||||
|
echo "REPOSITORY=${REPOSITORY}" >> $GITHUB_ENV
|
||||||
|
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Push images
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker image tag $REPOSITORY:$VERSION-amd64 $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-amd64
|
||||||
|
docker push $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-amd64
|
||||||
|
|
||||||
|
docker image tag $REPOSITORY:$VERSION-arm64 $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm64
|
||||||
|
docker push $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm64
|
||||||
|
|
||||||
|
docker image tag $REPOSITORY:$VERSION-arm $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm
|
||||||
|
docker push $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm
|
||||||
|
|
||||||
|
- name: Push manifest
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker manifest create $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION \
|
||||||
|
$REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-amd64 \
|
||||||
|
$REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm64 \
|
||||||
|
$REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm
|
||||||
|
docker manifest annotate $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-amd64 --arch amd64
|
||||||
|
docker manifest annotate $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm64 --arch arm64
|
||||||
|
docker manifest annotate $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm --arch arm
|
||||||
|
docker manifest push $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION
|
||||||
|
|
||||||
|
docker manifest create $REGISTRY/$NAMESPACE/$REPOSITORY:latest \
|
||||||
|
$REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-amd64 \
|
||||||
|
$REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm64 \
|
||||||
|
$REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm
|
||||||
|
docker manifest annotate $REGISTRY/$NAMESPACE/$REPOSITORY:latest $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-amd64 --arch amd64
|
||||||
|
docker manifest annotate $REGISTRY/$NAMESPACE/$REPOSITORY:latest $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm64 --arch arm64
|
||||||
|
docker manifest annotate $REGISTRY/$NAMESPACE/$REPOSITORY:latest $REGISTRY/$NAMESPACE/$REPOSITORY:$VERSION-arm --arch arm
|
||||||
|
docker manifest push $REGISTRY/$NAMESPACE/$REPOSITORY:latest
|
@ -1,14 +0,0 @@
|
|||||||
.env
|
|
||||||
/docker-compose.*
|
|
||||||
/result*
|
|
||||||
/.direnv/
|
|
||||||
/build/
|
|
||||||
|
|
||||||
# Client
|
|
||||||
/client/node_modules/
|
|
||||||
/client/.svelte-kit/
|
|
||||||
|
|
||||||
# Server
|
|
||||||
/server/client/
|
|
||||||
/server/tmp/
|
|
||||||
/server/build/
|
|
23
.gitea/workflows/check.yaml
Normal file
23
.gitea/workflows/check.yaml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
name: Check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, edited, auto_merge_enabled]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: |
|
||||||
|
contains(github.event.head_commit.message, 'bump:') == false &&
|
||||||
|
contains(github.event.head_commit.message, 'Merge pull request') == false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.actions/init
|
||||||
|
with:
|
||||||
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
|
- run: nix flake check
|
68
.gitea/workflows/release.yaml
Normal file
68
.gitea/workflows/release.yaml
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.actions/init
|
||||||
|
with:
|
||||||
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
|
- run: nix flake check
|
||||||
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: check
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.actions/init
|
||||||
|
with:
|
||||||
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
|
- run: >
|
||||||
|
nix build
|
||||||
|
.#trevstack-linux-amd64
|
||||||
|
.#trevstack-linux-arm64
|
||||||
|
.#trevstack-linux-arm
|
||||||
|
.#trevstack-windows-amd64
|
||||||
|
.#trevstack-darwin-amd64
|
||||||
|
.#trevstack-darwin-arm64
|
||||||
|
|
||||||
|
- uses: akkuman/gitea-release-action@v1
|
||||||
|
with:
|
||||||
|
files: |-
|
||||||
|
result*/bin/*
|
||||||
|
|
||||||
|
package:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: release
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.actions/init
|
||||||
|
with:
|
||||||
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
|
- uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ github.server_url }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.PAT }}
|
||||||
|
|
||||||
|
- name: Build & load images
|
||||||
|
run: |
|
||||||
|
nix build .#trevstack-linux-amd64-image && ./result | docker load
|
||||||
|
nix build .#trevstack-linux-arm64-image && ./result | docker load
|
||||||
|
nix build .#trevstack-linux-arm-image && ./result | docker load
|
||||||
|
|
||||||
|
- name: Push images
|
||||||
|
uses: ./.actions/push
|
||||||
|
with:
|
||||||
|
server_url: ${{ github.server_url }}
|
||||||
|
repository: ${{ github.repository }}
|
||||||
|
tag: ${{ github.ref_name }}
|
50
.gitea/workflows/update.yaml
Normal file
50
.gitea/workflows/update.yaml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
name: Update
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 0 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.actions/init
|
||||||
|
with:
|
||||||
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
|
# https://github.com/actions/checkout/issues/13
|
||||||
|
- name: Set git config
|
||||||
|
run: |
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
git checkout -B update
|
||||||
|
|
||||||
|
- run: nix run .#update
|
||||||
|
|
||||||
|
- name: Create pull request
|
||||||
|
env:
|
||||||
|
PAT: ${{ secrets.PAT }}
|
||||||
|
run: |
|
||||||
|
URL="${{ gitea.server_url }}"
|
||||||
|
REPO_OWNER_SLASH_NAME="${{ gitea.repository }}"
|
||||||
|
|
||||||
|
if ! git ls-remote --exit-code origin update; then
|
||||||
|
git push origin update --force
|
||||||
|
|
||||||
|
PR_RESPONSE=$(curl -s -X POST -H "Authorization: token $PAT" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"title":"update","body":"automatic update","head":"update","base":"main"}' \
|
||||||
|
"$URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls")
|
||||||
|
|
||||||
|
PR_NUMBER=$(echo "$PR_RESPONSE" | jq -r '.number')
|
||||||
|
|
||||||
|
curl -s -X POST -H "Authorization: token $PAT" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"Do":"merge","merge_when_checks_succeed":true,"delete_branch_after_merge":true}' \
|
||||||
|
"$URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls/$PR_NUMBER/merge"
|
||||||
|
|
||||||
|
else
|
||||||
|
git push origin update --force
|
||||||
|
fi
|
23
.github/workflows/check.yaml
vendored
Normal file
23
.github/workflows/check.yaml
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
name: Check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, edited, auto_merge_enabled]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: |
|
||||||
|
contains(github.event.head_commit.message, 'bump:') == false &&
|
||||||
|
contains(github.event.head_commit.message, 'Merge pull request') == false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.actions/init
|
||||||
|
with:
|
||||||
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
|
- run: nix flake check
|
28
.github/workflows/lint.yaml
vendored
28
.github/workflows/lint.yaml
vendored
@ -1,28 +0,0 @@
|
|||||||
name: Lint Workflow
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install Nix
|
|
||||||
uses: cachix/install-nix-action@v31
|
|
||||||
with:
|
|
||||||
nix_path: nixpkgs=channel:nixos-unstable
|
|
||||||
|
|
||||||
- name: Use Cachix
|
|
||||||
uses: cachix/cachix-action@v16
|
|
||||||
with:
|
|
||||||
name: trevstack
|
|
||||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
|
||||||
|
|
||||||
- name: Run checks
|
|
||||||
run: nix flake check
|
|
81
.github/workflows/release.yaml
vendored
81
.github/workflows/release.yaml
vendored
@ -1,34 +1,35 @@
|
|||||||
name: Release Workflow
|
name: Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- "*"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- uses: ./.actions/init
|
||||||
|
|
||||||
- name: Install Nix
|
|
||||||
uses: cachix/install-nix-action@v31
|
|
||||||
with:
|
with:
|
||||||
nix_path: nixpkgs=channel:nixos-unstable
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
- name: Use Cachix
|
- run: nix flake check
|
||||||
uses: cachix/cachix-action@v16
|
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: check
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ./.actions/init
|
||||||
with:
|
with:
|
||||||
name: trevstack
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
|
||||||
|
|
||||||
- name: Build
|
- run: >
|
||||||
run: >
|
|
||||||
nix build
|
nix build
|
||||||
.#trevstack-linux-amd64
|
.#trevstack-linux-amd64
|
||||||
.#trevstack-linux-arm64
|
.#trevstack-linux-arm64
|
||||||
@ -37,52 +38,36 @@ jobs:
|
|||||||
.#trevstack-darwin-amd64
|
.#trevstack-darwin-amd64
|
||||||
.#trevstack-darwin-arm64
|
.#trevstack-darwin-arm64
|
||||||
|
|
||||||
- name: Create Release
|
- uses: softprops/action-gh-release@v2
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
with:
|
||||||
|
generate_release_notes: true
|
||||||
files: |-
|
files: |-
|
||||||
result*/bin/*
|
result*/bin/*
|
||||||
|
|
||||||
# https://docs.docker.com/build/ci/github-actions/manage-tags-labels/
|
|
||||||
package:
|
package:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: release # Wait for binary cache to propagate
|
needs: release
|
||||||
steps:
|
steps:
|
||||||
- name: Docker meta
|
- uses: actions/checkout@v4
|
||||||
id: meta
|
- uses: ./.actions/init
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
with:
|
||||||
# list of Docker images to use as base name for tags
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
images: |
|
|
||||||
${{ github.repository }}
|
|
||||||
ghcr.io/${{ github.repository }}
|
|
||||||
# generate Docker tags based on the following events/attributes
|
|
||||||
tags: |
|
|
||||||
type=ref,event=branch
|
|
||||||
type=semver,pattern={{version}}
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- uses: docker/login-action@v3
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Build & load images
|
||||||
uses: docker/setup-qemu-action@v3
|
run: |
|
||||||
|
nix build .#trevstack-linux-amd64-image && ./result | docker load
|
||||||
|
nix build .#trevstack-linux-arm64-image && ./result | docker load
|
||||||
|
nix build .#trevstack-linux-arm-image && ./result | docker load
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Push images
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: ./.actions/push
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
with:
|
||||||
push: true
|
server_url: ghcr.io
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
repository: ${{ github.repository }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
tag: ${{ github.ref_name }}
|
||||||
|
39
.github/workflows/update.yaml
vendored
39
.github/workflows/update.yaml
vendored
@ -1,41 +1,40 @@
|
|||||||
name: Update Workflow
|
name: Update
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 0 * * *"
|
- cron: "0 0 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update:
|
update:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- uses: ./.actions/init
|
||||||
|
|
||||||
- name: Install Nix
|
|
||||||
uses: cachix/install-nix-action@v31
|
|
||||||
with:
|
with:
|
||||||
nix_path: nixpkgs=channel:nixos-unstable
|
token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
|
||||||
|
|
||||||
- name: Use Cachix
|
|
||||||
uses: cachix/cachix-action@v16
|
|
||||||
with:
|
|
||||||
name: trevstack
|
|
||||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
|
||||||
|
|
||||||
# https://github.com/actions/checkout/issues/13
|
# https://github.com/actions/checkout/issues/13
|
||||||
- name: Set Git Config
|
- name: Set git config
|
||||||
run: |
|
run: |
|
||||||
git config user.name "github-actions[bot]"
|
git config user.name "github-actions[bot]"
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
- name: Update
|
- run: nix run .#update
|
||||||
run: nix run .#update
|
|
||||||
|
|
||||||
- name: Create Pull Request
|
- name: Create pull request
|
||||||
|
id: cpr
|
||||||
uses: peter-evans/create-pull-request@v7
|
uses: peter-evans/create-pull-request@v7
|
||||||
with:
|
with:
|
||||||
delete-branch: true
|
branch: update
|
||||||
title: Bump deps
|
title: update
|
||||||
|
body: automatic update
|
||||||
|
|
||||||
|
- name: Enable automerge
|
||||||
|
run: gh pr merge --merge --auto "${{ steps.cpr.outputs.pull-request-number }}"
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.PAT }}
|
||||||
|
@ -3,7 +3,25 @@
|
|||||||
git_root=$(git rev-parse --show-toplevel)
|
git_root=$(git rev-parse --show-toplevel)
|
||||||
git_version=$(git describe --tags --abbrev=0)
|
git_version=$(git describe --tags --abbrev=0)
|
||||||
version=${git_version#v}
|
version=${git_version#v}
|
||||||
next_version=$(echo "${version}" | awk -F. -v OFS=. '{$NF += 1 ; print}')
|
|
||||||
|
major=$(echo "${version}" | cut -d . -f1)
|
||||||
|
minor=$(echo "${version}" | cut -d . -f2)
|
||||||
|
patch=$(echo "${version}" | cut -d . -f3)
|
||||||
|
case "${1-patch}" in
|
||||||
|
major) major=$((major + 1)) ;;
|
||||||
|
minor) minor=$((minor + 1)) ;;
|
||||||
|
*) patch=$((patch + 1)) ;;
|
||||||
|
esac
|
||||||
|
next_version="${major}.${minor}.${patch}"
|
||||||
|
|
||||||
|
echo "${version} -> ${next_version}"
|
||||||
|
|
||||||
|
echo "bumping openapi"
|
||||||
|
cd "${git_root}"
|
||||||
|
sed -i -e "s/${version}/${next_version}/g" openapi.yaml
|
||||||
|
sed -i -e "s/${version}/${next_version}/g" client/static/openapi/openapi.yaml
|
||||||
|
git add openapi.yaml
|
||||||
|
git add client/static/openapi/openapi.yaml
|
||||||
|
|
||||||
echo "bumping client"
|
echo "bumping client"
|
||||||
cd "${git_root}/client"
|
cd "${git_root}/client"
|
||||||
|
@ -11,6 +11,14 @@ if ! git diff --exit-code flake.lock; then
|
|||||||
git commit -m "build(nix): updated nix dependencies"
|
git commit -m "build(nix): updated nix dependencies"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "updating protobuf deps"
|
||||||
|
cd "${git_root}/proto"
|
||||||
|
buf dep update
|
||||||
|
if ! git diff --exit-code buf.lock; then
|
||||||
|
git add buf.lock
|
||||||
|
git commit -m "build(buf): updated buf dependencies"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "updating client"
|
echo "updating client"
|
||||||
cd "${git_root}/client"
|
cd "${git_root}/client"
|
||||||
npm update --save && npm i
|
npm update --save && npm i
|
||||||
|
1
.vscode/extensions.json
vendored
1
.vscode/extensions.json
vendored
@ -2,6 +2,7 @@
|
|||||||
"recommendations": [
|
"recommendations": [
|
||||||
"golang.go",
|
"golang.go",
|
||||||
"dorzey.vscode-sqlfluff",
|
"dorzey.vscode-sqlfluff",
|
||||||
|
"bufbuild.vscode-buf",
|
||||||
"dbaeumer.vscode-eslint",
|
"dbaeumer.vscode-eslint",
|
||||||
"svelte.svelte-vscode",
|
"svelte.svelte-vscode",
|
||||||
"esbenp.prettier-vscode"
|
"esbenp.prettier-vscode"
|
||||||
|
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@ -4,6 +4,7 @@
|
|||||||
// Go
|
// Go
|
||||||
"go.lintTool": "revive",
|
"go.lintTool": "revive",
|
||||||
"go.formatTool": "goimports",
|
"go.formatTool": "goimports",
|
||||||
|
"go.buildTags": "dev",
|
||||||
"go.lintFlags": ["--config=server/revive.toml"],
|
"go.lintFlags": ["--config=server/revive.toml"],
|
||||||
"gopls": { "ui.semanticTokens": true },
|
"gopls": { "ui.semanticTokens": true },
|
||||||
"[go]": {
|
"[go]": {
|
||||||
@ -12,6 +13,14 @@
|
|||||||
|
|
||||||
// SQLFluff
|
// SQLFluff
|
||||||
"sqlfluff.config": "server/db/.sqlfluff",
|
"sqlfluff.config": "server/db/.sqlfluff",
|
||||||
|
"[sql]": {
|
||||||
|
"editor.defaultFormatter": "dorzey.vscode-sqlfluff"
|
||||||
|
},
|
||||||
|
|
||||||
|
// Proto
|
||||||
|
"[proto]": {
|
||||||
|
"editor.defaultFormatter": "bufbuild.vscode-buf"
|
||||||
|
},
|
||||||
|
|
||||||
// ESLint
|
// ESLint
|
||||||
"eslint.workingDirectories": ["./client"],
|
"eslint.workingDirectories": ["./client"],
|
||||||
|
29
Dockerfile
29
Dockerfile
@ -1,29 +0,0 @@
|
|||||||
# Nix builder
|
|
||||||
FROM nixos/nix:latest AS builder
|
|
||||||
|
|
||||||
# Copy our source and setup our working dir.
|
|
||||||
COPY . /tmp/build
|
|
||||||
WORKDIR /tmp/build
|
|
||||||
|
|
||||||
# Build our Nix environment
|
|
||||||
RUN nix \
|
|
||||||
--extra-experimental-features "nix-command flakes" \
|
|
||||||
--option filter-syscalls false \
|
|
||||||
--accept-flake-config \
|
|
||||||
build
|
|
||||||
|
|
||||||
# Copy the Nix store closure into a directory. The Nix store closure is the
|
|
||||||
# entire set of Nix store values that we need for our build.
|
|
||||||
RUN mkdir /tmp/nix-store-closure
|
|
||||||
RUN cp -R $(nix-store -qR result/) /tmp/nix-store-closure
|
|
||||||
|
|
||||||
# Final image is based on scratch. We copy a bunch of Nix dependencies
|
|
||||||
# but they're fully self-contained so we don't need Nix anymore.
|
|
||||||
FROM scratch
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy /nix/store
|
|
||||||
COPY --from=builder /tmp/nix-store-closure /nix/store
|
|
||||||
COPY --from=builder /tmp/build/result /app
|
|
||||||
CMD ["/app/bin/trevstack"]
|
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Trev
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
125
README.md
Normal file
125
README.md
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
## TrevStack
|
||||||
|
|
||||||
|
This is a CRUD app to use as a template for starting projects
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- **Communicate anywhere**. Define a [protocol buffer](https://protobuf.dev/), and [Connect](https://connectrpc.com/) generates type-safe code to facilitate communication between the server and any client (web, mobile, embedded, etc). The protocol buffers can contain annotations to validate fields on the client and server. For clients that cannot use Connect, an OpenAPI spec is also generated
|
||||||
|
- **Build anywhere**. The dev environment, testing and building is all declared in a single [Nix](https://nixos.org/) flake. Every developer and server can use the same environment
|
||||||
|
- **Deploy anywhere**. CI/CD is already set up using github actions. New versions are automatically released for every major platform, along with a docker image. The binaries created require zero run-time dependencies and are relatively small (this app is 26 MiB)
|
||||||
|
- Can be entirely self-hosted
|
||||||
|
- Authentication is rolled in, including API key, fingerprint & passkey
|
||||||
|
- Automatic database migration on startup
|
||||||
|
- Light & dark modes with the [catppuccin](https://catppuccin.com/palette/) color palette
|
||||||
|
- Really good at running as a [progressive web app](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps)
|
||||||
|
|
||||||
|
While I personally prefer using a Svelte frontend and Go backend, feel free to swap them out with whatever you like, you'll be surprised how easy it is.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
1. [Install Nix](https://nixos.org/download/)
|
||||||
|
2. Run `nix develop`
|
||||||
|
3. Create a `server/.env` file that looks something like
|
||||||
|
|
||||||
|
```env
|
||||||
|
KEY=changeme
|
||||||
|
PORT=8080
|
||||||
|
URL=http://localhost:5173
|
||||||
|
DATABASE_URL=sqlite:/home/trev/.config/trevstack/sqlite.db
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Run `treli` to start the server & client
|
||||||
|
|
||||||
|
It's that simple. If you're feeling fancy, install [direnv](https://direnv.net/) and the dev environment will load automatically.
|
||||||
|
|
||||||
|
### Useful Commands
|
||||||
|
|
||||||
|
- `nix run #update`: updates all of the dependencies
|
||||||
|
|
||||||
|
- `nix run #bump [major | minor]`: bumps the current version up one. Defaults to "patch" (0.0.1 -> 0.0.2)
|
||||||
|
|
||||||
|
- `nix build [#trevstack-(GOOS)-(GOARCH)]`: builds the application. Defaults to building for your current platform, but can be built to many by specifying the GOOS and GOARCH values
|
||||||
|
|
||||||
|
- `nix flake check`: runs all validations
|
||||||
|
|
||||||
|
- `buf lint proto` & `buf generate`: lints and generates code from protocol buffers
|
||||||
|
|
||||||
|
- `sqlc vet` & `sqlc generate`: verifies and generates code from SQL files
|
||||||
|
|
||||||
|
- `dbmate new` & `dbmate up`: creates a new migration file and runs pending migrations
|
||||||
|
|
||||||
|
### Github Actions
|
||||||
|
|
||||||
|
To use github actions for CI/CD, you'll need to create a fine-grained personal access token for the repository with the permissions:
|
||||||
|
|
||||||
|
- Contents (read and write)
|
||||||
|
- Pull requests (read and write)
|
||||||
|
|
||||||
|
And change some settings for the repository:
|
||||||
|
|
||||||
|
- General -> Allow auto-merge: true
|
||||||
|
- Rules -> Rulesets -> New ruleset
|
||||||
|
- Branch targeting criteria: Default
|
||||||
|
- Branch rules
|
||||||
|
- Require status checks to pass -> Add checks -> "check"
|
||||||
|
- Actions -> General -> Workflow permissions
|
||||||
|
- Read and write permissions: true
|
||||||
|
- Allow GitHub Actions to create and approve pull requests: true
|
||||||
|
- Secrets and variables -> Actions -> Repository secrets
|
||||||
|
- PAT: (personal access token)
|
||||||
|
|
||||||
|
### Gitea Actions
|
||||||
|
|
||||||
|
To use gitea actions for CI/CD, you'll need to create an [API token](https://docs.gitea.com/development/api-usage) with the scopes:
|
||||||
|
|
||||||
|
- write:repository
|
||||||
|
- write:package
|
||||||
|
|
||||||
|
And change some settings for the repository:
|
||||||
|
|
||||||
|
- Repository -> Delete pull request branch after merge by default: true
|
||||||
|
- Branches -> Add New Rule
|
||||||
|
- Protected Branch Name Pattern: main
|
||||||
|
- Enable Status Check: true
|
||||||
|
- Status check patterns: Check / check\*
|
||||||
|
- Actions -> Secrets
|
||||||
|
- PAT: (API token)
|
||||||
|
|
||||||
|
## Components
|
||||||
|
|
||||||
|
### Client
|
||||||
|
|
||||||
|
- **svelte 5** [[docs](https://svelte.dev/docs/svelte)] UI framework
|
||||||
|
- **tailwind 4** [[docs](https://tailwindcss.com/)] CSS framework
|
||||||
|
- **bits ui** [[docs](https://bits-ui.com/docs/)] headless components
|
||||||
|
- [components](https://github.com/spotdemo4/trevstack/tree/main/client/src/lib/ui) from **shadcn-svelte** [[docs](https://www.shadcn-svelte.com/docs)] altered to work with tailwind 4, fit the [catppuccin](https://catppuccin.com/palette/) color palette, and use [shallow routing](https://svelte.dev/docs/kit/shallow-routing)
|
||||||
|
- **connect rpc** [[docs](https://connectrpc.com/docs/web/)] to communicating with the server
|
||||||
|
- **protovalidate-es** [[docs](https://github.com/bufbuild/protovalidate-es)], along with a function [coolforms](https://github.com/spotdemo4/trevstack/blob/main/client/src/lib/coolforms/) to emulate the library [sveltekit-superforms](https://superforms.rocks/)
|
||||||
|
- **simplewebauthn** [[docs](https://simplewebauthn.dev/docs/packages/browser)] for passkey authentication
|
||||||
|
- **scalar** [[docs](https://github.com/scalar/scalar)] for displaying openapi specs
|
||||||
|
- **tw-animate-css** [[docs](https://github.com/Wombosvideo/tw-animate-css)] to animate with just tailwind classes
|
||||||
|
- vite [[docs](https://vite.dev/)] for dev server and bundling
|
||||||
|
- eslint [[docs](https://eslint.org/)] for linting
|
||||||
|
- prettier [[docs](https://prettier.io/)] for formatting
|
||||||
|
- prettier-plugin-svelte [[docs](https://github.com/sveltejs/prettier-plugin-svelte)]
|
||||||
|
- prettier-plugin-tailwindcss [[docs](https://github.com/tailwindlabs/prettier-plugin-tailwindcss)]
|
||||||
|
- prettier-plugin-sort-imports [[docs](https://github.com/IanVS/prettier-plugin-sort-imports)]
|
||||||
|
|
||||||
|
### Server
|
||||||
|
|
||||||
|
- **go** [[docs](https://go.dev/doc/)]
|
||||||
|
- **connect rpc** [[docs](https://connectrpc.com/docs/go/)] to serve gRPC & HTTP requests
|
||||||
|
- **protovalidate-go** [[docs](https://github.com/bufbuild/protovalidate-go)] for validating those requests
|
||||||
|
- **sqlc** [[docs](https://docs.sqlc.dev/en/latest/)] because writing the SQL yourself is better than an ORM
|
||||||
|
- **go-webauthn** [[docs](https://github.com/go-webauthn/webauthn)] because webauthn is hard
|
||||||
|
- **dbmate** [[docs](https://github.com/amacneil/dbmate)] for database migrations
|
||||||
|
- revive [[docs](https://github.com/mgechev/revive)] for linting
|
||||||
|
|
||||||
|
### Protocol Buffers / gRPC
|
||||||
|
|
||||||
|
- **buf** [[docs](https://buf.build/docs/)] CLI for linting & code generation
|
||||||
|
- **protovalidate** [[docs](https://buf.build/docs/protovalidate/)] provides annotations to validate proto messages & fields
|
||||||
|
- **protoc-gen-connect-openapi** [[docs](https://github.com/sudorandom/protoc-gen-connect-openapi)] generates openapi specs
|
||||||
|
- protoc-gen-go [[docs](https://pkg.go.dev/google.golang.org/protobuf)]
|
||||||
|
- protoc-gen-connect-go [[docs](https://connectrpc.com/docs/go)]
|
||||||
|
- protoc-gen-es [[docs](https://connectrpc.com/docs/web/)]
|
@ -1,5 +1,8 @@
|
|||||||
version: v2
|
version: v2
|
||||||
clean: true
|
clean: true
|
||||||
|
inputs:
|
||||||
|
- directory: proto
|
||||||
|
|
||||||
managed:
|
managed:
|
||||||
enabled: true
|
enabled: true
|
||||||
override:
|
override:
|
||||||
@ -27,5 +30,5 @@ plugins:
|
|||||||
out: client/static/openapi
|
out: client/static/openapi
|
||||||
strategy: all
|
strategy: all
|
||||||
opt:
|
opt:
|
||||||
- base=openapi.base.yaml
|
- base=openapi.yaml
|
||||||
- path=openapi.yaml
|
- path=openapi.yaml
|
||||||
|
1745
client/package-lock.json
generated
1745
client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "trevstack",
|
"name": "trevstack",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.23",
|
"version": "0.0.47",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
@ -21,30 +21,29 @@
|
|||||||
"@eslint/js": "^9.18.0",
|
"@eslint/js": "^9.18.0",
|
||||||
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
|
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
|
||||||
"@lucide/svelte": "^0.479.0",
|
"@lucide/svelte": "^0.479.0",
|
||||||
"@scalar/api-reference": "^1.28.33",
|
"@scalar/api-reference": "^1.28.34",
|
||||||
"@simplewebauthn/browser": "^13.1.0",
|
"@simplewebauthn/browser": "^13.1.0",
|
||||||
"@sveltejs/adapter-static": "^3.0.8",
|
"@sveltejs/adapter-static": "^3.0.8",
|
||||||
"@sveltejs/kit": "^2.21.0",
|
"@sveltejs/kit": "^2.21.1",
|
||||||
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||||
"@tailwindcss/vite": "^4.1.6",
|
"@tailwindcss/vite": "^4.1.7",
|
||||||
"bits-ui": "^1.4.8",
|
"bits-ui": "^1.5.3",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"eslint": "^9.26.0",
|
"eslint": "^9.27.0",
|
||||||
"eslint-config-prettier": "^10.1.5",
|
"eslint-config-prettier": "^10.1.5",
|
||||||
"eslint-plugin-svelte": "^3.6.0",
|
"eslint-plugin-svelte": "^3.8.1",
|
||||||
"fast-deep-equal": "^3.1.3",
|
|
||||||
"globals": "^16.1.0",
|
"globals": "^16.1.0",
|
||||||
"mode-watcher": "^1.0.7",
|
"mode-watcher": "^1.0.7",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.5.3",
|
||||||
"prettier-plugin-svelte": "^3.3.3",
|
"prettier-plugin-svelte": "^3.4.0",
|
||||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||||
"svelte": "^5.28.6",
|
"svelte": "^5.31.1",
|
||||||
"svelte-check": "^4.1.7",
|
"svelte-check": "^4.2.1",
|
||||||
"svelte-sonner": "^0.3.28",
|
"svelte-sonner": "^0.3.28",
|
||||||
"tailwind-merge": "^3.3.0",
|
"tailwind-merge": "^3.3.0",
|
||||||
"tailwind-variants": "^1.0.0",
|
"tailwind-variants": "^1.0.0",
|
||||||
"tailwindcss": "^4.0.13",
|
"tailwindcss": "^4.0.13",
|
||||||
"tw-animate-css": "^1.2.9",
|
"tw-animate-css": "^1.3.0",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
"typescript-eslint": "^8.32.1",
|
"typescript-eslint": "^8.32.1",
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
|
@ -3,8 +3,8 @@ servers:
|
|||||||
- url: /grpc
|
- url: /grpc
|
||||||
info:
|
info:
|
||||||
title: Trevstack API
|
title: Trevstack API
|
||||||
version: 1.0.0
|
version: 0.0.33
|
||||||
description: API for trevstack
|
description: API for Trevstack
|
||||||
contact:
|
contact:
|
||||||
name: Trev
|
name: Trev
|
||||||
email: spam@trev.xyz
|
email: spam@trev.xyz
|
||||||
|
6
flake.lock
generated
6
flake.lock
generated
@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1746904237,
|
"lastModified": 1747542820,
|
||||||
"narHash": "sha256-3e+AVBczosP5dCLQmMoMEogM57gmZ2qrVSrmq9aResQ=",
|
"narHash": "sha256-GaOZntlJ6gPPbbkTLjbd8BMWaDYafhuuYRNrxCGnPJw=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d89fc19e405cb2d55ce7cc114356846a0ee5e956",
|
"rev": "292fa7d4f6519c074f0a50394dbbe69859bb6043",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
72
flake.nix
72
flake.nix
@ -21,7 +21,7 @@
|
|||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
pname = "trevstack";
|
pname = "trevstack";
|
||||||
version = "0.0.23";
|
version = "0.0.47";
|
||||||
|
|
||||||
build-systems = [
|
build-systems = [
|
||||||
"x86_64-linux"
|
"x86_64-linux"
|
||||||
@ -29,6 +29,17 @@
|
|||||||
"x86_64-darwin"
|
"x86_64-darwin"
|
||||||
"aarch64-darwin"
|
"aarch64-darwin"
|
||||||
];
|
];
|
||||||
|
forSystem = f:
|
||||||
|
nixpkgs.lib.genAttrs build-systems (
|
||||||
|
system:
|
||||||
|
f {
|
||||||
|
inherit system;
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
host-systems = [
|
host-systems = [
|
||||||
{
|
{
|
||||||
GOOS = "linux";
|
GOOS = "linux";
|
||||||
@ -55,16 +66,6 @@
|
|||||||
GOARCH = "arm64";
|
GOARCH = "arm64";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
forSystem = f:
|
|
||||||
nixpkgs.lib.genAttrs build-systems (
|
|
||||||
system:
|
|
||||||
f {
|
|
||||||
inherit system;
|
|
||||||
pkgs = import nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
in {
|
in {
|
||||||
devShells = forSystem ({pkgs, ...}: let
|
devShells = forSystem ({pkgs, ...}: let
|
||||||
protoc-gen-connect-openapi = pkgs.buildGoModule {
|
protoc-gen-connect-openapi = pkgs.buildGoModule {
|
||||||
@ -80,9 +81,12 @@
|
|||||||
in {
|
in {
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
git
|
|
||||||
nix-update
|
|
||||||
treli.packages."${system}".default
|
treli.packages."${system}".default
|
||||||
|
git
|
||||||
|
|
||||||
|
# Nix
|
||||||
|
nix-update
|
||||||
|
alejandra
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
go
|
go
|
||||||
@ -91,7 +95,7 @@
|
|||||||
revive
|
revive
|
||||||
sqlc
|
sqlc
|
||||||
|
|
||||||
# database
|
# Database
|
||||||
sqlite
|
sqlite
|
||||||
dbmate
|
dbmate
|
||||||
sqlfluff
|
sqlfluff
|
||||||
@ -126,7 +130,7 @@
|
|||||||
pname = "check-client";
|
pname = "check-client";
|
||||||
inherit version;
|
inherit version;
|
||||||
src = ./client;
|
src = ./client;
|
||||||
npmDepsHash = "sha256-Te5HGbp7mKG3p1P4O266IpoPPBN7oQ/dZbttdgKbgWs=";
|
npmDepsHash = "sha256-dl32ehKir0dZ4uiJ4s59xPIIbMkkZtH9dlTm4W0PZag=";
|
||||||
dontNpmInstall = true;
|
dontNpmInstall = true;
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
@ -159,9 +163,10 @@
|
|||||||
runtimeInputs = with pkgs; [
|
runtimeInputs = with pkgs; [
|
||||||
git
|
git
|
||||||
nix
|
nix
|
||||||
nodejs_22
|
|
||||||
go
|
|
||||||
nix-update
|
nix-update
|
||||||
|
go
|
||||||
|
buf
|
||||||
|
nodejs_22
|
||||||
];
|
];
|
||||||
text = builtins.readFile ./.scripts/update.sh;
|
text = builtins.readFile ./.scripts/update.sh;
|
||||||
});
|
});
|
||||||
@ -188,7 +193,7 @@
|
|||||||
client = pkgs.buildNpmPackage {
|
client = pkgs.buildNpmPackage {
|
||||||
inherit pname version;
|
inherit pname version;
|
||||||
src = ./client;
|
src = ./client;
|
||||||
npmDepsHash = "sha256-Te5HGbp7mKG3p1P4O266IpoPPBN7oQ/dZbttdgKbgWs=";
|
npmDepsHash = "sha256-dl32ehKir0dZ4uiJ4s59xPIIbMkkZtH9dlTm4W0PZag=";
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
cp -r build "$out"
|
cp -r build "$out"
|
||||||
@ -203,13 +208,11 @@
|
|||||||
|
|
||||||
preBuild = ''
|
preBuild = ''
|
||||||
cp -r ${client} client
|
cp -r ${client} client
|
||||||
|
HOME=$PWD
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in
|
|
||||||
{
|
binaries = builtins.listToAttrs (builtins.map (x: {
|
||||||
default = server;
|
|
||||||
}
|
|
||||||
// builtins.listToAttrs (builtins.map (x: {
|
|
||||||
name = "${pname}-${x.GOOS}-${x.GOARCH}";
|
name = "${pname}-${x.GOOS}-${x.GOARCH}";
|
||||||
value = server.overrideAttrs {
|
value = server.overrideAttrs {
|
||||||
nativeBuildInputs =
|
nativeBuildInputs =
|
||||||
@ -232,7 +235,28 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
host-systems)
|
host-systems);
|
||||||
|
|
||||||
|
images = builtins.listToAttrs (builtins.map (x: {
|
||||||
|
name = "${pname}-${x.GOOS}-${x.GOARCH}-image";
|
||||||
|
value = pkgs.dockerTools.streamLayeredImage {
|
||||||
|
name = "${pname}";
|
||||||
|
tag = "${version}-${x.GOARCH}";
|
||||||
|
created = "now";
|
||||||
|
architecture = "${x.GOARCH}";
|
||||||
|
contents = [binaries."${pname}-${x.GOOS}-${x.GOARCH}"];
|
||||||
|
config = {
|
||||||
|
Cmd = ["${binaries."${pname}-${x.GOOS}-${x.GOARCH}"}/bin/${pname}-${x.GOOS}-${x.GOARCH}-${version}"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
(builtins.filter (x: x.GOOS == "linux") host-systems));
|
||||||
|
in
|
||||||
|
{
|
||||||
|
default = server;
|
||||||
|
}
|
||||||
|
// binaries
|
||||||
|
// images
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ servers:
|
|||||||
- url: /grpc
|
- url: /grpc
|
||||||
info:
|
info:
|
||||||
title: Trevstack API
|
title: Trevstack API
|
||||||
version: 1.0.0
|
version: 0.0.47
|
||||||
description: API for trevstack
|
description: API for Trevstack
|
||||||
contact:
|
contact:
|
||||||
name: Trev
|
name: Trev
|
||||||
email: spam@trev.xyz
|
email: spam@trev.xyz
|
@ -1,6 +1,6 @@
|
|||||||
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
|
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
|
||||||
version: v2
|
version: v2
|
||||||
modules:
|
modules:
|
||||||
- path: proto
|
- path: .
|
||||||
deps:
|
deps:
|
||||||
- buf.build/bufbuild/protovalidate
|
- buf.build/bufbuild/protovalidate
|
@ -1,16 +0,0 @@
|
|||||||
wipe: true
|
|
||||||
|
|
||||||
replacements:
|
|
||||||
- match:
|
|
||||||
db_type: "INTEGER"
|
|
||||||
replace: "int64"
|
|
||||||
|
|
||||||
- match:
|
|
||||||
db_type: "INTEGER"
|
|
||||||
nullable: true
|
|
||||||
replace: "int64"
|
|
||||||
|
|
||||||
sql:
|
|
||||||
dialect: sqlite
|
|
||||||
dir: db
|
|
||||||
output: internal/models
|
|
@ -29,6 +29,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
name := "TrevStack"
|
||||||
|
|
||||||
// Get env
|
// Get env
|
||||||
env, err := getEnv()
|
env, err := getEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,7 +51,7 @@ func main() {
|
|||||||
|
|
||||||
// Create webauthn
|
// Create webauthn
|
||||||
webAuthn, err := webauthn.New(&webauthn.Config{
|
webAuthn, err := webauthn.New(&webauthn.Config{
|
||||||
RPDisplayName: env.Name,
|
RPDisplayName: name,
|
||||||
RPID: env.URL.Hostname(),
|
RPID: env.URL.Hostname(),
|
||||||
RPOrigins: []string{env.URL.String()},
|
RPOrigins: []string{env.URL.String()},
|
||||||
})
|
})
|
||||||
@ -63,10 +65,10 @@ func main() {
|
|||||||
log.Fatalf("failed to create validator: %s", err.Error())
|
log.Fatalf("failed to create validator: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve GRPC Handlers
|
// Serve gRPC Handlers
|
||||||
api := http.NewServeMux()
|
api := http.NewServeMux()
|
||||||
api.Handle(interceptors.WithCORS(user.NewAuthHandler(vi, sqlc, webAuthn, env.Name, env.Key)))
|
api.Handle(interceptors.WithCORS(user.NewAuthHandler(vi, sqlc, webAuthn, name, env.Key)))
|
||||||
api.Handle(interceptors.WithCORS(user.NewHandler(vi, sqlc, webAuthn, env.Key)))
|
api.Handle(interceptors.WithCORS(user.NewHandler(vi, sqlc, webAuthn, name, env.Key)))
|
||||||
api.Handle(interceptors.WithCORS(item.NewHandler(vi, sqlc, env.Key)))
|
api.Handle(interceptors.WithCORS(item.NewHandler(vi, sqlc, env.Key)))
|
||||||
|
|
||||||
// Serve web interface
|
// Serve web interface
|
||||||
@ -108,7 +110,6 @@ func main() {
|
|||||||
type env struct {
|
type env struct {
|
||||||
Port string
|
Port string
|
||||||
Key string
|
Key string
|
||||||
Name string
|
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
DatabaseURL string
|
DatabaseURL string
|
||||||
}
|
}
|
||||||
@ -123,7 +124,6 @@ func getEnv() (*env, error) {
|
|||||||
env := env{
|
env := env{
|
||||||
Port: os.Getenv("PORT"),
|
Port: os.Getenv("PORT"),
|
||||||
Key: os.Getenv("KEY"),
|
Key: os.Getenv("KEY"),
|
||||||
Name: os.Getenv("NAME"),
|
|
||||||
DatabaseURL: os.Getenv("DATABASE_URL"),
|
DatabaseURL: os.Getenv("DATABASE_URL"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,10 +135,6 @@ func getEnv() (*env, error) {
|
|||||||
if env.Key == "" {
|
if env.Key == "" {
|
||||||
return nil, errors.New("env 'KEY' not found")
|
return nil, errors.New("env 'KEY' not found")
|
||||||
}
|
}
|
||||||
if env.Name == "" {
|
|
||||||
env.Name = "trevstack"
|
|
||||||
log.Printf("env 'NAME' not found, defaulting to %s\n", env.Name)
|
|
||||||
}
|
|
||||||
if env.DatabaseURL == "" {
|
if env.DatabaseURL == "" {
|
||||||
return nil, errors.New("env 'DATABASE_URL' not found")
|
return nil, errors.New("env 'DATABASE_URL' not found")
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ type Handler struct {
|
|||||||
db *sqlc.Queries
|
db *sqlc.Queries
|
||||||
webAuthn *webauthn.WebAuthn
|
webAuthn *webauthn.WebAuthn
|
||||||
key []byte
|
key []byte
|
||||||
|
name string
|
||||||
|
|
||||||
sessions *map[int64]*webauthn.SessionData
|
sessions *map[int64]*webauthn.SessionData
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
@ -132,7 +133,7 @@ func (h *Handler) GetAPIKey(ctx context.Context, req *connect.Request[userv1.Get
|
|||||||
|
|
||||||
// Generate JWT
|
// Generate JWT
|
||||||
t := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.RegisteredClaims{
|
t := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.RegisteredClaims{
|
||||||
Issuer: "trevstack",
|
Issuer: h.name,
|
||||||
Subject: strconv.FormatInt(user.ID, 10),
|
Subject: strconv.FormatInt(user.ID, 10),
|
||||||
IssuedAt: &jwt.NumericDate{
|
IssuedAt: &jwt.NumericDate{
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
@ -341,8 +342,8 @@ func transportsToString(transports []protocol.AuthenticatorTransport) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(vi *validate.Interceptor, db *sqlc.Queries, webauth *webauthn.WebAuthn, key string) (string, http.Handler) {
|
func NewHandler(vi *validate.Interceptor, db *sqlc.Queries, webauth *webauthn.WebAuthn, name string, key string) (string, http.Handler) {
|
||||||
interceptors := connect.WithInterceptors(interceptors.NewAuthInterceptor(key), vi)
|
interceptors := connect.WithInterceptors(vi, interceptors.NewAuthInterceptor(key))
|
||||||
|
|
||||||
sd := map[int64]*webauthn.SessionData{}
|
sd := map[int64]*webauthn.SessionData{}
|
||||||
return userv1connect.NewUserServiceHandler(
|
return userv1connect.NewUserServiceHandler(
|
||||||
@ -350,6 +351,7 @@ func NewHandler(vi *validate.Interceptor, db *sqlc.Queries, webauth *webauthn.We
|
|||||||
db: db,
|
db: db,
|
||||||
webAuthn: webauth,
|
webAuthn: webauth,
|
||||||
key: []byte(key),
|
key: []byte(key),
|
||||||
|
name: name,
|
||||||
|
|
||||||
sessions: &sd,
|
sessions: &sd,
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user