7

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

on:
  push:
    branches: [ master ]

jobs:
  deploy-to-staging:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      # Login to DockerHub
      - name: Docker Login
        uses: docker/login-action@v1.8.0
        with:
          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/wsgi-entrypoint.sh
      - 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 Dockerrun.aws.json at root location
      - name: Move Dockerrun file to root
        run: mv aws/staging/Dockerrun.aws.json Dockerrun.aws.json
      - name: Generate deployment package
        run: zip deploy-staging.zip Dockerrun.aws.json
      # Deploy to EB
      - name: Deploy to EB
        uses: einaregilsson/beanstalk-deploy@v10
        with:
          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 }}
          deployment_package: deploy-staging.zip
      - name: Move Dockerrun file back to its original location
        run: mv Dockerrun.aws.json aws/staging/

Here is my Dockerfile:

FROM python:3.7.7

WORKDIR /app
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/wsgi-entrypoint.sh && /app/docker/backend/staging/wsgi-entrypoint.sh"]

And finally my sh file wsgi-entrypoint.sh :

#!/bin/bash

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

until ./manage.py migrate
do
    echo "Waiting for db to be ready..."
    sleep 2
done

./manage.py collectstatic --noinput

gunicorn RRWProject.wsgi --bind 0.0.0.0:8000 --workers 4 --threads 4

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

What I have tried so far:

  • chmod my file locally before pushing to github with :
    > chmod +x docker/backend/staging/wsgi-entrypoint.sh
    
  • 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/wsgi-entrypoint.sh
    
  • simply running the following from my dockerfile:
    CMD ["sh","docker/backend/staging/wsgi-entrypoint.sh"]
    

Is there anything I missed out to make it work ?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
chlouska
  • 71
  • 1
  • 2
  • 3
    Um, is `manage.py` executable? – astrochun Mar 04 '21 at 00:54
  • Did you try executing the commands with SUDO? Source: https://stackoverflow.com/questions/57982945/how-to-apt-get-install-in-a-github-actions-workflow – GuiFalourd Mar 23 '21 at 18:25
  • 1
    Does this answer your question? [Permission Denied when executing python file in linux](https://stackoverflow.com/questions/32899919/permission-denied-when-executing-python-file-in-linux) – tripleee Jun 25 '22 at 10:30
  • To elaborate: The final `CMD` should definitely work, at the very least; but you are attacking the wrong problem. By your own description, the permission problem is with `manage.py`, not with the shell script. – tripleee Jan 14 '23 at 11:31

1 Answers1

1

Make sure to set the executable bit on the .py file:

In your docker file or entrypoint.sh:

chmod +x ./manage.py
jessehouwing
  • 106,458
  • 22
  • 256
  • 341