我正在尝试使用GitHub Actions(用于CD目的)部署我的Elastic Beanstalk应用程序。在运行负责部署的作业之前,我正在构建并推送Docker镜像以使我的应用程序在DockerHub上运行所需的环境。
但我遇到了一个问题,我在从GitHub中构建和运行图像时遇到了“Permission Denied”错误,而在本地构建和运行镜像时却没有出现此类问题。
以下是我的GitHub Actions yml文件、Dockerfile和sh文件的样式:
迄今为止我尝试过的方法:
但我遇到了一个问题,我在从GitHub中构建和运行图像时遇到了“Permission Denied”错误,而在本地构建和运行镜像时却没有出现此类问题。
以下是我的GitHub Actions yml文件、Dockerfile和sh文件的样式:
# .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/
这是我的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"]
最后是我的 sh 文件 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
Permission Denied
错误会在docker尝试执行`.manage.py migrate`命令时发生。迄今为止我尝试过的方法:
- 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"]
有什么我疏忽了的地方需要补充,以使它能够正常工作吗?
manage.py
可执行吗? - astrochunCMD
应该至少能够正常工作;但是您正在解决错误的问题。根据您自己的描述,权限问题出现在manage.py
而不是 shell 脚本上。 - tripleee