Compare commits

...

6 Commits

Author SHA1 Message Date
Henry
5dfb6427eb Update error code 2025-06-04 07:33:37 +01:00
Henry
6b861b6875 fix: bypass custom URL checkout for self hosted 2025-06-04 07:19:25 +01:00
Henry
348d81a705 fix: use PAT instead of github token 2025-06-03 22:44:53 +01:00
Henry
cef670dc11 fix: update build context to root 2025-06-03 21:48:17 +01:00
Henry
23ae7a375b feat: add docker-publish.yml 2025-06-03 21:35:51 +01:00
Henry
0b06f80181 feat: remove NEXT_PUBLIC env vars from docker build args (#13)
* feat: add next public envs to runtime

* Commit env vars
2025-06-03 21:25:57 +01:00
22 changed files with 166 additions and 37 deletions

View File

@@ -1,5 +1,7 @@
.env
docker-compose.override.yml
Dockerfile
./**/*/Dockerfile

97
.github/workflows/docker-publish.yml vendored Normal file
View File

@@ -0,0 +1,97 @@
name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
schedule:
- cron: "21 21 * * *"
push:
branches: ["main"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["main"]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
with:
cosign-release: "v2.2.4"
# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.KAN_PAT }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: apps/web/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

3
.gitignore vendored
View File

@@ -43,3 +43,6 @@ dist/
# turbo
.turbo
# docker
docker-compose.override.yml

View File

@@ -42,13 +42,6 @@ ENV CI=true
WORKDIR /app
ARG NEXT_PUBLIC_KAN_ENV=${NEXT_PUBLIC_KAN_ENV}
ARG NEXT_PUBLIC_UMAMI_ID=${NEXT_PUBLIC_UMAMI_ID}
ARG NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL}
ARG NEXT_PUBLIC_STORAGE_URL=${NEXT_PUBLIC_STORAGE_URL}
ARG NEXT_PUBLIC_STORAGE_DOMAIN=${NEXT_PUBLIC_STORAGE_DOMAIN}
ARG NEXT_PUBLIC_AVATAR_BUCKET_NAME=${NEXT_PUBLIC_AVATAR_BUCKET_NAME}
# Copy lockfile and package.json's of isolated subworkspace
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml

View File

@@ -1,9 +1,13 @@
import { fileURLToPath } from "url";
import createJiti from "jiti";
import { env } from "next-runtime-env";
import { configureRuntimeEnv } from "next-runtime-env/build/configure.js";
// Import env files to validate at build time. Use jiti so we can load .ts files in here.
createJiti(fileURLToPath(import.meta.url))("./src/env");
configureRuntimeEnv();
/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: true,
@@ -22,7 +26,7 @@ const config = {
typescript: { ignoreBuildErrors: true },
images: {
domains: [process.env.NEXT_PUBLIC_STORAGE_DOMAIN ?? ""],
domains: [env("NEXT_PUBLIC_STORAGE_DOMAIN") ?? ""],
},
experimental: {
instrumentationHook: true,

View File

@@ -35,6 +35,7 @@
"jwt-decode": "^4.0.0",
"next": "^14.2.15",
"next-logger": "^5.0.1",
"next-runtime-env": "^1.7.2",
"nextjs-cors": "^2.2.0",
"pino": "^9.6.0",
"react": "catalog:react18",

1
apps/web/public/__ENV.js Normal file
View File

@@ -0,0 +1 @@
window.__ENV = {"NEXT_PUBLIC_UMAMI_ID":"aaed1f55-25e2-4223-b918-e429c390be35","NEXT_PUBLIC_KAN_ENV":"cloud","NEXT_PUBLIC_BASE_URL":"http://localhost:3000","NEXT_PUBLIC_AVATAR_BUCKET_NAME":"avatars","NEXT_PUBLIC_STORAGE_DOMAIN":"storage.kanbn.com","NEXT_PUBLIC_STORAGE_URL":"https://storage.kanbn.com"};

View File

@@ -2,8 +2,8 @@ import "~/styles/globals.css";
import type { AppType } from "next/app";
import { Plus_Jakarta_Sans } from "next/font/google";
import { env } from "next-runtime-env";
import { env } from "~/env";
import { ModalProvider } from "~/providers/modal";
import { PopupProvider } from "~/providers/popup";
import { ThemeProvider } from "~/providers/theme";
@@ -31,13 +31,14 @@ const MyApp: AppType = ({ Component, pageProps }) => {
position: relative;
}
`}</style>
{env.NEXT_PUBLIC_UMAMI_ID && (
{env("NEXT_PUBLIC_UMAMI_ID") && (
<script
defer
src="https://cloud.umami.is/script.js"
data-website-id={env.NEXT_PUBLIC_UMAMI_ID}
data-website-id={env("NEXT_PUBLIC_UMAMI_ID")}
/>
)}
<script src="/__ENV.js" />
<main className="font-sans">
<ThemeProvider>
<ModalProvider>

View File

@@ -1,4 +1,5 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { env } from "next-runtime-env";
import { createNextApiContext } from "@kan/api/trpc";
import { createStripeClient } from "@kan/stripe";
@@ -22,7 +23,7 @@ export default async function handler(
const session = await stripe.billingPortal.sessions.create({
customer: user.stripeCustomerId,
return_url: `${process.env.NEXT_PUBLIC_BASE_URL}/settings`,
return_url: `${env("NEXT_PUBLIC_BASE_URL")}/settings`,
});
return res.status(200).json({ url: session.url });

View File

@@ -1,4 +1,5 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { env } from "next-runtime-env";
import { z } from "zod";
import { createNextApiContext } from "@kan/api/trpc";
@@ -73,8 +74,8 @@ export default async function handler(
quantity: 1,
},
],
success_url: `${process.env.NEXT_PUBLIC_BASE_URL}${successUrl}`,
cancel_url: `${process.env.NEXT_PUBLIC_BASE_URL}${cancelUrl}`,
success_url: `${env("NEXT_PUBLIC_BASE_URL")}${successUrl}`,
cancel_url: `${env("NEXT_PUBLIC_BASE_URL")}${cancelUrl}`,
customer: user.stripeCustomerId ?? undefined,
metadata: {
workspaceSlug: slug,

View File

@@ -1,10 +1,9 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { env } from "next-runtime-env";
import { createNextApiContext } from "@kan/api/trpc";
import { env } from "~/env";
const allowedContentTypes = ["image/jpeg", "image/png"];
@@ -55,7 +54,7 @@ export default async function handler(
// @ts-ignore
client,
new PutObjectCommand({
Bucket: process.env.NEXT_PUBLIC_AVATAR_BUCKET_NAME ?? "",
Bucket: env("NEXT_PUBLIC_AVATAR_BUCKET_NAME") ?? "",
Key: filename,
}),
);

View File

@@ -1,4 +1,4 @@
import { env } from "~/env";
import { env } from "next-runtime-env";
export const formatToArray = (
value: string | string[] | undefined,
@@ -46,5 +46,5 @@ export const formatMemberDisplayName = (
};
export const getAvatarUrl = (key: string) => {
return `${env.NEXT_PUBLIC_STORAGE_URL}/${env.NEXT_PUBLIC_AVATAR_BUCKET_NAME}/${key}`;
return `${env("NEXT_PUBLIC_STORAGE_URL")}/${env("NEXT_PUBLIC_AVATAR_BUCKET_NAME")}/${key}`;
};

View File

@@ -1,7 +1,7 @@
import Image from "next/image";
import { env } from "next-runtime-env";
import { useState } from "react";
import { env } from "~/env";
import { usePopup } from "~/providers/popup";
import { api } from "~/utils/api";
import { getAvatarUrl } from "~/utils/helpers";
@@ -62,7 +62,7 @@ export default function Avatar({
setUploading(true);
const response = await fetch(
env.NEXT_PUBLIC_BASE_URL + "/api/upload/image",
env("NEXT_PUBLIC_BASE_URL") + "/api/upload/image",
{
method: "POST",
headers: {

View File

@@ -1,4 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { env } from "next-runtime-env";
import { useForm } from "react-hook-form";
import { HiCheck, HiMiniStar } from "react-icons/hi2";
import { z } from "zod";
@@ -92,7 +93,9 @@ const UpdateWorkspaceUrlForm = ({
const isWorkspaceSlugAvailable = checkWorkspaceSlugAvailability.data;
const onSubmit = (data: FormValues) => {
if (isWorkspaceSlugAvailable?.isAvailable && workspacePlan !== "pro")
if (!isWorkspaceSlugAvailable?.isAvailable) return;
if (workspacePlan !== "pro" && env("NEXT_PUBLIC_KAN_ENV") === "cloud")
return openModal("UPDATE_WORKSPACE_URL", data.slug);
updateWorkspaceSlug.mutate({
@@ -118,7 +121,11 @@ const UpdateWorkspaceUrlForm = ({
? "This workspace username has already been taken"
: undefined)
}
prefix="kan.bn/"
prefix={
env("NEXT_PUBLIC_KAN_ENV") === "cloud"
? "kan.bn/"
: `${env("NEXT_PUBLIC_BASE_URL")}/`
}
iconRight={
isWorkspaceSlugAvailable?.isAvailable ||
(workspacePlan === "pro" && slug === workspaceUrl) ? (

View File

@@ -1,3 +1,4 @@
import { env } from "next-runtime-env";
import { HiMiniArrowTopRightOnSquare } from "react-icons/hi2";
import Button from "~/components/Button";
@@ -95,7 +96,7 @@ export default function SettingsPage() {
/>
</div>
{process.env.NEXT_PUBLIC_KAN_ENV === "cloud" && (
{env("NEXT_PUBLIC_KAN_ENV") === "cloud" && (
<div className="mb-8 border-t border-light-300 dark:border-dark-300">
<h2 className="mb-4 mt-8 text-[14px] text-neutral-900 dark:text-dark-1000">
Billing

View File

@@ -2,6 +2,7 @@ version: "3.7"
services:
web:
image: ghcr.io/kanbn/kan:latest
ports:
- "3001:3000"
networks:
@@ -9,12 +10,6 @@ services:
build:
context: .
dockerfile: ./apps/web/Dockerfile
args:
NEXT_PUBLIC_KAN_ENV: ${NEXT_PUBLIC_KAN_ENV}
NEXT_PUBLIC_UMAMI_ID: ${NEXT_PUBLIC_UMAMI_ID}
NEXT_PUBLIC_BASE_URL: ${NEXT_PUBLIC_BASE_URL}
NEXT_PUBLIC_STORAGE_URL: ${NEXT_PUBLIC_STORAGE_URL}
NEXT_PUBLIC_AVATAR_BUCKET_NAME: ${NEXT_PUBLIC_AVATAR_BUCKET_NAME}
env_file:
- .env
command: ["pnpm", "start"]
@@ -40,7 +35,6 @@ services:
- NEXT_PUBLIC_AVATAR_BUCKET_NAME=${NEXT_PUBLIC_AVATAR_BUCKET_NAME}
- NEXT_PUBLIC_STORAGE_DOMAIN=${NEXT_PUBLIC_STORAGE_DOMAIN}
- NEXT_PUBLIC_UMAMI_ID=${NEXT_PUBLIC_UMAMI_ID}
networks:
dokploy-network:
external: true

View File

@@ -1,3 +1,4 @@
import { env } from "next-runtime-env";
import { generateOpenApiDocument } from "trpc-to-openapi";
import { appRouter } from "./root";
@@ -6,7 +7,7 @@ export const openApiDocument = generateOpenApiDocument(appRouter, {
title: "Kan API",
description: "OpenAPI compliant REST API",
version: "1.0.0",
baseUrl: `${process.env.NEXT_PUBLIC_BASE_URL}/api/v1`,
baseUrl: `${env("NEXT_PUBLIC_BASE_URL")}/api/v1`,
docsUrl: "docs.kan.bn",
tags: ["Auth", "Users", "Boards", "Lists", "Cards", "Labels", "Imports"],
});

View File

@@ -1,4 +1,5 @@
import { TRPCError } from "@trpc/server";
import { env } from "next-runtime-env";
import { z } from "zod";
import * as workspaceRepo from "@kan/db/repository/workspace.repo";
@@ -224,10 +225,19 @@ export const workspaceRouter = createTRPCRouter({
const isWorkspaceSlugAvailable =
await workspaceRepo.isWorkspaceSlugAvailable(ctx.db, input.slug);
if (
env("NEXT_PUBLIC_KAN_ENV") === "cloud" &&
workspace.plan !== "pro" &&
input.slug !== workspace.publicId
) {
throw new TRPCError({
message: `Workspace slug cannot be changed in cloud without upgrading to a paid plan`,
code: "FORBIDDEN",
});
}
if (
reservedOrPremiumWorkspaceSlug?.type === "reserved" ||
(workspace.plan !== "pro" &&
reservedOrPremiumWorkspaceSlug?.type === "premium") ||
!isWorkspaceSlugAvailable
) {
throw new TRPCError({

View File

@@ -3,6 +3,7 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { createAuthMiddleware } from "better-auth/api";
import { apiKey } from "better-auth/plugins";
import { magicLink } from "better-auth/plugins/magic-link";
import { env } from "next-runtime-env";
import type { dbClient } from "@kan/db/client";
import * as memberRepo from "@kan/db/repository/member.repo";
@@ -70,7 +71,7 @@ export const initAuth = (db: dbClient) => {
const user = ctx.context.session?.user;
if (
process.env.NEXT_PUBLIC_KAN_ENV === "cloud" &&
env("NEXT_PUBLIC_KAN_ENV") === "cloud" &&
user &&
!user.stripeCustomerId
) {

View File

@@ -8,6 +8,7 @@ import { Html } from "@react-email/html";
import { Link } from "@react-email/link";
import { Preview } from "@react-email/preview";
import { Text } from "@react-email/text";
import { env } from "next-runtime-env";
import * as React from "react";
export const JoinWorkspaceTemplate = ({
@@ -90,7 +91,7 @@ export const JoinWorkspaceTemplate = ({
/>
<Text style={{ color: "#7e7e7e" }}>
<Link
href={process.env.NEXT_PUBLIC_BASE_URL}
href={env("NEXT_PUBLIC_BASE_URL")}
target="_blank"
style={{ color: "#7e7e7e", textDecoration: "underline" }}
>

View File

@@ -8,6 +8,7 @@ import { Html } from "@react-email/html";
import { Link } from "@react-email/link";
import { Preview } from "@react-email/preview";
import { Text } from "@react-email/text";
import { env } from "next-runtime-env";
import * as React from "react";
export const MagicLinkTemplate = ({
@@ -90,7 +91,7 @@ export const MagicLinkTemplate = ({
/>
<Text style={{ color: "#7e7e7e" }}>
<Link
href={process.env.NEXT_PUBLIC_BASE_URL}
href={env("NEXT_PUBLIC_BASE_URL")}
target="_blank"
style={{ color: "#7e7e7e", textDecoration: "underline" }}
>

10
pnpm-lock.yaml generated
View File

@@ -138,6 +138,9 @@ importers:
next-logger:
specifier: ^5.0.1
version: 5.0.1(next@14.2.20(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(pino@9.6.0)
next-runtime-env:
specifier: ^1.7.2
version: 1.8.0
nextjs-cors:
specifier: ^2.2.0
version: 2.2.0(next@14.2.20(react-dom@18.3.1(react@18.3.1))(react@18.3.1))
@@ -4461,6 +4464,9 @@ packages:
winston:
optional: true
next-runtime-env@1.8.0:
resolution: {integrity: sha512-QJVxzmr2gTao/vZKFgcrByFrifl0YOMTvuUVxcI/X7ratlW+9zMvMmA9AGU9cFsumXJtohWkCvwPdBNdkTCYfw==}
next@14.2.20:
resolution: {integrity: sha512-yPvIiWsiyVYqJlSQxwmzMIReXn5HxFNq4+tlVQ812N1FbvhmE+fDpIAD7bcS2mGYQwPJ5vAsQouyme2eKsxaug==}
engines: {node: '>=18.17.0'}
@@ -10665,6 +10671,10 @@ snapshots:
optionalDependencies:
pino: 9.6.0
next-runtime-env@1.8.0:
dependencies:
chalk: 4.1.2
next@14.2.20(react-dom@18.3.1(react@18.3.1))(react@18.3.1):
dependencies:
'@next/env': 14.2.20