warpnet / salt-lint

A command-line utility that checks for best practices in SaltStack.
https://salt-lint.readthedocs.io/en/latest/
MIT License
152 stars 39 forks source link

docker WORKDIR nor writeable #260

Closed colttt closed 3 years ago

colttt commented 3 years ago

Describe the bug it looks like that the workdir is not writeable

$ cp -r $CI_PROJECT_DIR/states /data
cp: can't create directory '/data/states': Permission denied

The docker-file looks like:

WORKDIR /data
USER linter

but I guess it should look soemthing like that:

RUN mkdir -p /data
RUN chown linter /data
WORKDIR /data
USER linter

To Reproduce my gitlab ci-yaml config looks like:

image:
  name: warpnetbv/salt-lint
  entrypoint:
  - "/bin/bash"
  - "-c"
default:
  before_script:
  - cp -r $CI_PROJECT_DIR/states /data
stages:
- ".pre"
- Lint
- ".post"
linux:lint:
  stage: Lint
  needs: []
  tags:
  - docker
  script:
  - find /data -type f -name "*.sls" |xargs --no-run-if-empty salt-lint -x 201 -x
    207 -x 208 -x 204
  only:
  - branches
jbouter commented 3 years ago

Hi @colttt 👋🏻

I don't think you need to specify a workdir, and copy files over. The limitation might very well be GitLab not supporting the writable directory.

Our .gitlab-ci.yml looks as such, and works flawlessly:

"🧂 - Lint SaltStack":
  stage: lint
  image:
    name: warpnetbv/salt-lint:latest
    entrypoint: [ '/bin/bash', '-c' ]
  script:
    - find . -type f -name "*.sls" | xargs --no-run-if-empty salt-lint

In other words, if you don't copy over the files, you can run find in the current directory (in which GitLab already has the repo files).

colttt commented 3 years ago

thanks for that! it was the first time in gitlab-ci, thank you very much!

jbouter commented 3 years ago

You're most welcome. Glad you were able to resolve it! :-)