test
This commit is contained in:
21
Dockerfile
21
Dockerfile
@@ -1,5 +1,5 @@
|
|||||||
# Use official Node.js image as base
|
# Use official Node.js image as base
|
||||||
FROM node:18-alpine AS builder
|
FROM node:20-alpine as builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
@@ -7,9 +7,13 @@ RUN npm install --force
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Install git, get commit hash
|
# Install git and get commit hash
|
||||||
RUN apk add --no-cache git \
|
RUN apk add --no-cache git && \
|
||||||
&& git rev-parse --short HEAD > /app/git_commit_sha
|
if [ -d .git ]; then \
|
||||||
|
git rev-parse --short HEAD > /app/git_commit_sha; \
|
||||||
|
else \
|
||||||
|
echo "unknown" > /app/git_commit_sha; \
|
||||||
|
fi
|
||||||
|
|
||||||
ENV NEXT_PUBLIC_API_URL=/api
|
ENV NEXT_PUBLIC_API_URL=/api
|
||||||
|
|
||||||
@@ -19,7 +23,7 @@ ENV NEXT_PUBLIC_API_URL=/api
|
|||||||
RUN echo "Building with GIT_COMMIT_SHA=$(cat /app/git_commit_sha)" && npm run build
|
RUN echo "Building with GIT_COMMIT_SHA=$(cat /app/git_commit_sha)" && npm run build
|
||||||
|
|
||||||
# ---- Production Stage ----
|
# ---- Production Stage ----
|
||||||
FROM node:18-alpine AS runner
|
FROM node:20-alpine
|
||||||
|
|
||||||
# Set working directory inside the container
|
# Set working directory inside the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -30,19 +34,22 @@ RUN mkdir -p /app/public
|
|||||||
COPY --from=builder /app/package.json /app/package-lock.json ./
|
COPY --from=builder /app/package.json /app/package-lock.json ./
|
||||||
COPY --from=builder /app/.next ./.next
|
COPY --from=builder /app/.next ./.next
|
||||||
COPY --from=builder /app/node_modules ./node_modules
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder /app/next.config.mjs ./next.config.mjs
|
||||||
|
|
||||||
# Copy commit hash file from builder stage
|
# Copy commit hash file from builder stage
|
||||||
COPY --from=builder /app/git_commit_sha /app/git_commit_sha
|
COPY --from=builder /app/git_commit_sha /app/git_commit_sha
|
||||||
|
RUN cat /app/git_commit_sha
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV NEXT_PUBLIC_API_URL=/api
|
ENV NEXT_PUBLIC_API_URL=/api
|
||||||
ENV SERVER_API_URL=https://internal-api.inboxi.ng/api
|
ENV SERVER_API_URL=https://internal-api.inboxi.ng
|
||||||
|
|
||||||
# Set GIT_COMMIT_SHA environment variable in the final image by reading the file
|
# Set GIT_COMMIT_SHA environment variable in the final image by reading the file
|
||||||
ENV GIT_COMMIT_SHA="$(cat /app/git_commit_sha)"
|
ENV GIT_COMMIT_SHA="$(cat /app/git_commit_sha)"
|
||||||
|
|
||||||
|
|
||||||
# Start Next.js server
|
# Start Next.js server
|
||||||
CMD ["npm", "run", "start"]
|
CMD ["npm", "start"]
|
||||||
@@ -31,6 +31,28 @@ export async function getGitCommitInfo(): Promise<GitInfo> {
|
|||||||
return gitInfo;
|
return gitInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In Docker, the hash might be stored in a file at /app/git_commit_sha
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
try {
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Check for Docker-specific git hash file
|
||||||
|
const dockerGitHashPath = '/app/git_commit_sha';
|
||||||
|
if (fs.existsSync(dockerGitHashPath)) {
|
||||||
|
const hash = fs.readFileSync(dockerGitHashPath, 'utf8').trim();
|
||||||
|
const gitInfo: GitInfo = {
|
||||||
|
commitHash: hash,
|
||||||
|
buildTime: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
cachedGitInfo = gitInfo;
|
||||||
|
return gitInfo;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Could not read git hash from Docker file', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// In the browser, fetch from the public directory
|
// In the browser, fetch from the public directory
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user