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
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
DATABASE_PATH="/absolute/path/"
DATABASE_NAME="aftermath.db"
DATABASE_URL="postgresql://aftermath:password@0.0.0.0:5432/aftermath-local?sslmode=disable"
DATABASE_NAME="aftermath-local"
DATABASE_USER="aftermath"
DATABASE_PASSWORD="password"

# Init
INIT_GLOBAL_ADMIN_USER="" # Discord user ID for a user who will be assigned permissions.GlobalAdmin on startup, can be left blank
Expand Down
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Download localizations
FROM node:23 AS builder-node
# # Download localizations
# FROM node:23 AS builder-node

ARG LOCALIZE_API_KEY
ENV LOCALIZE_API_KEY $LOCALIZE_API_KEY
# ARG LOCALIZE_API_KEY
# ENV LOCALIZE_API_KEY $LOCALIZE_API_KEY

WORKDIR /workspace
# WORKDIR /workspace

RUN npm install @tolgee/cli
# RUN npm install @tolgee/cli

COPY ./.tolgeerc ./
# COPY ./.tolgeerc ./

RUN npx tolgee pull --api-key "${LOCALIZE_API_KEY}" --states REVIEWED
# RUN npx tolgee pull --api-key "${LOCALIZE_API_KEY}" --states REVIEWED

# Build app
FROM golang:1.24.3 AS builder-go

ARG BRAND_FLAVOR=red
ENV BRAND_FLAVOR $BRAND_FLAVOR

Check warning on line 19 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-amd64-image

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

WORKDIR /workspace

Expand All @@ -26,14 +26,14 @@
COPY ./ ./

# load localizations
COPY --from=builder-node /workspace/static/localization/ ./static/localization/
# COPY --from=builder-node /workspace/static/localization/ ./static/localization/

# generate static assets
RUN --mount=type=cache,target=$GOPATH/pkg/mod go generate ./internal/assets
RUN --mount=type=cache,target=$GOPATH/pkg/mod go generate ./cmd/frontend/assets/generate

# generate frontend
RUN go tool templ generate
RUN --mount=type=cache,target=$GOPATH/pkg/mod go tool templ generate

# build a fully standalone binary with zero dependencies
RUN --mount=type=cache,target=$GOPATH/pkg/mod CGO_ENABLED=0 GOOS=linux go build -ldflags='-s -w' -trimpath -o /bin/aftermath .
Expand Down
4 changes: 2 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ tasks:
- ".env.test"
desc: runs tests
cmds:
# - task: db-migrate-apply-test
- task: db-migrate-tests
- |
if [ -z "{{ .CLI_ARGS }}" ]; then
go test -timeout 30s --count=1 -v ./...
go test -timeout 30s --count=1 -v ./... | grep -v "\[no test files\]"
else
go test -timeout 30s --count=1 -v -run {{ .CLI_ARGS }}
fi
Expand Down
20 changes: 4 additions & 16 deletions atlas.hcl
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
variable "database_name" {
variable "database_url" {
type = string
default = getenv("DATABASE_NAME")
}
variable "database_user" {
type = string
default = getenv("DATABASE_USER")
}
variable "database_password" {
type = string
default = getenv("DATABASE_PASSWORD")
}
variable "database_host" {
type = string
default = getenv("DATABASE_HOST")
default = getenv("DATABASE_URL")
}
variable "sources" {
type = list(string)
Expand All @@ -35,7 +23,7 @@ env "local" {
dir = "file://internal/database/migrations"
}

url = "postgresql://${var.database_user}:${var.database_password}@${var.database_host}/${var.database_name}?sslmode=disable"
url = var.database_url
dev = "docker://postgres/17/dev?search_path=public"
}

Expand All @@ -55,5 +43,5 @@ env "migrate" {
}
tx-mode = "all"

url = "postgresql://${var.database_user}:${var.database_password}@${var.database_host}/${var.database_name}?sslmode=disable"
url = var.database_url
}
12 changes: 3 additions & 9 deletions cmd/core/scheduler/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,12 @@ func UpdateAveragesWorker(client core.Client) func() {
return
}

aErr, err := client.Database().UpsertVehicleAverages(ctx, averages)
err = client.Database().UpsertVehicleAverages(ctx, averages)
if err != nil {
log.Err(err).Msg("failed to update averages cache")
return
}

for id, err := range aErr {
if err != nil {
log.Err(err).Str("", id).Msg("failed to update some average cache")
}
}

log.Info().Msg("averages cache updated")
}
}
Expand Down Expand Up @@ -148,7 +142,7 @@ func UpdateGlossaryWorker(client core.Client) func() {
vctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()

_, err = client.Database().UpsertVehicles(vctx, vehicles)
err = client.Database().UpsertVehicles(vctx, vehicles)
if err != nil {
log.Err(err).Msg("failed to save vehicle glossary")
return
Expand Down Expand Up @@ -208,7 +202,7 @@ func UpdateGlossaryWorker(client core.Client) func() {
gmctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

_, err = client.Database().UpsertGameModes(gmctx, withTags)
err = client.Database().UpsertGameModes(gmctx, withTags)
if err != nil {
log.Err(err).Msg("failed save game modes glossary")
return
Expand Down
19 changes: 1 addition & 18 deletions cmd/core/server/handlers/private/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ func LoadAccountsHandler(client core.Client) http.HandlerFunc {
batchSize := 50
var wg sync.WaitGroup
sem := semaphore.NewWeighted(5)
errors := make(map[string]error)
var errorsMx sync.Mutex

for realm, accounts := range accountsByRealm {
for i := 0; i < len(accounts); i += batchSize {
end := i + batchSize
Expand Down Expand Up @@ -113,29 +110,15 @@ func LoadAccountsHandler(client core.Client) http.HandlerFunc {
inserts = append(inserts, &update)
}

accErr, err := client.Database().UpsertAccounts(ctx, inserts...)
err = client.Database().UpsertAccounts(ctx, inserts...)
if err != nil {
log.Err(err).Msg("failed to upsert accounts")
}
if len(accErr) > 0 {
errorsMx.Lock()
for id, err := range accErr {
errors[id] = err
}
errorsMx.Unlock()
}

}(accounts[i:end], realm)
}
}
wg.Wait()

for id, err := range errors {
if err != nil {
log.Err(err).Str("id", id).Msg("some account imports failed")
}
}

log.Debug().Int("count", len(accounts)-len(existing)).Msg("finished importing accounts")
}(accounts, existing)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/frontend/handler/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (ws WebSocket) Serve(ctx *Context) error {

conn, err := u.Upgrade(ctx.w, ctx.r, nil)
if err != nil {
return ctx.String(err.Error())
return ctx.String("%v", err)
}
return handler(conn)
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
build:
context: .
dockerfile: Dockerfile.migrate
command: migrate apply --dir "file:///migrations" --tx-mode all --url "postgresql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?sslmode=disable"
command: migrate apply --dir "file:///migrations" --tx-mode all --url "${DATABASE_URL}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
Expand Down
15 changes: 10 additions & 5 deletions docker-compose.dokploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
restart: no
environment:
- COLLECTOR_BACKEND_URL=backend-${ENVIRONMENT}:${PRIVATE_SERVER_PORT}
- DATABASE_HOST=database-${ENVIRONMENT}:5432
- DATABASE_URL=${DATABASE_URL}
networks:
dokploy-network:
aliases:
Expand All @@ -28,7 +28,7 @@ services:
file: docker-compose.base.yaml
service: aftermath-migrate-base
environment:
- DATABASE_HOST=database-${ENVIRONMENT}:5432
- DATABASE_URL=${DATABASE_URL}
depends_on:
database:
condition: service_healthy
Expand All @@ -41,11 +41,16 @@ services:
extends:
file: docker-compose.base.yaml
service: aftermath-backup-base
restart: no
restart: always
entrypoint: ["/bin/sh", "-c", "sleep infinity"]
labels:
ofelia.enabled: "true"
ofelia.job-exec.backup-run.schedule: "@daily"
ofelia.job-exec.backup-run.command: "/backup.sh"
environment:
# relations will not be scanned when making a backup
- TARGET_TABLES=account,clan,app_configuration,application_command,user,user_connection,user_subscription,user_content,user_restriction,moderation_request,widget_settings
- DATABASE_URL=postgresql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?sslmode=disable
- DATABASE_URL=${DATABASE_URL}
- S3_BUCKET=${DATABASE_BACKUP_S3_BUCKET}
- ENDPOINT_URL=${DATABASE_BACKUP_ENDPOINT_URL}
- AWS_ACCESS_KEY_ID=${DATABASE_BACKUP_AWS_ACCESS_KEY_ID}
Expand All @@ -68,7 +73,7 @@ services:
environment:
# the rest is imported from .env, which is going to be created by Dokploy automatically
- PORT=3000 # the port does not matter, but it needs to match Traefik labels. we set it here explicitly in order to avoid any issues
- DATABASE_HOST=database-${ENVIRONMENT}:5432
- DATABASE_URL=${DATABASE_URL}
depends_on:
migrate:
condition: service_completed_successfully
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ go 1.24.3

require github.com/go-jet/jet/v2 v2.13.0

// replace github.com/cufee/facepaint => ../facepaint

require (
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9
github.com/PuerkitoBio/goquery v1.10.3
Expand Down
2 changes: 1 addition & 1 deletion internal/assets/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func generateDiscordHelpImage(printer func(string) string) {
dctx.Fill()

fontSize := 20.0
commands := []string{"help", "links", "stats", "session"}
commands := []string{"help", "links", "career", "session"}
for i, name := range commands {
drawY := float64((padding + int(fontSize)) + i*(int(fontSize*2)+padding))
dctx.SetColor(color.White)
Expand Down
4 changes: 1 addition & 3 deletions internal/constants/database.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package constants

import "fmt"

var (
DatabaseConnString = fmt.Sprintf("postgresql://%s:%s@%s/%s?sslmode=disable", MustGetEnv("DATABASE_USER"), MustGetEnv("DATABASE_PASSWORD"), MustGetEnv("DATABASE_HOST"), MustGetEnv("DATABASE_NAME"))
DatabaseConnString = MustGetEnv("DATABASE_URL")
)
9 changes: 4 additions & 5 deletions internal/database/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ func (c *client) GetAccounts(ctx context.Context, ids []string) ([]models.Accoun
return accounts, nil
}

func (c *client) UpsertAccounts(ctx context.Context, accounts ...*models.Account) (map[string]error, error) {
func (c *client) UpsertAccounts(ctx context.Context, accounts ...*models.Account) error {
if len(accounts) < 1 {
return nil, nil
return nil
}

errors := make(map[string]error)
return errors, c.withTx(ctx, func(tx *transaction) error {
return c.withTx(ctx, func(tx *transaction) error {
for _, a := range accounts {
stmt := t.Account.
INSERT(t.Account.AllColumns).
Expand All @@ -96,7 +95,7 @@ func (c *client) UpsertAccounts(ctx context.Context, accounts ...*models.Account
)
_, err := tx.exec(ctx, stmt)
if err != nil {
errors[a.ID] = err
return err
}
}
return nil
Expand Down
23 changes: 4 additions & 19 deletions internal/database/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAccounts(t *testing.T) {
t.Run("upsert and check a new account", func(t *testing.T) {
is := is.New(t)

errors, err := client.UpsertAccounts(context.Background(), &models.Account{
err := client.UpsertAccounts(context.Background(), &models.Account{
ID: "id-1",
Realm: "realm",
Nickname: "nickname-1",
Expand All @@ -26,15 +26,12 @@ func TestAccounts(t *testing.T) {
LastBattleTime: time.Now(),
})
is.NoErr(err)
for _, err := range errors {
is.NoErr(err)
}

account, err := client.GetAccountByID(context.Background(), "id-1")
is.NoErr(err)
is.True(account.Nickname == "nickname-1")

errors, err = client.UpsertAccounts(context.Background(), &models.Account{
err = client.UpsertAccounts(context.Background(), &models.Account{
ID: "id-1",
Realm: "realm",
Nickname: "nickname-2",
Expand All @@ -44,9 +41,6 @@ func TestAccounts(t *testing.T) {
LastBattleTime: time.Now(),
})
is.NoErr(err)
for _, err := range errors {
is.NoErr(err)
}

account, err = client.GetAccountByID(context.Background(), "id-1")
is.NoErr(err)
Expand All @@ -56,7 +50,7 @@ func TestAccounts(t *testing.T) {
t.Run("get multiple accounts", func(t *testing.T) {
is := is.New(t)

errors, err := client.UpsertAccounts(context.Background(),
err := client.UpsertAccounts(context.Background(),
&models.Account{
ID: "id-21",
Realm: "realm",
Expand All @@ -76,9 +70,6 @@ func TestAccounts(t *testing.T) {
LastBattleTime: time.Now(),
})
is.NoErr(err)
for _, err := range errors {
is.NoErr(err)
}

accounts, err := client.GetAccounts(context.Background(), []string{"id-21", "id-22"})
is.NoErr(err)
Expand All @@ -91,7 +82,7 @@ func TestAccounts(t *testing.T) {
t.Run("set account to private", func(t *testing.T) {
is := is.New(t)

errors, err := client.UpsertAccounts(context.Background(), &models.Account{
err := client.UpsertAccounts(context.Background(), &models.Account{
ID: "id-10",
Realm: "realm",
Nickname: "nickname-10",
Expand All @@ -101,19 +92,13 @@ func TestAccounts(t *testing.T) {
LastBattleTime: time.Now(),
})
is.NoErr(err)
for _, err := range errors {
is.NoErr(err)
}

account, err := client.GetAccountByID(context.Background(), "id-10")
is.NoErr(err)
is.True(!account.Private)

err = client.AccountSetPrivate(context.Background(), "id-10", true)
is.NoErr(err)
for _, err := range errors {
is.NoErr(err)
}

account, err = client.GetAccountByID(context.Background(), "id-10")
is.NoErr(err)
Expand Down
Loading