docker – Permission Denied on shell script execution – GitHub Actions

I am trying to deploy my Elastic Beanstalk Application using GitHub Actions (for CD purposes). Before running the job responsible for deployment, I am building and pushing docker images required for my app to work on DockerHub.

The problem I am facing is that I am having a Permission Denied error after building and running the image from GitHub ( GitHub Actions YAML file ) that I am not having when I am building and running the images locally.

Here is how my GitHub Actions yml file, Dockerfile and sh file look like:

# .github/workflows/deploy-to-staging.yml
name: Deploy to Staging

    branches: ( master )

    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
      # Login to DockerHub
      - name: Docker Login
        uses: docker/login-action@v1.8.0
          username: ${{secrets.DOCKERHUB_USERNAME}}
          password: ${{secrets.DOCKERHUB_TOKEN}}
          logout: true
      # build, tag and push Nginx image to DockerHub
      - name: Build nginx image
        run: docker build -t repo/nginx-staging -f docker/nginx/staging/Dockerfile .
      - name: Tag Image
        run: docker tag repo/nginx-staging repo/nginx-staging:latest
      - name: Push to dockerhub
        run: docker push repo/nginx-staging:latest
      # build, tag and push Backend image to DockerHub
      - name: grant permissions to shell script
        run: chmod +x ./docker/backend/staging/
      - name: Build Backend image
        run: docker build -t repo/backend-staging -f docker/backend/staging/Dockerfile .
      - name: Tag Image
        run: docker tag repo/backend-staging repo/backend-staging:latest
      - name: Push to dockerhub
        run: docker push repo/backend-staging:latest
      # Move staging at root location
      - name: Move Dockerrun file to root
        run: mv aws/staging/
      - name: Generate deployment package
        run: zip
      # Deploy to EB
      - name: Deploy to EB
        uses: einaregilsson/beanstalk-deploy@v10
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY }}
          aws_secret_key: ${{ secrets.AWS_ACCESS_SECRET_KEY }}
          application_name: rrw-webapp
          environment_name: staging-env
          region: eu-west-3
          version_label: ${{ github.run_number }}
          version_description: ${{ github.run_number }}
      - name: Move Dockerrun file back to its original location
        run: mv aws/staging/

Here is my Dockerfile:

FROM python:3.7.7

ADD ./backend/requirements.txt /app/backend/

RUN pip install --upgrade pip
RUN pip install gunicorn
RUN pip install -r backend/requirements.txt

ADD ./docker /app/docker
ADD ./backend /app/backend

CMD ("/bin/bash","-c","chmod +x /app/docker/backend/staging/ && /app/docker/backend/staging/")

And finally my sh file :


until cd /app/backend
    echo "Waiting for server volume..."

until ./ migrate
    echo "Waiting for db to be ready..."
    sleep 2

./ collectstatic --noinput

gunicorn RRWProject.wsgi --bind --workers 4 --threads 4

The Permission Denied error happens when docker tries to execute the migrate command.

What I have tried so far:

  • chmod my file locally before pushing to github with :
> chmod +x docker/backend/staging/
  • chmod my file from the github actions file as it is shown above
  • run git update-index before committing my files:
git update-index --chmod=+x docker/backend/staging/
  • simply running the following from my dockerfile:
CMD ("sh","docker/backend/staging/")

Is there anything I missed out to make it work ?