-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |