Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ jobs:
- name: setup golang
uses: actions/setup-go@v5
with:
go-version: '^1.23.4'
- name: install task
uses: arduino/setup-task@v2
go-version: '^1.24.0'
- name: Set up gotestfmt
uses: gotesttools/gotestfmt-action@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: test backend
run: task backend-test
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
run: |
set -euo pipefail
go test -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Upload test log
uses: actions/upload-artifact@v4
if: always()
with:
name: test-log
path: /tmp/gotest.log
if-no-files-found: error
linter:
runs-on: ubuntu-22.04
permissions:
Expand All @@ -38,10 +46,7 @@ jobs:
- name: setup golang
uses: actions/setup-go@v5
with:
go-version: '^1.23.4'
- name: lint backend
go-version: '^1.24.0'
- name: run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
working-directory: backend

17 changes: 2 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
## Backend
HELP.md
backend/kayvault.json
backend/key.file
backend/config.yaml
config.yaml
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
Expand Down Expand Up @@ -40,12 +35,6 @@ out/
### VS Code ###
.vscode/

### FIREBASE ###
backend/kayvault.json

### OKTETO LOGIN TOKEN ###
dockersecret

## FRONTEND
.DS_Store
frontend/node_modules
Expand All @@ -59,6 +48,4 @@ frontend/vite.config.js.timestamp-*
frontend/vite.config.ts.timestamp-*
**/.firebase
**/.firebaserc
frontend/build

**/kayvault.json
static
10 changes: 0 additions & 10 deletions .run/run backend.run.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .run/run frontend.run.xml

This file was deleted.

31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:22-alpine AS frontend-builder

WORKDIR /opt/kayvault-frontend

COPY frontend/package*.json .

RUN ["npm", "ci"]

COPY frontend .

RUN ["npm", "run", "build"]
RUN ["npm", "prune", "--production"]

FROM golang:1.24.0 AS builder

WORKDIR /opt/kayvault

COPY go.mod go.sum ./
COPY backend backend
COPY cmd cmd
COPY sql sql

RUN CGO_ENABLED=0 go build -o bin/kayvault cmd/main.go

FROM alpine:3.21.2 AS runner

COPY --from=frontend-builder /opt/kayvault-frontend/build static
COPY --from=builder /opt/kayvault/bin/kayvault kayvault
COPY sql/migrations sql/migrations

CMD ["./kayvault"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ https://kayvault.torfstack.com
<img src="/dark.png" width="200" />
<img src="/light.png" width="200" height="412" />
</p>

31 changes: 12 additions & 19 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,31 @@ vars:
sh: git tag --sort=-creatordate | head -n 1

tasks:
backend-test:
dir: backend
test:
cmds:
- cmd: go test ./...
backend-release:
dir: backend
requires:
vars: [IMAGE_TAG]
- cmd: set -euo pipefail && go test -json -v ./... 2>&1 | gotestfmt
start-local:
cmds:
- cmd: docker buildx build -t ghcr.io/torfstack/kayvault-backend:{{.IMAGE_TAG}} .
- cmd: docker push ghcr.io/torfstack/kayvault-backend:{{.IMAGE_TAG}}
frontend-release:
dir: frontend
- cmd: npm run --prefix frontend build
- cmd: mv frontend/build/ static/
- cmd: go build -o bin/kayvault cmd/main.go
- cmd: ./bin/kayvault
release:
requires:
vars: [IMAGE_TAG]
cmds:
- cmd: docker buildx build -t ghcr.io/torfstack/kayvault-frontend:{{.IMAGE_TAG}} .
- cmd: docker push ghcr.io/torfstack/kayvault-frontend:{{.IMAGE_TAG}}
- cmd: docker buildx build -t ghcr.io/torfstack/kayvault:{{.IMAGE_TAG}} .
- cmd: docker push ghcr.io/torfstack/kayvault:{{.IMAGE_TAG}}
deploy:
requires:
vars: [VERSION_TO_DEPLOY]
cmds:
- cmd: helm upgrade --install kayvault deployment --set backend.tag={{.VERSION_TO_DEPLOY}} --set frontend.tag={{.VERSION_TO_DEPLOY}}
- cmd: helm upgrade --install kayvault deployment --set tag={{.VERSION_TO_DEPLOY}}
dev-deploy:
vars:
DEV_IMAGE_TAG: development
cmds:
- task: backend-release
vars:
IMAGE_TAG:
ref: .DEV_IMAGE_TAG
- task: frontend-release
- task: release
vars:
IMAGE_TAG:
ref: .DEV_IMAGE_TAG
Expand Down
17 changes: 0 additions & 17 deletions backend/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions backend/README.md

This file was deleted.

36 changes: 36 additions & 0 deletions backend/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package backend

import (
"context"
"fmt"

"github.com/torfstack/kayvault/backend/config"
"github.com/torfstack/kayvault/backend/db"
"github.com/torfstack/kayvault/backend/domain"
"github.com/torfstack/kayvault/backend/http"
)

type Application struct {
}

func NewApplication() *Application {
return &Application{}
}

func (a *Application) Run() error {
cfg, err := config.ParseFile("config.yaml")
if err != nil {
return fmt.Errorf("could not parse config at './config.yaml': %v", err)
}

err = db.Migrate(context.Background(), cfg.DB.ConnectionString())
if err != nil {
return fmt.Errorf("could not migrate database: %v", err)
}

database := db.NewDatabase(cfg.DB.ConnectionString())
domainService := domain.NewDomainService(database)
server := http.NewServer(*cfg, domainService)

return server.Start()
}
3 changes: 0 additions & 3 deletions backend/buildLocal

This file was deleted.

22 changes: 0 additions & 22 deletions backend/cmd/main.go

This file was deleted.

11 changes: 0 additions & 11 deletions backend/config.yaml.tpl

This file was deleted.

22 changes: 17 additions & 5 deletions backend/internal/config/config.go → backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,36 @@ type DBConfig struct {
}

func (dbCfg DBConfig) ConnectionString() string {
return fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", dbCfg.Host, dbCfg.Port, dbCfg.User, dbCfg.Password, dbCfg.DBName)
return fmt.Sprintf(
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
dbCfg.Host,
dbCfg.Port,
dbCfg.User,
dbCfg.Password,
dbCfg.DBName,
)
}

type AuthConfig struct {
Issuer string `yaml:"issuer" validate:"required"`
ClientID string `yaml:"clientId" validate:"required"`
ClientSecret string `yaml:"clientSecret" validate:"required"`
RedirectURL string `yaml:"redirectUrl" validate:"required"`
BaseURL string `yaml:"baseUrl" validate:"required"`
}

type ServerConfig struct {
Port int `yaml:"port" validate:"required"`
BaseURL string `yaml:"baseUrl" validate:"required"`
}

type Config struct {
DB DBConfig `yaml:"db" validate:"required"`
Auth AuthConfig `yaml:"auth" validate:"required"`
DB DBConfig `yaml:"db" validate:"required"`
Auth AuthConfig `yaml:"auth" validate:"required"`
Server ServerConfig `yaml:"server" validate:"required"`
}

func ParseFile(path string) (*Config, error) {
viper.AddConfigPath(".")
viper.SetConfigFile(path)

var cfg Config
if err := viper.ReadInConfig(); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fromdb

import (
"github.com/torfstack/kayvault/internal/models"
sqlc "github.com/torfstack/kayvault/sql/gen"
"strings"

"github.com/torfstack/kayvault/backend/models"
sqlc "github.com/torfstack/kayvault/sql/gen"
)

func Secret(in sqlc.Secret) models.Secret {
Expand All @@ -27,7 +28,9 @@ func Secrets(in []sqlc.Secret) []models.Secret {
func User(in sqlc.User) models.User {
return models.User{
ID: in.ID,
Username: in.Username,
Subject: in.Subject,
Email: in.Email,
FullName: in.FullName,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package todb

import (
"github.com/torfstack/kayvault/internal/models"
"github.com/torfstack/kayvault/backend/models"
sqlc "github.com/torfstack/kayvault/sql/gen"
)

Expand Down Expand Up @@ -36,6 +36,14 @@ func UpdateSecretParams(in models.Secret, userID int32) sqlc.UpdateSecretParams
}
}

func InsertUserParams(in models.User) sqlc.InsertUserParams {
return sqlc.InsertUserParams{
Subject: in.Subject,
Email: in.Email,
FullName: in.FullName,
}
}

func tagsString(tags []string) string {
t := ""
for _, tag := range tags {
Expand Down
Loading