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
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
.svelte-kit
build
.git
.gitignore
.env
.env.*
.vscode
.idea
Dockerfile
.dockerignore
.prettierrc
.prettierignore
pnpm-lock.yaml
pnpm-workspace.yaml
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build Docker image

on:
push:
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
docker:
name: Build and push Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/geode-sdk/website
tags: |
# use 'latest' for main branch, and use branch name for other branches
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }}

- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Build and push
uses: docker/build-push-action@v7
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max,compression=zstd,compression-level=12
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# build the app first
FROM node:26-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json .npmrc ./
RUN npm ci
COPY . .
RUN npm run build

# build only deps needed for runtime, that will be copied to final stage
FROM node:26-alpine AS prod-deps
WORKDIR /app
COPY package.json package-lock.json .npmrc ./
RUN npm ci --omit=dev && npm cache clean --force

# runner stage
FROM node:26-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production HOST=0.0.0.0 PORT=3000
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=builder /app/build ./build
COPY package.json .

USER node
EXPOSE 3000
CMD ["node", "build"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can preview the production build with `npm run preview`.

## Configuration

The site uses the following (optional) static environment variables:
The site uses the following (optional) dynamic environment variables:

- `PUBLIC_API_ENDPOINT`: Base API endpoint for all requests. Current default is "https://api.geode-sdk.org".

Expand Down
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HandleFetch } from "@sveltejs/kit";
import * as publicEnv from "$env/static/public";
import * as privateEnv from "$env/static/private";
import { env as publicEnv } from "$env/dynamic/public";
import { env as privateEnv } from "$env/dynamic/private";

interface PrivateSchema {
PRIVATE_ENDPOINT_ENABLED: string;
Expand Down Expand Up @@ -39,10 +39,10 @@ function checkPublic(obj: unknown): obj is PublicSchema {
return true;
}

const validPrivate = checkPrivate(privateEnv) ? privateEnv : null;
const validPublic = checkPublic(publicEnv) ? publicEnv : null;

export const handleFetch: HandleFetch = async ({ request, fetch }) => {
const validPrivate = checkPrivate(privateEnv) ? privateEnv : null;
const validPublic = checkPublic(publicEnv) ? publicEnv : null;

if (!validPrivate || !validPublic) {
return fetch(request);
}
Expand Down
7 changes: 2 additions & 5 deletions src/lib/api/index-repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as publicEnv from "$env/static/public";
import { env as publicEnv } from "$env/dynamic/public";

import type { ServerDeveloper, ServerDeveloperProfile, ServerTag } from "./models/base";
import type { ServerMod, ServerModDeprecation, ServerSimpleMod } from "./models/mod.js";
Expand All @@ -14,10 +14,7 @@ import type { ServerStats } from "./models/stats";
import type { Cookies } from "@sveltejs/kit";
import { setCookieTokens } from "$lib/api/tokens";

const BASE_URL =
"PUBLIC_API_ENDPOINT" in publicEnv && typeof publicEnv.PUBLIC_API_ENDPOINT == "string"
? publicEnv.PUBLIC_API_ENDPOINT
: "https://api.geode-sdk.org";
const BASE_URL = publicEnv.PUBLIC_API_ENDPOINT || "https://api.geode-sdk.org";

export interface Paginated<T> {
data: T[];
Expand Down
7 changes: 2 additions & 5 deletions src/lib/server/redis.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as privateEnv from "$env/static/private";
import { env as privateEnv } from "$env/dynamic/private";
import { createClient } from "redis";

const redisUrl =
"PRIVATE_REDIS_URL" in privateEnv && typeof privateEnv.PRIVATE_REDIS_URL == "string"
? privateEnv.PRIVATE_REDIS_URL
: null;
const redisUrl = privateEnv.PRIVATE_REDIS_URL || null;

export const redis = redisUrl ? createClient({ url: redisUrl }) : null;

Expand Down
6 changes: 2 additions & 4 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import { onMount } from "svelte";
import type { LayoutData } from "./$types";
import { setUserContext } from "$lib/context/user";
import { env as publicEnv } from "$env/dynamic/public";

interface Props {
data: LayoutData;
Expand All @@ -21,10 +22,7 @@
let { data, children, nav }: Props = $props();

setUserContext(() => data.loggedInUser);
import * as publicEnv from "$env/static/public";
const GID = "PUBLIC_GTAG_ID" in publicEnv && typeof publicEnv.PUBLIC_GTAG_ID == "string"
? publicEnv.PUBLIC_GTAG_ID
: "";
const GID = publicEnv.PUBLIC_GTAG_ID ?? "";

if (GID !== "") {
onMount(() => {
Expand Down
Loading