-
-
Save arvi9/cac11e9bf5125f7adb67f231c749ff8b to your computer and use it in GitHub Desktop.
My docker-compose with nextjs and nginx
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
.next/ | |
node_modules/ | |
Dockerfile | |
yarn-error.log | |
.dockerignore | |
.git | |
.gitignore |
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
image: docker | |
services: | |
- docker:dind | |
stages: | |
- test | |
- deploy | |
test: | |
stage: test | |
only: | |
- staging | |
script: | |
- echo It should be running some test | |
tags: | |
- staging | |
step-deploy-staging: | |
stage: deploy | |
only: | |
- staging | |
variables: | |
API_URL: "" | |
GOOGLE_KEY: "ABCD" | |
NEXT_APP_VERSION: "0.0.13" | |
script: | |
# - sudo docker image prune -f | |
# - docker volume prune -f | |
- docker-compose build | |
- docker-compose down | |
- docker-compose up -d | |
tags: | |
- staging | |
environment: staging | |
step-deploy-prod: | |
stage: deploy | |
only: | |
- production | |
variables: | |
API_URL: "" | |
script: | |
- sudo docker image prune -f | |
- docker-compose build --no-cache | |
- docker-compose up -d | |
environment: production |
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
version: "3.8" | |
services: | |
nextjs: | |
ports: | |
- "3000:3000" | |
build: | |
context: nextapp | |
dockerfile: Dockerfile.dev | |
volumes: | |
- ./nextapp:/app | |
- nextjs-dev-node_modules:/app/node_modules | |
- nextjs-dev-next:/app/.next | |
restart: always | |
frontend: | |
image: nginx:latest | |
volumes: | |
- ./nginx/nginx.conf:/etc/nginx/nginx.conf | |
- ./nginx/conf.d:/etc/nginx/conf.d | |
ports: | |
- "80:80" | |
depends_on: | |
- nextjs | |
restart: always | |
volumes: | |
nextjs-dev-node_modules: | |
nextjs-dev-next: |
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
version: "3.8" | |
services: | |
nextjs: | |
image: kennethnwc/nextapp:${NEXT_APP_VERSION} | |
ports: | |
- "3000:3000" | |
build: | |
context: nextapp | |
dockerfile: Dockerfile | |
target: prod | |
args: | |
NEXT_PUBLIC_GOOGLE_KEY: ${GOOGLE_KEY} | |
NEXT_PUBLIC_APP_VERSION: ${NEXT_APP_VERSION} | |
volumes: | |
- /app/node_modules | |
- /app/.next | |
restart: always | |
environment: | |
- API_URL=${API_URL} | |
- GOOGLE_KEY=${GOOGLE_KEY} | |
frontend: | |
image: nginx:latest | |
volumes: | |
- ./nginx/nginx.conf:/etc/nginx/nginx.conf | |
- ./nginx/conf.d:/etc/nginx/conf.d | |
ports: | |
- "80:80" | |
depends_on: | |
- nextjs | |
restart: always |
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
FROM node:14.15-alpine as base | |
RUN mkdir /app | |
WORKDIR /app | |
COPY package*.json ./ | |
COPY yarn.lock ./ | |
FROM base as pre-prod | |
COPY . . | |
RUN yarn install --frozen-lockfile | |
ARG NEXT_PUBLIC_GOOGLE_KEY | |
ARG NEXT_PUBLIC_APP_VERSION | |
ENV NEXT_PUBLIC_GOOGLE_KEY=${NEXT_PUBLIC_GOOGLE_KEY} | |
ENV NEXT_PUBLIC_APP_VERSION=${NEXT_PUBLIC_APP_VERSION} | |
RUN yarn build | |
FROM node:14.15-alpine as prod | |
RUN mkdir /app | |
WORKDIR /app | |
COPY --from=pre-prod /app/public ./public | |
COPY --from=pre-prod /app/.next ./.next | |
COPY --from=pre-prod /app/node_modules ./node_modules | |
EXPOSE 3000 | |
CMD ["node_modules/.bin/next", "start"] |
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
FROM node:14.5.0 as dev | |
RUN mkdir /app | |
WORKDIR /app | |
COPY package*.json ./ | |
COPY yarn.lock ./ | |
RUN yarn | |
EXPOSE 3000 | |
CMD ["yarn" , "dev"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment