Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker inferred sync should use the specified target stage when specified #6524

Open
briandealwis opened this issue Aug 26, 2021 · 0 comments

Comments

@briandealwis
Copy link
Member

briandealwis commented Aug 26, 2021

Expected behavior

A user should be able to use inferred sync to reference files from a specific target in a multi-stage Dockerfile regardless of the position of that target stage in the Dockerfile:

- image: frontend
    context: frontend
    docker:
      target: development
    sync:
      infer:
      - '**/*.ts'
      - '**/*.tsx'
      - '**/*.css'

Actual behavior

The inferencing code only considers the last stage in the Dockerfile, and so the inferencing may not work.

Skaffold should examine the named stage when specified rather than the last stage.

Information

  • Skaffold version: 1.30.0 (but has been a limitation for a long time)
  • Contents of skaffold.yaml:

Example from @tclasen https://github.com/tclasen/example/tree/broken_hot_reloading

apiVersion: skaffold/v2beta20
kind: Config
metadata:
  name: example
build:
  artifacts:
  - image: frontend
    context: frontend
    docker:
      target: development
    sync:
      infer:
      - '**/*.ts'
      - '**/*.tsx'
      - '**/*.css'

Dockerfile:

ARG IMAGENAME=node
ARG IMAGETAG=16-slim

FROM ${IMAGENAME}:${IMAGETAG} AS base
EXPOSE 3000
RUN useradd -ms /bin/bash nodejs
WORKDIR /app
RUN chown -R nodejs /app
ENV NEXT_TELEMETRY_DISABLED 1

FROM base AS deps
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

FROM base AS development
ENV NODE_ENV development
COPY --chown=nodejs . .
COPY --from=deps /app/node_modules ./node_modules
CMD ["yarn", "dev"]

FROM development AS builder
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline

FROM base AS production
ENV NODE_ENV production
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
USER nodejs
CMD ["yarn", "start"]

Workaround

There are two workaround:

  1. Place the desired target stage last in the Dockerfile.
  2. Explicitly specify the destinations using manual sync rules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant