-
Notifications
You must be signed in to change notification settings - Fork 19
feat: improve dockerfile #1295
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
Open
ndrpp
wants to merge
15
commits into
main
Choose a base branch
from
feat/1278-improve-dockerfile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−45
Open
feat: improve dockerfile #1295
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c775af7
feat: improve dockerfile
ndrpp 00757a5
fix: copy all dir contents to runner
ndrpp b99979e
fix: create storage dirs manually
ndrpp fe29d46
fix: check with root permissions
ndrpp b025691
fix: update permissions for database dirs
ndrpp 7d22ad1
fix: directory permissions for node user
ndrpp 454e393
fix: recursive chown for databases dir
ndrpp 9869208
fix: update get version method to work for node dist/index.js run
ndrpp 8e0289e
fix: change permissions for jobs dir so child containers can write
ndrpp fb9e8e0
Merge branch 'main' into feat/1278-improve-dockerfile
ndrpp 6847317
feat: make image smaller by removing unneeded stuff
ndrpp 451b027
docs: explain the assignment of node user to docker group
ndrpp c7ceb5a
ci: add faster failure for test_integration & system to check error
ndrpp 30ebd22
Revert "ci: add faster failure for test_integration & system to check…
ndrpp bde93ed
docs: add comment for chmodSync fn
ndrpp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,56 @@ | ||
| FROM ubuntu:22.04 AS base | ||
| RUN apt-get update && apt-get -y install bash curl git wget libatomic1 python3 build-essential | ||
| COPY .nvmrc /usr/src/app/ | ||
| RUN rm /bin/sh && ln -s /bin/bash /bin/sh | ||
| ENV NVM_DIR=/usr/local/nvm | ||
| RUN mkdir $NVM_DIR | ||
| ENV NODE_VERSION=v22.15.0 | ||
| # Install nvm with node and npm | ||
| RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \ | ||
| && source $NVM_DIR/nvm.sh \ | ||
| && nvm install $NODE_VERSION \ | ||
| && nvm alias default $NODE_VERSION \ | ||
| && nvm use default | ||
| ENV NODE_PATH=$NVM_DIR/$NODE_VERSION/lib/node_modules | ||
| ENV PATH=$NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH | ||
| ENV IPFS_GATEWAY='https://ipfs.io/' | ||
| ENV ARWEAVE_GATEWAY='https://arweave.net/' | ||
|
|
||
| FROM base AS builder | ||
| COPY package*.json /usr/src/app/ | ||
| COPY scripts/ /usr/src/app/scripts/ | ||
| WORKDIR /usr/src/app/ | ||
| FROM node:22.15.0-bookworm@sha256:a1f1274dadd49738bcd4cf552af43354bb781a7e9e3bc984cfeedc55aba2ddd8 AS builder | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| python3 \ | ||
| build-essential \ | ||
| libatomic1 \ | ||
| git \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| WORKDIR /usr/src/app | ||
| COPY package*.json ./ | ||
| COPY scripts/ ./scripts/ | ||
| RUN npm ci | ||
| COPY . . | ||
| RUN npm run build && npm prune --omit=dev | ||
|
|
||
|
|
||
| FROM node:22.15.0-bookworm-slim@sha256:557e52a0fcb928ee113df7e1fb5d4f60c1341dbda53f55e3d815ca10807efdce AS runner | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| dumb-init \ | ||
| gosu \ | ||
| libatomic1 \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| ENV NODE_ENV=production \ | ||
| IPFS_GATEWAY='https://ipfs.io/' \ | ||
| ARWEAVE_GATEWAY='https://arweave.net/' \ | ||
| P2P_ipV4BindTcpPort=9000 \ | ||
| P2P_ipV4BindWsPort=9001 \ | ||
| P2P_ipV6BindTcpPort=9002 \ | ||
| P2P_ipV6BindWsPort=9003 \ | ||
| P2P_ipV4BindWssPort=9005 \ | ||
| HTTP_API_PORT=8000 | ||
|
|
||
| EXPOSE 9000 9001 9002 9003 9005 8000 | ||
|
|
||
| # GID of the docker group on the host. Needs to match so the node user can access | ||
| # /var/run/docker.sock for compute jobs. Default is 999 (common on Debian/Ubuntu). | ||
| # Override at build time if your host differs: docker build --build-arg DOCKER_GID=$(getent group docker | cut -d: -f3) . | ||
| ARG DOCKER_GID=999 | ||
| RUN groupadd -g ${DOCKER_GID} docker && usermod -aG docker node | ||
|
|
||
| WORKDIR /usr/src/app | ||
|
|
||
| COPY --chown=node:node --from=builder /usr/src/app/dist ./dist | ||
| COPY --chown=node:node --from=builder /usr/src/app/node_modules ./node_modules | ||
| COPY --chown=node:node --from=builder /usr/src/app/schemas ./schemas | ||
| COPY --chown=node:node --from=builder /usr/src/app/package.json ./ | ||
| COPY --chown=node:node --from=builder /usr/src/app/config.json ./ | ||
|
|
||
| RUN mkdir -p databases c2d_storage logs | ||
|
|
||
| COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh | ||
| RUN chmod +x /usr/local/bin/docker-entrypoint.sh | ||
|
|
||
| FROM base AS runner | ||
| COPY . /usr/src/app | ||
| WORKDIR /usr/src/app/ | ||
| COPY --from=builder /usr/src/app/node_modules/ /usr/src/app/node_modules/ | ||
| RUN npm run build | ||
| ENV P2P_ipV4BindTcpPort=9000 | ||
| EXPOSE 9000 | ||
| ENV P2P_ipV4BindWsPort=9001 | ||
| EXPOSE 9001 | ||
| ENV P2P_ipV6BindTcpPort=9002 | ||
| EXPOSE 9002 | ||
| ENV P2P_ipV6BindWsPort=9003 | ||
| EXPOSE 9003 | ||
| ENV P2P_ipV4BindWssPort=9005 | ||
| EXPOSE 9005 | ||
| ENV HTTP_API_PORT=8000 | ||
| EXPOSE 8000 | ||
| ENV NODE_ENV='production' | ||
| CMD ["npm","run","start"] | ||
| ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] | ||
| CMD ["node", "--max-old-space-size=28784", "--trace-warnings", "--experimental-specifier-resolution=node", "dist/index.js"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| # Fix ownership of directories that may be mounted as volumes (owned by root). | ||
| # Runs as root, then drops to 'node' user via gosu. | ||
| chown -R node:node /usr/src/app/databases /usr/src/app/c2d_storage /usr/src/app/logs 2>/dev/null || true | ||
|
|
||
| exec gosu node dumb-init -- "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { createRequire } from 'module' | ||
|
|
||
| const require = createRequire(import.meta.url) | ||
|
|
||
| export function getPackageVersion(): string { | ||
| return process.env.npm_package_version ?? require('../../package.json').version | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a description comment above