I have a GitHub pipeline that builds and pushes an image to DockerHub. However, GitHub Actions consistently attempts to install devDependencies, causing it to fail when it can’t install better-sqlite3. Here are my Dockerfile and pipeline configuration:
Dockerfile:
FROM node:slim
WORKDIR /app
COPY . .
ENV NODE_ENV=production
RUN echo $NODE_ENV
RUN echo "npm version: $(npm -v)"
RUN npm install --omit=dev
CMD [ "npm", "run dev" ]
EXPOSE 3004
Pipeline Configuration:
name: Publish Docker image
on:
push:
branches: ["main"]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: my-image
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
How can I prevent GitHub Actions from installing devDependencies during the build process?
I have attempted to set NODE_ENV to production and run npm install with flags such as –production, –only=production, and –omit=dev, but the pipeline still attempts to fetch devDependencies. I expect the pipeline to exclude devDependencies during the npm install process.