Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion .env.docker-compose.dev
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres

VALKEY_URL='redis://cache:6379'
VALKEY_HOST='cache'
2 changes: 1 addition & 1 deletion .env.docker-compose.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ MAILGUN_SMTP_USERNAME=omitted
OTEL_SERVICE_NAME=core.core
PUBPUB_URL=http://localhost:3000
API_KEY=xxx
VALKEY_URL='redis://cache:6379'
VALKEY_HOST='cache'
32 changes: 16 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ARG PNPM_VERSION=9.10.0

################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} as base
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS base

# these are necessary to be able to use them inside of `base`
ARG BASE_IMAGE
Expand All @@ -39,22 +39,22 @@ RUN --mount=type=cache,target=/root/.npm \
npm install -g pnpm@${PNPM_VERSION}


FROM base as fetch-deps
FROM base AS fetch-deps


# Copy pnpm-lock.yaml so that we can use pnpm to install dependencies
COPY pnpm-lock.yaml ./

# Could possibly be sped up using `turbo prune`
# Could possibly be sped up using `turbo prune`
# https://turbo.build/repo/docs/guides/tools/docker
RUN pnpm fetch

# Install dependencies we only need to run pnpm install
RUN apk add g++ make py3-pip
RUN apk add g++ make py3-pip

################################################################################
# Create a stage for building the application.
FROM fetch-deps as monorepo
FROM fetch-deps AS monorepo

# Copy over the rest of the files
ADD . ./
Expand All @@ -76,39 +76,39 @@ RUN test -n "$PACKAGE" || (echo "PACKAGE not set, required for this target" &&
ENV DOCKERBUILD=1

ARG CI
ENV CI $CI
ENV CI=$CI

RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN,env=SENTRY_AUTH_TOKEN \
pnpm --filter $PACKAGE build
pnpm --filter $PACKAGE build

FROM withpackage as prepare-jobs
FROM withpackage AS prepare-jobs

ARG PACKAGE

RUN pnpm --filter $PACKAGE --prod deploy /tmp/app


FROM base as jobs
FROM base AS jobs

WORKDIR /usr/src/app

COPY --from=prepare-jobs --chown=node:node /tmp/app .

USER node

CMD pnpm start
CMD ["pnpm", "start"]

################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
# this is separated by package to make it slightly more clear what happens
# and because you cannot conditionally copy from a different folder
# based on the argument
FROM base as prod-setup
# based on the argument
FROM base AS prod-setup
ARG PORT

# Use production node environment by default.
ENV NODE_ENV production
ENV NODE_ENV=production

# Run the application as a non-root user.
USER node
Expand All @@ -117,10 +117,10 @@ USER node
EXPOSE $PORT

# Use production node environment by default.
ENV NODE_ENV production
ENV NODE_ENV=production

# otherwise it will use the strange default docker hostname
ENV HOSTNAME "0.0.0.0"
ENV HOSTNAME="0.0.0.0"

### Core

Expand All @@ -132,4 +132,4 @@ COPY --from=withpackage --chown=node:node /usr/src/app/core/public ./core/public
# needed to set the database url correctly based on PGHOST variables
COPY --from=withpackage --chown=node:node /usr/src/app/core/.env.docker ./core/.env

CMD node core/server.js
CMD ["node", "core/server.js"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently using non-json arguments here can prevent the server from responding to signals sent to the container

2 changes: 1 addition & 1 deletion core/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ DATACITE_PASSWORD=""
DATACITE_API_URL="https://api.test.datacite.org"

GCLOUD_KEY_FILE='xxx'
VALKEY_URL='redis://cache:6379'
VALKEY_HOST='localhost'
2 changes: 1 addition & 1 deletion core/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ HONEYCOMB_API_KEY="xxx"
# KYSELY_DEBUG="true"

GCLOUD_KEY_FILE='xxx'
VALKEY_URL='redis://cache:6379'
VALKEY_HOST='cache'
20 changes: 10 additions & 10 deletions core/app/api/health/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import type { NextRequest } from "next/server";

import { NextResponse } from "next/server";

import { logger } from "logger";

import { db } from "~/kysely/database";
import { getRedisClient } from "~/lib/redis";
import { handleErrors } from "~/lib/server";

export async function GET(req: NextRequest) {
return await handleErrors(async () => {
const errors: string[] = [];
try {
const dbQuery = await db
const dbQuery = db
.selectFrom("communities")
.selectAll()
.select("id")
.limit(1)
.executeTakeFirstOrThrow();
const cacheQuery = (await getRedisClient()).ping();
await Promise.all([dbQuery, cacheQuery]);
} catch (err) {
if (err instanceof Error) {
errors.push(err.message);
}
}

if (errors.length > 0) {
return NextResponse.json({ errors }, { status: 500 });
logger.error({ msg: "error in health check", err });
return NextResponse.json({}, { status: 500 });
}

return NextResponse.json({});
Expand Down
Loading
Loading