|
| 1 | +# Copyright Red Hat, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# ── Stage 1: build ──────────────────────────────────────────────────────────── |
| 16 | +FROM node:20-bookworm-slim AS build |
| 17 | + |
| 18 | +RUN corepack enable |
| 19 | + |
| 20 | +WORKDIR /app |
| 21 | + |
| 22 | +COPY package.json yarn.lock .yarnrc.yml backstage.json ./ |
| 23 | +COPY .yarn ./.yarn |
| 24 | + |
| 25 | +COPY tsconfig.json .eslintrc.js .eslintignore ./ |
| 26 | + |
| 27 | +COPY packages/ ./packages/ |
| 28 | +COPY plugins/ ./plugins/ |
| 29 | + |
| 30 | +COPY app-config.yaml ./ |
| 31 | + |
| 32 | +RUN YARN_ENABLE_SCRIPTS=0 \ |
| 33 | + YARN_ENABLE_IMMUTABLE_INSTALLS=false \ |
| 34 | + YARN_CACHE_FOLDER=/root/.yarn/berry/cache \ |
| 35 | + yarn install |
| 36 | + |
| 37 | +RUN yarn tsc |
| 38 | +RUN yarn workspace app build |
| 39 | +RUN yarn workspace backend build |
| 40 | + |
| 41 | +# ── Stage 2: production image ───────────────────────────────────────────────── |
| 42 | +FROM node:20-bookworm-slim |
| 43 | + |
| 44 | +RUN corepack enable \ |
| 45 | + && apt-get update && apt-get install -y --no-install-recommends \ |
| 46 | + python3 make g++ \ |
| 47 | + && rm -rf /var/lib/apt/lists/* |
| 48 | + |
| 49 | +WORKDIR /app |
| 50 | + |
| 51 | +COPY --from=build /app/packages/backend/dist/skeleton.tar.gz ./ |
| 52 | +RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz |
| 53 | + |
| 54 | +COPY --from=build /app/package.json /app/yarn.lock /app/.yarnrc.yml ./ |
| 55 | +COPY --from=build /app/.yarn ./.yarn |
| 56 | + |
| 57 | +RUN node -e " \ |
| 58 | + const fs = require('fs'); \ |
| 59 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); \ |
| 60 | + if (pkg.scripts) pkg.scripts.postinstall = 'true'; \ |
| 61 | + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); \ |
| 62 | + " \ |
| 63 | + && YARN_ENABLE_IMMUTABLE_INSTALLS=false \ |
| 64 | + YARN_CACHE_FOLDER=/root/.yarn/berry/cache \ |
| 65 | + yarn workspaces focus --all --production \ |
| 66 | + && rm -rf "$(yarn cache dir)" |
| 67 | + |
| 68 | +COPY --from=build /app/packages/app/package.json packages/app/package.json |
| 69 | +RUN ln -sf ../packages/app node_modules/app |
| 70 | + |
| 71 | +COPY --from=build /app/packages/backend/dist/bundle.tar.gz ./ |
| 72 | +RUN tar xzf bundle.tar.gz && rm bundle.tar.gz |
| 73 | + |
| 74 | +COPY --from=build /app/plugins/dcm-backend/config.d.ts plugins/dcm-backend/config.d.ts |
| 75 | +COPY --from=build /app/packages/app/dist packages/app/dist |
| 76 | +COPY app-config.yaml app-config.production.yaml ./ |
| 77 | + |
| 78 | +RUN chown -R node:node /app |
| 79 | +USER node |
| 80 | + |
| 81 | +EXPOSE 7007 |
| 82 | + |
| 83 | +CMD ["node", "packages/backend", \ |
| 84 | + "--config", "app-config.yaml", \ |
| 85 | + "--config", "app-config.production.yaml"] |
0 commit comments