GitLab CI/CD permission denied when mounting volume for docker

A. Vreeswijk

For the past few days I have been trying to setup a GitLab pipeline for my Laravel application, so that it installs, tests, builds and deploys to my kubernetes cluster. However, when i am trying to install composer using the following line:

docker run --volume $(pwd):/app --rm $CONTAINER_REGISTRY_URL/internal/docker/composer:${COMPOSER_TAG} install $COMPOSER_ARGS

I am getting a permission denied error on the $(pwd) command. This is the error:

/scripts-66-218/step_script: eval: line 153: /builds/my-project/laravel-api: Permission denied

I am not an expert in GitLab CI/CD, but I do know my ways with dockers etc, but in this case I don't exactly know why I am getting this permission denied. The files are readable for every user, so I am not sure, but that seems correct. This is the full composer pipeline code:

composer-install-production:
  extends: .custom-composer-install
  variables:
      COMPOSER_ARGS: "--ignore-platform-reqs --no-ansi --no-interaction --no-progress --optimize-autoloader --prefer-dist --no-dev --no-scripts"
  before_script:
    - echo $CONTAINER_REGISTRY_PASSWORD | docker login -u $CONTAINER_REGISTRY_USERNAME $CONTAINER_REGISTRY_URL --password-stdin
    - cp .env.pipeline .env
  only:
    - tags


.custom-composer-install:
  extends: .composer-install
  variables:
    COMPOSER_TAG: "2"
    COMPOSER_SSH_DEPLOY_KEY: $GITLAB_RUNNER_RSA
  artifacts:
    paths:
      - .env
      - public/
      - vendor/
      - storage/

.composer-install:

  # Default variables
  variables:
    COMPOSER_TAG:             "prestissimo" # Change composer tag to use a differrent version. 
    COMPOSER_ARGS:            "--ignore-platform-reqs --no-ansi --no-interaction --no-progress --optimize-autoloader --prefer-dist" # If provided, composer arguments are added to the install.
    COMPOSER_AUTHJSON:        "" # If provided, authentication can be added to install private packages like Nova.
    COMPOSER_SSH_DEPLOY_KEY:  "" # If provided, adds an SSH key to the composer image to access private packages.

  stage: install

  before_script:
    - echo $CONTAINER_REGISTRY_PASSWORD | docker login -u $CONTAINER_REGISTRY_USERNAME $CONTAINER_REGISTRY_URL --password-stdin

  script:
    - $(pwd)
    - >
      if [ "$COMPOSER_AUTHJSON" != "" ]; then
        echo $COMPOSER_AUTHJSON > auth.json
      fi
    - >
      if [ "$COMPOSER_SSH_DEPLOY_KEY" == "" ]; then
        docker run --volume $PWD:/app --rm $CONTAINER_REGISTRY_URL/internal/docker/composer:${COMPOSER_TAG} install $COMPOSER_ARGS
      else
        docker run --volume $PWD:/app --rm -e "SSH_DEPLOY_KEY=$COMPOSER_SSH_DEPLOY_KEY" $CONTAINER_REGISTRY_URL/internal/docker/composer:${COMPOSER_TAG} install --ignore-platform-reqs $COMPOSER_ARGS
      fi

  artifacts:
    name: "$CI_JOB_ID-$CI_BUILD_REF_NAME"
    expire_in: 1 day
    paths:
      - vendor/

  interruptible: true

And the script crashes on this line:

- $(pwd)

Does somebody know what is going on here and how to fix this?

VonC

I would first test if using pws instead of $(pwd) (which executes a command in a subshell) would work:

script:
    - pwd
    - >
      ...

You would find $(pwd) when you want to assign the current working directory to a variable, as in here.

ci_app_path=$(pwd) && echo "INFO: current directory: $ci_app_path"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Permission denied when mounting Docker volume in OSX

docker mounting volume with permission denied

Docker mounting volume. Permission denied

How to solve permission denied when mounting volume during docker run command?

Docker: Got "permission denied" error at volume mounting directory

Docker rootfs_linux.go permission denied when mounting /proc

Docker compose permission denied with volume

Permission denied error when rebuilding docker image with volume

Docker not starting, volume permission denied error

Chown permission denied while Docker volume binding

Permission denied error with docker-compose volume

when mounting volume, directory is empty in docker

Why does docker prompt "Permission denied" when backing up the data volume?

docker-compose issue: Permission denied when attempting to create/mount volume

Permission denied when python app tries to write log file into shared volume in docker

permission denied when adding ssh to gitlab

Docker non mounting volume

Permission denied when executing docker commands from Gitlab CI/CD pipeline

mounting a docker volume to a docker container

Docker Compose Make Shared Volume Writable Permission Denied

Airflow on Docker: Can't Write to Volume (Permission Denied)

Unable to access jarfile error when mounting a volume in a Docker

Docker permission problems when doing volume mapping

Permission denied when running a container (docker 1.12.5)

Permission denied when writing logs in Docker

When mounting /var/run/docker.sock into a container, which file system is used for volume mounting?

Kubernetes docker volume mounting option

Docker container not mounting volume properly

Docker Volume not mounting any files