Skip to content

Commit

Permalink
t7
Browse files Browse the repository at this point in the history
  • Loading branch information
mazzyy committed Oct 26, 2024
1 parent 932a8a1 commit f1f22b2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
66 changes: 54 additions & 12 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,74 @@
# Use the official Node.js image from the Docker Hub
# Build stage
FROM node:20-slim AS build

# Set the working directory in the container
# Add build arguments
ARG REACT_APP_BASE_URL
ARG gemini_key
ARG PERSONAL_ACCESS_TOKEN_GITHUB

# Set environment variables
ENV REACT_APP_BASE_URL=$REACT_APP_BASE_URL
ENV gemini_key=$gemini_key
ENV PERSONAL_ACCESS_TOKEN_GITHUB=$PERSONAL_ACCESS_TOKEN_GITHUB

# Set the working directory
WORKDIR /app

# Copy the package.json and package-lock.json into the container at /app
# Copy package files
COPY package*.json ./

# Install any dependencies specified in package.json
# Install dependencies
RUN npm install

# Copy the rest of the application code into the container at /app
# Copy the rest of the application code
COPY . .

# Build the React app for production
# Log environment variables for debugging during build
RUN echo "Building with REACT_APP_BASE_URL=$REACT_APP_BASE_URL"

# Build the React app
RUN npm run build

# Use a different base image for serving the app
# Production stage
FROM nginx:alpine

# Copy the build output to Nginx's html directory
# Install bash and curl for debugging if needed
RUN apk add --no-cache bash curl

# Copy the build output
COPY --from=build /app/build /usr/share/nginx/html

# Copy custom Nginx configuration file
# Copy nginx config
COPY default.conf /etc/nginx/conf.d/default.conf

# Expose port 3000
# Create a runtime environment script
RUN echo "window._env_ = {};" > /usr/share/nginx/html/env-config.js

# Create entrypoint script with improved error handling
RUN echo '#!/bin/bash' > /entrypoint.sh && \
echo 'set -e' >> /entrypoint.sh && \
echo '' >> /entrypoint.sh && \
echo '# Create env-config.js with environment variables' >> /entrypoint.sh && \
echo 'cat <<EOF > /usr/share/nginx/html/env-config.js' >> /entrypoint.sh && \
echo 'window._env_ = {' >> /entrypoint.sh && \
echo ' REACT_APP_BASE_URL: "${REACT_APP_BASE_URL:-\"http://localhost:8080\"},"' >> /entrypoint.sh && \
echo ' gemini_key: "${gemini_key:-\"\"},"' >> /entrypoint.sh && \
echo ' PERSONAL_ACCESS_TOKEN_GITHUB: "${PERSONAL_ACCESS_TOKEN_GITHUB:-\"\"}"' >> /entrypoint.sh && \
echo '};' >> /entrypoint.sh && \
echo 'EOF' >> /entrypoint.sh && \
echo '' >> /entrypoint.sh && \
echo '# Verify nginx config' >> /entrypoint.sh && \
echo 'nginx -t' >> /entrypoint.sh && \
echo '' >> /entrypoint.sh && \
echo '# Start nginx' >> /entrypoint.sh && \
echo 'exec nginx -g "daemon off;"' >> /entrypoint.sh && \
chmod +x /entrypoint.sh

# Add healthcheck
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost:3000/ || exit 1

EXPOSE 3000

# Command to run nginx
CMD ["nginx", "-g", "daemon off;"]
# Use entrypoint script
ENTRYPOINT ["/entrypoint.sh"]
24 changes: 24 additions & 0 deletions frontend/default.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server {
listen 3000;
server_name localhost;

location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}

# Enable gzip compression
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

# Error pages
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

0 comments on commit f1f22b2

Please sign in to comment.