GoogleContainerTools / GoogleContainerTools/skaffold
Docker inferred sync should use the specified target stage when specified
- Dominant language
- Go
- Stars
- 15.9k
- Forks
- 1.7k
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 10
Description
### 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:
```yaml
- 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
```yaml
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](https://skaffold.dev/docs/pipeline-stages/filesync/#manual-sync-mode).
Contributor guide
Assessment
This issue has not been assessed yet.