mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
create standalone infisical docker file
This commit is contained in:
102
Dockerfile.stand-alone-infisical
Normal file
102
Dockerfile.stand-alone-infisical
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
ARG POSTHOG_HOST=https://app.posthog.com
|
||||||
|
ARG POSTHOG_API_KEY=posthog-api-key
|
||||||
|
|
||||||
|
FROM node:16-alpine AS frontend-dependencies
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY frontend/package.json frontend/package-lock.json frontend/next.config.js ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci --only-production --ignore-scripts
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM node:16-alpine AS frontend-builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy dependencies
|
||||||
|
COPY --from=frontend-dependencies /app/node_modules ./node_modules
|
||||||
|
# Copy all files
|
||||||
|
COPY /frontend .
|
||||||
|
|
||||||
|
ENV NODE_ENV production
|
||||||
|
ENV NEXT_PUBLIC_ENV production
|
||||||
|
ARG POSTHOG_HOST
|
||||||
|
ENV NEXT_PUBLIC_POSTHOG_HOST $POSTHOG_HOST
|
||||||
|
ARG POSTHOG_API_KEY
|
||||||
|
ENV NEXT_PUBLIC_POSTHOG_API_KEY $POSTHOG_API_KEY
|
||||||
|
|
||||||
|
# Build
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production image
|
||||||
|
FROM node:16-alpine AS frontend-runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
RUN mkdir -p /app/.next/cache/images && chown nextjs:nodejs /app/.next/cache/images
|
||||||
|
VOLUME /app/.next/cache/images
|
||||||
|
|
||||||
|
ARG POSTHOG_API_KEY
|
||||||
|
ENV NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY \
|
||||||
|
BAKED_NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY
|
||||||
|
|
||||||
|
COPY --chown=nextjs:nodejs --chmod=555 frontend/scripts ./scripts
|
||||||
|
COPY --from=frontend-builder /app/public ./public
|
||||||
|
RUN chown nextjs:nodejs ./public/data
|
||||||
|
COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
|
##
|
||||||
|
## BACKEND
|
||||||
|
##
|
||||||
|
FROM node:16-alpine AS backend-build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY backend/package*.json ./
|
||||||
|
RUN npm ci --only-production
|
||||||
|
|
||||||
|
COPY /backend .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:16-alpine AS backend-runner
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY backend/package*.json ./
|
||||||
|
RUN npm ci --only-production
|
||||||
|
|
||||||
|
COPY --from=backend-build /app .
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:14-alpine AS production
|
||||||
|
|
||||||
|
WORKDIR /
|
||||||
|
|
||||||
|
# Install PM2
|
||||||
|
RUN npm install -g pm2
|
||||||
|
# Copy ecosystem.config.js
|
||||||
|
COPY ecosystem.config.js .
|
||||||
|
|
||||||
|
RUN apk add --no-cache nginx
|
||||||
|
|
||||||
|
COPY nginx/default-stand-alone-docker.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
|
COPY --from=backend-runner /app /backend
|
||||||
|
|
||||||
|
COPY --from=frontend-runner /app/ /app/
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
ENV HTTPS_ENABLED false
|
||||||
|
|
||||||
|
CMD ["pm2-runtime", "start", "ecosystem.config.js"]
|
||||||
|
|
||||||
|
|
||||||
32
ecosystem.config.js
Normal file
32
ecosystem.config.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
module.exports = {
|
||||||
|
apps: [
|
||||||
|
{
|
||||||
|
name: 'frontend',
|
||||||
|
script: "./scripts/start.sh",
|
||||||
|
instances: 1,
|
||||||
|
cwd: "./app",
|
||||||
|
interpreter: 'sh',
|
||||||
|
exec_mode: "fork",
|
||||||
|
autorestart: true,
|
||||||
|
watch: false,
|
||||||
|
max_memory_restart: '500M',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'backend',
|
||||||
|
script: 'npm',
|
||||||
|
args: 'run start',
|
||||||
|
cwd: "./backend",
|
||||||
|
instances: 1,
|
||||||
|
exec_mode: "fork",
|
||||||
|
autorestart: true,
|
||||||
|
watch: false,
|
||||||
|
max_memory_restart: '500M',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "nginx",
|
||||||
|
script: "nginx",
|
||||||
|
args: "-g 'daemon off;'",
|
||||||
|
exec_interpreter: "none",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
36
nginx/default-stand-alone-docker.conf
Normal file
36
nginx/default-stand-alone-docker.conf
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
events {}
|
||||||
|
http {
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
|
||||||
|
location /api {
|
||||||
|
proxy_set_header X-Real-RIP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-NginX-Proxy true;
|
||||||
|
|
||||||
|
proxy_pass http://localhost:4000; # for backend
|
||||||
|
proxy_redirect off;
|
||||||
|
|
||||||
|
# proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
|
||||||
|
proxy_cookie_path / "/; HttpOnly; SameSite=strict";
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
|
||||||
|
proxy_set_header X-Real-RIP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-NginX-Proxy true;
|
||||||
|
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
|
proxy_pass http://localhost:3000; # for frontend
|
||||||
|
proxy_redirect off;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user