Skip to content

Commit

Permalink
Add docker build config for cyberstorm-nextjs
Browse files Browse the repository at this point in the history
Add necessary configs for building a container distribution of the
cyberstorm-nextjs app
MythicManiac committed Jul 5, 2023
1 parent ce20cc9 commit 02b051d
Showing 7 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/node_modules
.git
build-secrets
**/next-env.d.ts
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -152,6 +152,30 @@ needs to be set (in the repo it's stored as a Secret for Actions).

## Docker

### Docker Compose

The build configuration for some apps is included in the
`docker-compose.build.yml` file, making building of the services simple.

**You will need to ensure all configured secrets are present before building
with docker compose.** Currently the only required secret is the `.npmrc` file,
which should include authentication to the font awesome private registry. See
[Font Awesome documentation](https://fontawesome.com/docs/web/setup/packages)
for more info on how to authenticate with npm, and then copy the `~/.npmrc` file
it generates to the `./build-secrets` directory.

**Build secrets are unsupported in the `docker-compose` python package, you must
use the built-in `docker compose` subcommand instead.**

Once the build-time secrets are available, building the services is as simple as
running:

```bash
docker compose -f docker-compose.build.yml build
```

### Plain Docker

The provided `Dockerfile` can be used to run the Next.js production server, e.g:

```
23 changes: 23 additions & 0 deletions apps/cyberstorm-nextjs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# For running @thunderstore/cyberstorm-nextjs in Docker container.
FROM node:18-alpine3.17
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

WORKDIR /app

COPY package.json yarn.lock babel.config.js .eslintrc.json .eslintignore .yarnrc .prettierrc .prettierignore .stylelintrc ./
COPY .yarn ./.yarn
COPY packages ./packages
COPY apps/cyberstorm-nextjs ./apps/cyberstorm-nextjs
RUN chown node:node -R /app

USER node
RUN --mount=type=secret,id=npmrc,target=/home/node/.npmrc,uid=1000 yarn install --frozen-lockfile
RUN yarn workspace @thunderstore/cyberstorm-nextjs run build

ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production
ENV PORT 3000
EXPOSE 3000

CMD ["yarn", "workspace", "@thunderstore/cyberstorm-nextjs", "start"]
1 change: 1 addition & 0 deletions apps/cyberstorm-nextjs/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react/next" />
3 changes: 3 additions & 0 deletions build-secrets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!README.md
7 changes: 7 additions & 0 deletions build-secrets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Build Secrets

This directory exists to house secrets that should not be committed to git but
should be available when building, such as the .npmrc file.

The docker compose configuration should expect any such build-time secrets to
be in this directory.
14 changes: 14 additions & 0 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -8,3 +8,17 @@ services:
image: thunderstore/thunderstore-ui.sertra:${IMAGE_TAG:-dev}
ports:
- "127.0.0.1:3000:3000"

cyberstorm-nextjs:
build:
context: "./"
dockerfile: "apps/cyberstorm-nextjs/Dockerfile"
secrets:
- "npmrc"
image: thunderstore/thunderstore-ui.cyberstorm-nextjs:${IMAGE_TAG:-dev}
ports:
- "127.0.0.1:3000:3000"

secrets:
npmrc:
file: "./build-secrets/.npmrc"

0 comments on commit 02b051d

Please sign in to comment.