权限被拒绝执行 shell 脚本 - GitHub 操作

时间:2021-03-04 00:00:57

标签: docker github dockerfile sh github-actions

我正在尝试使用 GitHub 操作(用于 CD 目的)部署我的 Elastic Beanstalk 应用程序。在运行负责部署的作业之前,我正在构建和推送我的应用程序所需的 Docker 映像,以便在 DockerHub 上运行。

我面临的问题是,我在从 GitHub(GitHub 操作 YAML 文件)构建和运行图像后遇到了 Permission Denied 错误,而在本地构建和运行图像时却没有。< /p>

这是我的 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

当 docker 尝试执行 .manage.py migrate 命令时会发生 Permission Denied 错误。

到目前为止我尝试过的:

  • 在推送到 github 之前在本地 chmod 我的文件:
> chmod +x docker/backend/staging/wsgi-entrypoint.sh
  • 从 github 操作文件 chmod 我的文件,如上所示
  • 在提交我的文件之前运行 git update-index:
git update-index --chmod=+x docker/backend/staging/wsgi-entrypoint.sh
  • 只需从我的 dockerfile 运行以下内容:
CMD ["sh","docker/backend/staging/wsgi-entrypoint.sh"]

有什么我遗漏的地方吗?

0 个答案:

没有答案