3

The issue:

When running skaffold and update watched files, I see the file sync update occur and nodemon restart the server, but refreshing the page doesn't show the change. It's not until after I stop skaffold entirely and restart that I see the change.

Syncing 1 files for test/dev-client:e9c0a112af09abedcb441j4asdfasfd1cf80f2a9bc80342fd4123f01f32e234cfc18
Watching for changes every 1s...
[client-deployment-656asdf881-m643v client] [nodemon] restarting due to changes...
[client-deployment-656asdf881-m643v client] [nodemon] starting `node bin/server.js`

The setup:

I have a simple microservices application. It has a server side (flask/python) and a client side (react) with express handling the dev server. I have nodemon on with the legacy watch flag as true (For Chokidar polling). On development I'm using Kubernetes via Docker for Mac.

Code:

I'm happy to post my code to assist. Just let me know which ones are most needed.

Here's some starters:

Skaffold.yaml:

apiVersion: skaffold/v1beta7
kind: Config
build:
  local:
    push: false
  artifacts:
    - image: test/dev-client
      docker:
        dockerfile: Dockerfile.dev
      context: ./client
      sync:
        '**/*.css': .
        '**/*.scss': .
        '**/*.js': .
    - image: test/dev-server
      docker:
        dockerfile: Dockerfile.dev
      context: ./server
      sync:
        '**/*.py': .
deploy:
  kubectl:
    manifests:
      - k8s-test/client-ip-service.yaml
      - k8s-test/client-deployment.yaml
      - k8s-test/ingress-service.yaml
      - k8s-test/server-cluster-ip-service.yaml
      - k8s-test/server-deployment.yaml

The relevant part from Package.json:

 "start": "nodemon -L bin/server.js",

Dockerfile.dev (Client side):

# base image
FROM node:10.8.0-alpine

# setting the working directory 
# may have to run this depending on environment
# RUN mkdir -p /usr/src/app 
WORKDIR /usr/src/app

# add '/usr/src/app/node_modules/.bin' to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache app depencies
COPY package.json /usr/src/app/package.json
RUN npm install

# copy over everything else
COPY . .

# start the app.
CMD ["npm", "run", "start"]
dizzy
  • 1,177
  • 2
  • 12
  • 34

1 Answers1

5

It turns out I was using the wrong pattern for my file syncs. **/*.js doesn't sync the directory properly.

After changing

sync:
        '**/*.css': .
        '**/*.scss': .
        '**/*.js': .

to

sync:
        '***/*.css': .
        '***/*.scss': .
        '***/*.js': .

It immediately began working.


Update: On the latest versions of skaffold, this pattern no longer works as skaffold abandoned flattening by default. You can now use **/* patterns and get the same results.

dizzy
  • 1,177
  • 2
  • 12
  • 34
  • 1
    @jtlz2 that's my ticket. Along with my edit (see above), there is now a new ticket discussing this: https://github.com/GoogleContainerTools/skaffold/issues/2158 – dizzy Jun 15 '19 at 06:31
  • I am getting issues with syncing in skaffold run, but since I have little idea where to start the question would be too vague :( – jtlz2 Jun 15 '19 at 12:13
  • 1
    If you post an issue on github or a question here, let me know and I'd be happy to look over it. – dizzy Jun 15 '19 at 18:38
  • Thanks @dizzy, much appreciated! – jtlz2 Jun 15 '19 at 18:42