0

I was expecting Skaffold to restart the container process when the code is changed, but it turns out that nodemon is still necessary to restart the server after the source files are synced.

apiVersion: skaffold/v4beta2
kind: Config
metadata:
  name: microservices-quiz-app
build:
  local:
    push: false
  artifacts:
    - image: bogdan-pechounov/auth
      context: auth
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: src/**/*.js
            dest: .
FROM node:18-alpine

WORKDIR /app

COPY ["package.json", "package-lock.json*", "./"]

# RUN npm install --production
RUN npm install # to install nodemon dev dependency

COPY . .

# CMD ["npm", "start"] # node src/server.js
CMD [ "npm", "run", "dev" ] # nodemon src/server.js

Is there no way to rerun ["npm", "start"] on file change? (documentation, related) I would think that it should be trivial given that file changes are already detected ("half" of what nodemon does). I want to avoid having different configurations for development and production.


I would probably need a different configuration anyway to install dev depedencies for testing. I am thinking of using RUN if [ "$NODE_ENV" = "production" ] ; then npm install --production ; else npm install ; fi (source), but I don't know how to pass arguments with Skaffold.

BPDev
  • 397
  • 1
  • 9

0 Answers0