Skip to content

Commit

Permalink
changed everything
Browse files Browse the repository at this point in the history
  • Loading branch information
f-bguiga committed Feb 12, 2024
1 parent d04ffc2 commit 0f5c802
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 13 deletions.
41 changes: 28 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
# Use an official Node.js runtime as a base image
FROM node:20-alpine
# Base stage to install node deps

# Set the working directory to /app
FROM --platform=linux/amd64 node:20-alpine AS base
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install dependencies
RUN npm install
RUN npm ci

# Copy the remaining application code to the working directory
# Build stage to transpile `src` into `dist`

FROM base AS build

COPY --from=base package*.json ./
COPY --from=base /app/node_modules ./node_modules
COPY . .

# Build the Next.js application
RUN npm run build
RUN npm run build \
&& npm prune --production

# Final stage for production app image

FROM base AS production

ENV NODE_ENV="production"
ENV PORT=3000

COPY --from=build --chown=node:node package*.json ./
COPY --from=build --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/dist ./dist

# Remove if you don't have public files
COPY --from=build --chown=node:node /app/public ./public
RUN mkdir -p /app/shared/public

# Expose the port that the application will run on
EXPOSE 3000
EXPOSE $PORT

# Start the application
CMD ["npm", "start"]
CMD ["node", "dist/main.js"]
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3.8"

services:
api:
image: 600453241670.dkr.ecr.us-east-1.amazonaws.com/next-docker:${IMAGE_TAG:-latest}
platform: linux/amd64
restart: always
ports:
- 3000:3000
command:
- /bin/sh
- -c
- |
# Sync shared public files
rm -rf /app/shared/public/*
cp -r /app/public/* /app/shared/public
#
# You can add more commands before startup: compile assets, run migrations, ... if you have
# ...
#
# Start node app
node dist/main.js
environment:
- DATABASE_URL=${DATABASE_URL}
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
- JWT_EXPIRES_TIME=${JWT_EXPIRES_TIME}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_S3_BUCKET=${AWS_S3_BUCKET}
- AWS_REGION=${AWS_REGION}
- SENTRY_DNS=${SENTRY_DNS}
volumes:
- public_assets:/app/shared/public

nginx:
image: nginx:alpine
platform: linux/amd64
restart: always
ports:
- 80:80
depends_on:
- api
volumes:
- public_assets:/app/public
- ./nginx.conf:/etc/nginx/conf.d/default.conf

volumes:
public_assets:

0 comments on commit 0f5c802

Please sign in to comment.