lenra-io / dofigen

Dofigen is a Dockerfile generator using a simplified description in YAML or JSON format
MIT License
25 stars 1 forks source link

[Bug]: Artifact copy does gives the write owner #193

Open taorepoara opened 3 weeks ago

taorepoara commented 3 weeks ago

What happened?

I used a builder with specified user but when I copy artifacts to the builder they are always added for the user 1000.

Here is my Dofigen file:

builders:
  - name: copy-source
    from: alpine
    workdir: /app
    adds: [.]
    run:
      - ls -al

  - name: cleaned-nginx
    from: bitnami/nginx
    root:
      run: 
        - rm -Rf /app/*
        - install_packages gettext-base

  - name: rdv-builder
    from: &flutter-image growerp/flutter-sdk-image:3.16.9
    workdir: /app
    artifacts:
      - builder: copy-source
        source: "/app/common"
        target: "/app/common"
      - builder: copy-source
        source: "/app/rdv"
        target: "/app/rdv"
    user: mobiledevops
    run:
      - cd rdv
      - flutter pub get
      - flutter build web

  - name: kine-builder
    from: *flutter-image
    workdir: /app
    artifacts:
      - builder: copy-source
        source: "/app/common"
        target: "/app/common"
      - builder: copy-source
        source: "/app/kine"
        target: "/app/kine"
    user: mobiledevops
    run:
      - cd kine
      - flutter pub get
      - flutter build web

  - name: backoffice-builder
    from: oven/bun
    workdir: /app
    artifacts:
      - builder: copy-source
        source: "/app/common-types"
        target: "/app/common-types"
      - builder: copy-source
        source: "/app/backoffice"
        target: "/app/backoffice"
    run:
      - cd backoffice
      - echo "install"
      - bun i
      - echo "build"
      - bun run build
from: cleaned-nginx
workdir: /app
artifacts:
  - builder: copy-source
    source: "/app/conf/nginx.conf"
    target: "/opt/bitnami/nginx/conf/server_blocks/custom.conf"
  - builder: rdv-builder
    source: "/app/rdv/build/web"
    target: "/app/rdv"
  - builder: kine-builder
    source: "/app/kine/build/web"
    target: "/app/kine"
  - builder: backoffice-builder
    source: "/app/backoffice/dist"
    target: "/app/backoffice"
context:
  - /conf/
  - /common/
  - /rdv/
  - /kine/
  - /common-types/
  - /backoffice/
ignores:
  - /rdv/build/
  - /kine/build/
  - /common/dist/
  - /backoffice/dist/
  - /common/node_modules/
  - /backoffice/node_modules/

Here is the generated Dockerfile:

# This file is generated by Dofigen v1.4.0
# https://github.com/lenra-io/dofigen

# syntax=docker/dockerfile:1.4

# copy-source
FROM alpine AS copy-source
WORKDIR /app
ADD --link . ./
RUN \
    ls -al

# cleaned-nginx
FROM bitnami/nginx AS cleaned-nginx
USER 0
RUN \
    rm -Rf /app/* && \
    install_packages gettext-base

# rdv-builder
FROM growerp/flutter-sdk-image:3.16.9 AS rdv-builder
WORKDIR /app
COPY --link --chown=1000:1000 --from=copy-source "/app/common" "/app/common"
COPY --link --chown=1000:1000 --from=copy-source "/app/rdv" "/app/rdv"
USER mobiledevops
RUN \
    cd rdv && \
    flutter pub get && \
    flutter build web

# kine-builder
FROM growerp/flutter-sdk-image:3.16.9 AS kine-builder
WORKDIR /app
COPY --link --chown=1000:1000 --from=copy-source "/app/common" "/app/common"
COPY --link --chown=1000:1000 --from=copy-source "/app/kine" "/app/kine"
USER mobiledevops
RUN \
    cd kine && \
    flutter pub get && \
    flutter build web

# backoffice-builder
FROM oven/bun AS backoffice-builder
WORKDIR /app
COPY --link --chown=1000:1000 --from=copy-source "/app/common-types" "/app/common-types"
COPY --link --chown=1000:1000 --from=copy-source "/app/backoffice" "/app/backoffice"
RUN \
    cd backoffice && \
    echo "install" && \
    bun i && \
    echo "build" && \
    bun run build

# runtime
FROM cleaned-nginx AS runtime
WORKDIR /app
COPY --link --chown=1000:1000 --from=copy-source "/app/conf/nginx.conf" "/opt/bitnami/nginx/conf/server_blocks/custom.conf"
COPY --link --chown=1000:1000 --from=rdv-builder "/app/rdv/build/web" "/app/rdv"
COPY --link --chown=1000:1000 --from=kine-builder "/app/kine/build/web" "/app/kine"
COPY --link --chown=1000:1000 --from=backoffice-builder "/app/backoffice/dist" "/app/backoffice"
USER 1000

Version

1.4.0

Relevant log output

No response

taorepoara commented 3 weeks ago

Also true for the cache management:

Dockerfile:29
--------------------
  28 |     USER mobiledevops
  29 | >>> RUN \
  30 | >>>     --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/home/mobiledevops/.pub-cache\
  31 | >>>     cd rdv && \
  32 | >>>     flutter pub get
  33 |