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

Refactored DockerFile to improve efficiency #2607

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Contains the PDF file of the Tag as JSON string, thus does not need to be linted

Check warning on line 1 in .eslintignore

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
src/components/CheckIn/tagTemplate.ts
package.json
package-lock.json
tsconfig.json
docker-compose.yml
Dockerfile
nginx.conf
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
FROM node:20.10.0 AS build

WORKDIR /usr/src/app
# Step 1: Build Stage
FROM node:20.10.0-alpine AS builder
WORKDIR /talawa-admin

COPY package*.json ./

RUN npm install

COPY . .

ENV NODE_ENV=production

RUN npm run build

EXPOSE 4321
#Step 2: Production
FROM nginx:1.27.3-alpine AS production

ENV NODE_ENV=production

CMD ["npm", "run", "serve"]
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /talawa-admin/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
app:
build:
context: .
ports:
- '${PORT}:80'
environment:
- REACT_APP_TALAWA_URL=${REACT_APP_TALAWA_URL}
- REACT_APP_BACKEND_WEBSOCKET_URL=${REACT_APP_BACKEND_WEBSOCKET_URL}
- PORT=${PORT}
- REACT_APP_USE_RECAPTCHA=${REACT_APP_USE_RECAPTCHA}
- REACT_APP_RECAPTCHA_SITE_KEY=${REACT_APP_RECAPTCHA_SITE_KEY}
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:80']
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
53 changes: 53 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
server {
listen 80;
server_name domain.com;

# Redirect HTTP to HTTPS
# return 301 https://$host$request_uri;

# listen 443 ssl;
# server_name domain.com;

# SSL Certificates
# ssl_certificate /etc/nginx/ssl/cert.pem;
# ssl_certificate_key /etc/nginx/ssl/key.pem;

root /usr/share/nginx/html;
index index.html;

# Security Headers
add_header X-Frame-Options "DENY";
add_header X-Content-Type-Options "nosniff";
add_header X-XSS-Protection "1; mode=block";
add_header Referrer-Policy "strict-origin-when-cross-origin";
# add_header Content-Security-Policy "default-src 'self'; connect-src 'self' https://your-graphql-server.com;";

# Static Files and SPA Routing
location / {
try_files $uri /index.html;
}

# Proxy GraphQL API
location /graphql/ {
proxy_pass http://127.0.0.1:4000/graphql/;
add_header Access-Control-Allow-Origin https://your-react-app-domain.com;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}

# Gzip Compression for better loading of Static Files
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 256;
gzip_vary on;

error_page 404 /index.html;
}
Loading
Loading