Skip to content

Commit

Permalink
Updating docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfieJones committed Mar 3, 2024
1 parent 0a91bf8 commit 9a95705
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
6 changes: 3 additions & 3 deletions apps/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ WORKDIR /app
# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=builder /app/out/pnpm-lock.yaml ./app/pnpm-lock.yaml
RUN corepack enable pnpm && pnpm install --frozen-lockfile

ENV SKIP_ENV_VALIDATION=true
ENV DOCKER_BUILD=true
ENV NEXT_PUBLIC_BACKEND_URL=/api

# Build the project
COPY --from=builder /app/out/full/ .
Expand All @@ -36,6 +35,7 @@ WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs


COPY --from=installer /app/apps/web/next.config.js .
COPY --from=installer /app/apps/web/package.json .
Expand All @@ -46,7 +46,7 @@ COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public

ENV NEXT_PUBLIC_BACKEND_URL=/api


EXPOSE 3000

Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@ import { NextResponse } from "next/server";
import { oryEndpoint } from "@pixeleye/auth";
import type { NextRequest } from "next/server";
import { Session } from "@ory/kratos-client";
import { env } from "./env";

// Bit of a hack to redirect self-hosted docker users to the correct backend URL.
function handleSelfHostedRewrites(request: NextRequest) {
if (env.NEXT_PUBLIC_PIXELEYE_HOSTING === "true" || !env.BACKEND_URL) return;

const url = request.nextUrl.clone();
if (!url.pathname.startsWith("/api")) return;

const newURL = new URL(env.BACKEND_URL);

newURL.pathname = url.pathname.replace("/api", "");

return NextResponse.rewrite(newURL, {
request,
});
}

// Anyone not logged in is redirected to the login page.

export async function middleware(request: NextRequest) {
const res = handleSelfHostedRewrites(request);
if (res) return res;

const data = await fetch(oryEndpoint + "/sessions/whoami", {
headers: {
cookie: request.cookies
Expand Down Expand Up @@ -48,5 +68,6 @@ export const config = {
"/settings/:path*",
"/usage/:path*",
"/invites/:path*",
"/api/:path*",
],
};
28 changes: 14 additions & 14 deletions docker/docker-compose-self-hosting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,20 @@ services:
# - GITHUB_APP_PRIVATE_KEY= # optional if you want to use the github login
networks:
- intranet
pixeleye-frontend:
image: pixeleye/pixeleye-frontend:latest
restart: unless-stopped
environment:
- NEXT_PUBLIC_ORY_URL=http://kratos:4433
- ORY_URL=http://kratos:4433
- NEXT_PUBLIC_ORY_URL=http://localhost:4433
- BACKEND_URL=http://pixeleye-backend:5000
- NEXT_PUBLIC_BACKEND_URL=/api
# - GITHUB_APP_NAME= # optional if you want to use the github login
networks:
- intranet
ports:
- "3000:3000"
# pixeleye-frontend:
# image: pixeleye/pixeleye-frontend:latest
# restart: unless-stopped
# environment:
# - NEXT_PUBLIC_ORY_URL=http://kratos:4433
# - ORY_URL=http://kratos:4433
# - NEXT_PUBLIC_ORY_URL=http://localhost:4433
# - BACKEND_URL=http://pixeleye-backend:5000
# - CLIENT_BACKEND_URL=http://localhost:5000
# # - GITHUB_APP_NAME= # optional if you want to use the github login
# networks:
# - intranet
# ports:
# - "3000:3000"

kratos-migrate:
image: oryd/kratos:v1.0.0
Expand Down

0 comments on commit 9a95705

Please sign in to comment.