|
| 1 | +################################################################################# |
| 2 | +# Eclipse Tractus-X - Industry Core Hub Frontend |
| 3 | +# |
| 4 | +# Copyright (c) 2025 Contributors to the Eclipse Foundation |
| 5 | +# |
| 6 | +# See the NOTICE file(s) distributed with this work for additional |
| 7 | +# information regarding copyright ownership. |
| 8 | +# |
| 9 | +# This program and the accompanying materials are made available under the |
| 10 | +# terms of the Apache License, Version 2.0 which is available at |
| 11 | +# https://www.apache.org/licenses/LICENSE-2.0. |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 16 | +# either express or implied. See the |
| 17 | +# License for the specific language govern in permissions and limitations |
| 18 | +# under the License. |
| 19 | +# |
| 20 | +# SPDX-License-Identifier: Apache-2.0 |
| 21 | +################################################################################# |
| 22 | + |
| 23 | +# Stage 1: Build the React app |
| 24 | +FROM node:23-alpine AS builder |
| 25 | + |
| 26 | +# Copy package files and install dependencies |
| 27 | +COPY package.json package-lock.json ./ |
| 28 | +RUN npm ci --ignore-scripts |
| 29 | + |
| 30 | +# Copy the rest of the source code |
| 31 | +COPY . /app |
| 32 | + |
| 33 | +# Set the working directory |
| 34 | +WORKDIR /app |
| 35 | + |
| 36 | +# Build the application |
| 37 | +RUN npm run build |
| 38 | + |
| 39 | + |
| 40 | +# Stage 2: Serve the app with Nginx |
| 41 | +FROM nginxinc/nginx-unprivileged:alpine3.21 |
| 42 | + |
| 43 | +# Copy custom Nginx configuration |
| 44 | +COPY nginx.conf /etc/nginx/conf.d/default.conf |
| 45 | + |
| 46 | +# Copy built files from the builder stage |
| 47 | +COPY --from=builder /app/dist /usr/share/nginx/html |
| 48 | + |
| 49 | +# Change to root user |
| 50 | +USER root |
| 51 | + |
| 52 | +# Rename index.html to index.html.reference, to be used by env variables inject script |
| 53 | +# Create symlink for tmp for index.html to enable readOnlyRootFilesystem |
| 54 | +RUN mv /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.reference \ |
| 55 | + && ln -s /tmp/index.html /usr/share/nginx/html/index.html |
| 56 | + |
| 57 | +# Add env variables inject script and mark as executable |
| 58 | +# Make nginx owner of /usr/share/nginx/html/ and change to nginx user |
| 59 | +COPY ./scripts/inject-dynamic-env.sh /docker-entrypoint.d/00-inject-dynamic-env.sh |
| 60 | +RUN chmod +x /docker-entrypoint.d/00-inject-dynamic-env.sh \ |
| 61 | + && chown -R 101:101 /usr/share/nginx/html/ |
| 62 | + |
| 63 | +# Change to nginx user |
| 64 | +USER 101 |
| 65 | + |
| 66 | +# Expose port 80 |
| 67 | +EXPOSE 80 |
| 68 | + |
| 69 | +# Healthcheck to verify Nginx is running |
| 70 | +HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ |
| 71 | + CMD wget --spider -q http://localhost || exit 1 |
| 72 | + |
| 73 | +# Start Nginx |
| 74 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments