Merge branch 'dotenv' into 'main'

Add .env.test, use --env-file flag, remove TEST_DATABASE_URL, remove @std/dotenv

See merge request soapbox-pub/ditto!559
This commit is contained in:
Alex Gleason 2024-10-18 18:39:55 +00:00
commit 68c1b31940
7 changed files with 20 additions and 39 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.env
.env.*
*.cpuprofile
*.swp
deno-test.xml

View file

@ -28,7 +28,7 @@ test:
- postgres:16
variables:
DITTO_NSEC: nsec1zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs4rm7hz
TEST_DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
POSTGRES_HOST_AUTH_METHOD: trust
artifacts:
when: always

View file

@ -1,27 +1,27 @@
{
"version": "1.1.0",
"tasks": {
"start": "deno run -A src/server.ts",
"dev": "deno run -A --watch src/server.ts",
"start": "deno run -A --env-file src/server.ts",
"dev": "deno run -A --env-file --watch src/server.ts",
"hook": "deno run --allow-read --allow-run --allow-write https://deno.land/x/deno_hooks@0.1.1/mod.ts",
"db:export": "deno run -A scripts/db-export.ts",
"db:import": "deno run -A scripts/db-import.ts",
"db:migrate": "deno run -A scripts/db-migrate.ts",
"nostr:pull": "deno run -A scripts/nostr-pull.ts",
"debug": "deno run -A --inspect src/server.ts",
"test": "deno test -A --junit-path=./deno-test.xml",
"db:export": "deno run -A --env-file scripts/db-export.ts",
"db:import": "deno run -A --env-file scripts/db-import.ts",
"db:migrate": "deno run -A --env-file scripts/db-migrate.ts",
"nostr:pull": "deno run -A --env-file scripts/nostr-pull.ts",
"debug": "deno run -A --env-file --inspect src/server.ts",
"test": "deno test -A --env-file=.env.test --junit-path=./deno-test.xml",
"check": "deno check --allow-import src/server.ts",
"nsec": "deno run scripts/nsec.ts",
"admin:event": "deno run -A scripts/admin-event.ts",
"admin:role": "deno run -A scripts/admin-role.ts",
"setup": "deno run -A scripts/setup.ts",
"setup:kind0": "deno run -A scripts/setup-kind0.ts",
"stats:recompute": "deno run -A scripts/stats-recompute.ts",
"admin:event": "deno run -A --env-file scripts/admin-event.ts",
"admin:role": "deno run -A --env-file scripts/admin-role.ts",
"setup": "deno run -A --env-file scripts/setup.ts",
"setup:kind0": "deno run -A --env-file scripts/setup-kind0.ts",
"stats:recompute": "deno run -A --env-file scripts/stats-recompute.ts",
"soapbox": "curl -O https://dl.soapbox.pub/main/soapbox.zip && mkdir -p public && mv soapbox.zip public/ && cd public/ && unzip -o soapbox.zip && rm soapbox.zip",
"trends": "deno run -A scripts/trends.ts",
"trends": "deno run -A --env-file scripts/trends.ts",
"clean:deps": "deno cache --reload src/app.ts",
"db:populate-search": "deno run -A scripts/db-populate-search.ts",
"vapid": "deno run -A scripts/vapid.ts"
"db:populate-search": "deno run -A --env-file scripts/db-populate-search.ts",
"vapid": "deno run scripts/vapid.ts"
},
"unstable": [
"cron",
@ -54,7 +54,6 @@
"@std/assert": "jsr:@std/assert@^0.225.1",
"@std/cli": "jsr:@std/cli@^0.223.0",
"@std/crypto": "jsr:@std/crypto@^0.224.0",
"@std/dotenv": "jsr:@std/dotenv@^0.224.0",
"@std/encoding": "jsr:@std/encoding@^0.224.0",
"@std/fs": "jsr:@std/fs@^0.229.3",
"@std/json": "jsr:@std/json@^0.223.0",

5
deno.lock generated
View file

@ -59,7 +59,6 @@
"jsr:@std/bytes@^1.0.2-rc.3": "1.0.2",
"jsr:@std/cli@0.223": "0.223.0",
"jsr:@std/crypto@0.224": "0.224.0",
"jsr:@std/dotenv@0.224": "0.224.2",
"jsr:@std/encoding@0.213.1": "0.213.1",
"jsr:@std/encoding@0.224": "0.224.3",
"jsr:@std/encoding@0.224.0": "0.224.0",
@ -527,9 +526,6 @@
"@std/dotenv@0.224.0": {
"integrity": "d9234cdf551507dcda60abb6c474289843741d8c07ee8ce540c60f5c1b220a1d"
},
"@std/dotenv@0.224.2": {
"integrity": "29081695357e4534696c9e986b2560be29c141ccf52daa32b6c20ff5b5c64ab9"
},
"@std/encoding@0.213.1": {
"integrity": "fcbb6928713dde941a18ca5db88ca1544d0755ec8fb20fe61e2dc8144b390c62"
},
@ -2101,7 +2097,6 @@
"jsr:@std/assert@~0.225.1",
"jsr:@std/cli@0.223",
"jsr:@std/crypto@0.224",
"jsr:@std/dotenv@0.224",
"jsr:@std/encoding@0.224",
"jsr:@std/fs@~0.229.3",
"jsr:@std/json@0.223",

View file

@ -1,5 +1,4 @@
import { z } from 'zod';
import '@/config.ts';
import {
updateTrendingEvents,

View file

@ -1,6 +1,5 @@
import os from 'node:os';
import ISO6391, { LanguageCode } from 'iso-639-1';
import * as dotenv from '@std/dotenv';
import { getPublicKey, nip19 } from 'nostr-tools';
import { z } from 'zod';
import { decodeBase64 } from '@std/encoding/base64';
@ -8,13 +7,6 @@ import { encodeBase64Url } from '@std/encoding/base64url';
import { getEcdsaPublicKey } from '@/utils/crypto.ts';
/** Load environment config from `.env` */
await dotenv.load({
export: true,
defaultsPath: null,
examplePath: null,
});
/** Application-wide configuration. */
class Conf {
private static _pubkey: string | undefined;
@ -78,10 +70,6 @@ class Conf {
static get databaseUrl(): string {
return Deno.env.get('DATABASE_URL') ?? 'file://data/pgdata';
}
/** Database to use in tests. */
static get testDatabaseUrl(): string {
return Deno.env.get('TEST_DATABASE_URL') ?? 'memory://';
}
/** PGlite debug level. 0 disables logging. */
static get pgliteDebug(): 0 | 1 | 2 | 3 | 4 | 5 {
return Number(Deno.env.get('PGLITE_DEBUG') || 0) as 0 | 1 | 2 | 3 | 4 | 5;

View file

@ -34,10 +34,9 @@ export function genEvent(t: Partial<NostrEvent> = {}, sk: Uint8Array = generateS
return purifyEvent(event);
}
/** Create a database for testing. It uses `TEST_DATABASE_URL`, or creates an in-memory database by default. */
/** Create a database for testing. It uses `DATABASE_URL`, or creates an in-memory database by default. */
export async function createTestDB(opts?: { pure?: boolean }) {
const { testDatabaseUrl } = Conf;
const { kysely } = DittoDB.create(testDatabaseUrl, { poolSize: 1 });
const { kysely } = DittoDB.create(Conf.databaseUrl, { poolSize: 1 });
await DittoDB.migrate(kysely);