firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.38k stars 135 forks source link

gitlab-ci-local sometimes update original sources file when artifacts requested #1034

Open airone-x1 opened 1 year ago

airone-x1 commented 1 year ago

I use marmail-cli in my CI. When using gitlab-ci-local :+1:

Minimal .gitlab-ci.yml illustrating the issue

marmaid_svg:
  image:
    name: docker.io/minlag/mermaid-cli
    entrypoint: [""]
  script:
    - MMDC="/home/mermaidcli/node_modules/.bin/mmdc -p /puppeteer-config.json"
    - $MMDC -i docs/index.md -o docs/index2.md
  artifacts:
   paths:
      - docs/
   expire_in: "30 mins"

Expected behavior updated artifacts in .gitlab-ci-local not in original sources

Host information Ubuntu gitlab-ci-local 4.45.1

Containerd binary Docker

Additional context

Sample project https://github.com/airone-x1/gcl-mermaidcli

After running gitlab-ci-local

I expect gitlab-ci-local writing only in its own .gitlab-ci-local directory, not in my project files.

firecow commented 1 year ago

This must be a bug.

gitlab-ci-local is not supposed to change project specific file permissions.

airone-x1 commented 1 year ago

I don't know if it matters, my docker is rootless.

drAlberT commented 12 months ago

I have a similar problem with the artifact from a docker build.

Doing docker save $IMAGE | gzip -c > artifact.tgz creates the file in the project root, but I can't find a way to remove it after the artifact has been uploaded.

Tried to use $CI_BUILDS_DIR hoping to operate inside .gitlab-ci-local/build/ dir but no luck.

firecow commented 11 months ago
---
test-job:
  image:
    name: alpine
  script:
    - echo "hello" > test.txt
    - chmod 777 test.txt
    - chown 0:0 text.txt
  artifacts:
    paths:
      - test.txt

Because #NoArtifactsToSource decorator is missing the test.txt is copied to the hosts cwd with 777 file permissions, but not 0:0 ownership, which is expected.

Can you try to simplify your example, so it's easier for me to reproduce?

airone-x1 commented 11 months ago

OK, thanks , so it's a kind of RTFM bug ;) , I haven't seen https://github.com/firecow/gitlab-ci-local#the-noartifactstosource-decorator

On the other side Docker executor copies artifacts to and from .gitlab-ci-local/artifacts . Your exemple it's a docker executor so artefacts shouldn't have been written in .gitlab-ci-locals/artifacts_ ?

firecow commented 11 months ago

In the very beginning gitlab-ci-local was pure shell executor without build folder isolating capabilities.

So artifacts to source is a ghost from the past, that will be opt-in in the next 5.x.x release

It will be written to both locations.

airone-x1 commented 11 months ago

opt-in in the next 5.x.x release is perfect, thank you

Until then we can use an alias gcl='gitlab-ci-local --no-artifacts-to-source' (no success trying to define this option in $HOME/.gitlab-ci-local)