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 ?