Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a Docker image #7

Open
kehralexander opened this issue Jul 14, 2023 · 14 comments
Open

Provide a Docker image #7

kehralexander opened this issue Jul 14, 2023 · 14 comments
Assignees
Labels
enhancement New feature or request

Comments

@kehralexander
Copy link

Provide a docker image for self-hosted deployment.
A matching docker compose file as an example would also be a good idea I think.

This also provides a quick way to try out the application for new users.

@alexfornuto
Copy link

Subscribed to this issue. When there's a docker image, I'm deffo gonna try it!

@kehralexander
Copy link
Author

I've had a quick shot at it but when running npm run build I'm getting:

> next build

❌ Invalid environment variables: {
  DATABASE_URL: [ 'Required' ],
  NEXTAUTH_SECRET: [ 'Required' ],
  NEXTAUTH_URL: [ 'Required' ],
  GITHUB_ID: [ 'Required' ],
  GITHUB_SECRET: [ 'Required' ],
  AWS_ENDPOINT: [ 'Required' ],
  AWS_REGION: [ 'Required' ],
  AWS_KEY_ID: [ 'Required' ],
  AWS_SECRET_ACCESS_KEY: [ 'Required' ],
  AWS_BUCKET_NAME: [ 'Required' ],
  POSTHOG_PROXY_PATH: [ 'Required' ],
  NEXT_PUBLIC_POSTHOG_HOST: [ 'Required' ],
  NEXT_PUBLIC_POSTHOG_PROXY_HOST: [ 'Required' ]
}

Which makes sense per the setup tutorial from the README. Yet compiling these credentials into the image statically is not what we want.
I sadly have no experience with NextJS and don't really know how to change it in a way that it reads these env vars at application startup.

@MarconLP MarconLP added the enhancement New feature or request label Jul 15, 2023
@vikramwalia
Copy link

+1 on the docker image.

@alexfornuto
Copy link

alexfornuto commented Jul 15, 2023

@m3shat would you care to share what got you to that point? I have more experience with NextJS than I do making Docker images (which is to say barely any), but it looks like we may need to just provide default values for those environment variables, and/or provide them when the image starts. Might be a great opportunity to write an example Docker Compose file.

@kehralexander
Copy link
Author

@alexfornuto See my temporary fork or this Dockerfile:

FROM node:18-alpine as builder
WORKDIR /build

COPY . /build
ENV NEXT_TELEMETRY_DISABLED 1

RUN npm install --omit=dev && npm run build     
#                               ↑ this is where that "Invalid environment variable" error occurs

FROM node:18-alpine AS runner
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /build/node_modules ./node_modules
COPY --from=builder /build/package.json ./package.json

USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["npm", "start"]

The dockerfile is heavily inspired from what is written in this blog.
Looks like there's also an official example.

@MarconLP MarconLP self-assigned this Jul 16, 2023
@MarconLP
Copy link
Owner

thanks @m3shat! I managed to build a docker container without statically embedding the environment variables.

https://github.com/MarconLP/snapify/pkgs/container/snapify

docker pull ghcr.io/marconlp/snapify:latest

@alexfornuto
Copy link

Consider re-opening this and considering it closed once there are complete instructions for using this with docker. For example, how should one provide the variables to the internal application?

Maybe a docker compose example with accompanying database?

@vikramwalia
Copy link

+1 on what @alexfornuto said ! Could we keep this open till we have documented way of using variables i.e. ports etc.

@0x3e4
Copy link

0x3e4 commented Jul 21, 2023

@alexfornuto @vikramwalia you need the following basic configuration to run it in docker:

PostgreSQL
docker run -d --name snapify-postgres -e POSTGRES_USER=snapify -e POSTGRES_PASSWORD=snapify -e POSTGRES_DB=snapify -p 5432:5432 postgres:latest

Snapify
docker run -d --name snapify-web -e DATABASE_URL="postgres://snapify:snapify@localhost:5432/snapify" -e NEXTAUTH_SECRET="REPLACESTRING" -e NEXTAUTH_URL="http://localhost:3000/" -e GITHUB_ID="" -e GITHUB_SECRET="" -e AWS_ENDPOINT="" -e AWS_REGION="" -e AWS_KEY_ID="" -e AWS_SECRET_ACCESS_KEY="" -e AWS_BUCKET_NAME="" -p 3000:3000 ghcr.io/marconlp/snapify:latest

but you will then get a copy of the https://snapify.it/ site hosted in your environment which does not look good for a production env yet.

but big up for the project!

@MarconLP MarconLP reopened this Jul 24, 2023
@MarconLP
Copy link
Owner

opening because of the lack of documentation

@sampritavh
Copy link

How did you managed to build it? For me it is giving following error

[+] Building 522.6s (21/21) FINISHED                                                                                            
 => [internal] load build definition from Dockerfile                                                                       0.0s
 => => transferring dockerfile: 37B                                                                                        0.0s
 => [internal] load .dockerignore                                                                                          0.0s
 => => transferring context: 34B                                                                                           0.0s
 => [internal] load metadata for docker.io/library/node:18-alpine3.17                                                      2.2s
 => [deps 1/6] FROM docker.io/library/node:18-alpine3.17@sha256:7186663f5c94e0f5e389304c748a2d5b5e5f8c941d305c3bae4f68a70  0.0s
 => [internal] load build context                                                                                          0.0s
 => => transferring context: 7.25kB                                                                                        0.0s
 => CACHED [builder 2/5] WORKDIR /app                                                                                      0.0s
 => CACHED [runner 3/9] RUN addgroup --system --gid 1001 nodejs                                                            0.0s
 => CACHED [runner 4/9] RUN adduser --system --uid 1001 nextjs                                                             0.0s
 => CACHED [deps 2/6] RUN apk add --no-cache libc6-compat openssl1.1-compat                                                0.0s
 => CACHED [deps 3/6] WORKDIR /app                                                                                         0.0s
 => CACHED [deps 4/6] COPY prisma ./                                                                                       0.0s
 => CACHED [deps 5/6] COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./                                   0.0s
 => CACHED [deps 6/6] RUN  if [ -f yarn.lock ]; then yarn --frozen-lockfile;  elif [ -f package-lock.json ]; then npm ci;  0.0s
 => CACHED [builder 3/5] COPY --from=deps /app/node_modules ./node_modules                                                 0.0s
 => [builder 4/5] COPY . .                                                                                                 0.1s
 => [builder 5/5] RUN  if [ -f yarn.lock ]; then SKIP_ENV_VALIDATION=1 yarn build;  elif [ -f package-lock.json ]; then  518.0s
 => CACHED [runner 5/9] COPY --from=builder /app/next.config.mjs ./                                                        0.0s
 => CACHED [runner 6/9] COPY --from=builder /app/public ./public                                                           0.0s
 => CACHED [runner 7/9] COPY --from=builder /app/package.json ./package.json                                               0.0s
 => ERROR [runner 8/9] COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./                                  0.0s
 => ERROR [runner 9/9] COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static                          0.0s
------                                                                                                                          
 > [runner 8/9] COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./:
------
------
 > [runner 9/9] COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static:
------
failed to compute cache key: "/app/.next/static" not found: not found

Do we have any specific instructions on building the Docker Image .. I tried it with the Dockerfile in the main branch

@alexfornuto
Copy link

The docker image also requires environment variables that I don't think should be needed to run locally, like the AWS and GitHub keys.

I'd really love to run this locally, but so far it seems to only be suitable for developers working on the project itself.

@accforgithubtest
Copy link

I wanted to selfhost and try this out - but the lack of a docker image and clear instructions is a problem for me as I am not a developer.

From above comments, looks like other have tried to build a custom image, Is there anyone that has built a image that doesnt need any external services like aws / etc ?

@alexfornuto
Copy link

Seeing no update to to the repo's single branch in 6 months, I'm afraid that this project may no longer be maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants