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

Stop running frontend and processor with root user #451

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ services:
dockerfile: Dockerfile

processor:
user: root
kasbah marked this conversation as resolved.
Show resolved Hide resolved
build:
context: processor/
dockerfile: Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ services:
- redis
- meilisearch
volumes:
- gitea-data:/gitea-data
- gitea-data:/gitea-data:ro
- processor-data:/data
# share docker daemon when running docker inside docker
- /var/run/docker.sock:/var/run/docker.sock
Expand Down
24 changes: 16 additions & 8 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ COPY yarn.lock .
RUN yarn --frozen-lockfile

FROM base AS production
COPY --from=build /build/.next/ .next/
COPY --from=build /deps/node_modules/ node_modules/
COPY package.json .
COPY next.config.js .
COPY public/ public/
RUN mkdir src/
COPY src/server.js src/server.js

ENV NODE_ENV=production
CMD yarn start
# give the node user read-only permissions
ARG PERMISSION=644
COPY --chmod=${PERMISSION} --from=build /deps/node_modules/ node_modules/
kasbah marked this conversation as resolved.
Show resolved Hide resolved
COPY --chmod=${PERMISSION} package.json .
COPY --chmod=${PERMISSION} next.config.js .
COPY --chmod=${PERMISSION} public/ public/
COPY --chmod=${PERMISSION} src/server.js server.js

# The `.next` directory is used by `next/image` to cache optimized images.
# So it needs to be owned by the `node` user.
COPY --chown=node:node --from=build /build/.next/ .next/

USER node

CMD ["node", "server.js"]
1 change: 1 addition & 0 deletions processor/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*Dockerfile*
*docker-compose*
node_modules
dist
kasbah marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 6 additions & 3 deletions processor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ RUN apt-get update -qq && apt-get install -qq --no-install-recommends -y \
python3-pip \
git

RUN mkdir /app
WORKDIR /app

COPY . .

RUN pip3 install -r requirements.txt
RUN yarn install
RUN yarn tsc
RUN yarn cp-assets

RUN addgroup --gid 1000 node && \
adduser -u 1000 --gid 1000 node --shell /bin/bash --home /home/node && \
mkdir /data /gitea-data && \
chown -R node /data /gitea-data

USER node
CMD ["node", "dist/src/server.js"]
5 changes: 5 additions & 0 deletions scripts/clear_volumes_and_test_processor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ docker-compose down -v

# you can pass arguments to mocha e.g. `-g multi`
args="$(concatenate_args "$@")"

# We need to install packages, compile ts, and move assets before running the actual testing code.
# The `node` user doesn't have permission to do any of these tasks.
docker-compose run \
-u root \
--rm \
-e LOG_LEVEL=debug \
-e DATA_DIR=/data/test \
processor sh -c "yarn install && yarn tsc && yarn cp-assets && yarn cp-test-assets && yarn test ${args}"