Skip to content

Commit

Permalink
Fix dockerfile to avoid the installation of playwright on production (o…
Browse files Browse the repository at this point in the history
…pendatahub-io#1004)

* Fix dockerfile and migrate from s2i

* WIP commit to avoid installng playwright in prod

* Adapt dockerfile to node 18

* Update copy to runtime container

* Fix some issues in the dockerfile multistage

* Add testing and lining dependencies to optionalDependencies
  • Loading branch information
lucferbux authored Mar 16, 2023
1 parent b37d37a commit 6d3be41
Show file tree
Hide file tree
Showing 6 changed files with 2,892 additions and 3,854 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ frontend/node_modules
frontend/public
backend/node_modules
backend/dist
node_modules/

.github/
.vscode/
.idea/
tests/
**/__mocks__/
**/__tests__/
**/.storybook/
scripts/
manifests/

Expand Down
48 changes: 28 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,45 @@ ARG SOURCE_CODE=.
# Use ubi8/nodejs-18 as default base image
ARG BASE_IMAGE="registry.access.redhat.com/ubi8/nodejs-18:latest"


FROM ${BASE_IMAGE}
FROM ${BASE_IMAGE} as builder

## Build args to be used at this step
ARG SOURCE_CODE

LABEL io.opendatahub.component="odh-dashboard" \
io.k8s.display-name="odh-dashboard" \
name="open-data-hub/odh-dashboard-ubi8" \
summary="odh-dashboard" \
description="Open Data Hub Dashboard"
WORKDIR /usr/src/app

## Copying in source code
COPY --chown=default:root ${SOURCE_CODE} /usr/src/app

## Switch to root as required for some operations
USER root
# Change file ownership to the assemble user
USER default

## Copying in source code
RUN mkdir /tmp/src && chown -R 1001:0 /tmp/src
COPY --chown=default:root ${SOURCE_CODE} /tmp/src
RUN npm ci --omit=optional

## For npm context. The assemble script will "mv /tmp/src/* /opt/app-root/src"
#@ but that won't pick up .* files at the root
COPY ${SOURCE_CODE}/.npmrc /opt/app-root/src/
RUN npm run build

FROM ${BASE_IMAGE} as runtime

WORKDIR /usr/src/app

RUN mkdir /usr/src/app/logs

# Change file ownership to the assemble user
USER default

## Build dashboard using NPM
ENV NPM_CONFIG_NODEDIR=/usr
RUN /usr/libexec/s2i/assemble
COPY --chown=default:root --from=builder /usr/src/app/frontend/public /usr/src/app/frontend/public
COPY --chown=default:root --from=builder /usr/src/app/backend/package.json /usr/src/app/backend/package.json
COPY --chown=default:root --from=builder /usr/src/app/backend/package-lock.json /usr/src/app/backend/package-lock.json
COPY --chown=default:root --from=builder /usr/src/app/backend/dist /usr/src/app/backend/dist

RUN cd backend && npm ci --omit=dev --omit=optional

CMD /usr/libexec/s2i/run
WORKDIR /usr/src/app/backend

CMD ["npm", "run", "start"]

LABEL io.opendatahub.component="odh-dashboard" \
io.k8s.display-name="odh-dashboard" \
name="open-data-hub/odh-dashboard-ubi8" \
summary="odh-dashboard" \
description="Open Data Hub Dashboard"

Loading

0 comments on commit 6d3be41

Please sign in to comment.