-
Notifications
You must be signed in to change notification settings - Fork 707
Closed
Description
Hi, i'm building a build-push action to Docker Hub from this repo but the Docker Image Build failed when running npm run build as it couldn't read process.env.MONGO_URI no .env file in a public repo.
The same error ofcourse happened when i tried to push from my local terminal to Docker Hub and .env is included in .dockerignore, and when i removed .env from .dockerignore it worked fine.
This is my Dockerfile
# Development Stage
# from node 16-alpine as a base image
FROM node:16-alpine AS development
# set /app as working directory
WORKDIR /app
# copy all files to working directory
COPY . ./
# install dependencies
RUN npm install
# run next build
RUN npm run build
# Production Stage
# from node 16-alpine as a base image
FROM node:16-alpine AS production
# set NODE_ENV as production
ENV NODE_ENV production
# set /app as working directory
WORKDIR /app
# copy package.json, package-lock.json from development stage
COPY --from=development /app/package*.json ./
# install production dependencies only
RUN npm install --only=prod
# copy all files to work dir
COPY . ./
# copy .next, public folders from development stage
COPY --from=development /app/.next ./.next
COPY --from=development /app/public ./public
EXPOSE 3000
# run next start
CMD ["npm", "run", "start"]And my Github Actions file
# Build and push to Docker Hub
name: ci
on:
push:
branches:
- 'main'
jobs:
build-container:
name: build Docker container
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_IMAGE }}Is there a workaround
Metadata
Metadata
Assignees
Labels
No labels

