问题描述
我正在构建一个工作流来测试、构建 docker 镜像并将其推送到 GitHub 私有存储库。
我曾经在 ububntu-latest 上运行该操作,并使用特定的 PHP 版本和一些环境构建,但由于它与生产构建不同,因此出现了一些问题。
我想使用与生产相同的环境,所以我使用了一个利用 PHP7.3 的容器,我在 ubuntu-latest 上运行操作后调用了它
我现在面临的问题是在 Composer 成功更新后,我无法调用默认步骤 tp build docker image。我在“设置 QEMU”步骤中收到此错误
Error: Unable to locate executable file: docker. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
这是我的行动
name: Build and Publish Docker for development on: push: branches: development jobs: build: runs-on: ubuntu-latest container: image: egahmad/PHP7.3-laravel-apache-development # volumes: # - app_files:/var/www/html/ services: MysqL: image: MysqL:5.7 env: MysqL_DATABASE: db MysqL_USER: user MysqL_PASSWORD: secret MysqL_ROOT_PASSWORD: secret ports: - 3306:3306 options: --health-cmd="MysqLadmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - uses: actions/checkout@v2 - name: Verify TNT MysqL connection run: | MysqL --version sudo apt-get install -y default-MysqL-client MysqL --host MysqL --port ${{ job.services.MysqL.ports['3306'] }} -uuser -psecret -e "SHOW DATABASES" - name: copy .env run: | PHP -r "file_exists('.env') || copy('.env.cicd','.env');" - name: Install Dependencies run: composer install - name: Generate key run: PHP artisan key:generate - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache - name: Execute tests (Unit and Feature tests) via PHPUnit env: MysqL_DATABASE: db DB_USERNAME: user DB_PASSWORD: secret DB_PORT: ${{ job.services.MysqL.ports[3306] }} run: vendor/bin/PHPunit - name: Set up QEMU uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Login to GitHub Container Registry uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_SECRET }} - name: Build and push uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile push: true target: ci tags: ghcr.io/account/image:development build-args: | GITHUB_USER=${{ secrets.GITHUB_USERNAME }} GITHUB_PASSWORD=${{ secrets.CR_PAT }} - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }}
解决方法
docker
命令在 egahmad/php7.3-laravel-apache-development
上不可用,而且我不相信 qemu 步骤旨在在容器中运行(它们正在对内核进行更改)。要在 ubuntu-latest
主机上运行 qemu 步骤,我相信您需要 remove the container 部分。如果步骤需要此环境,您可以尝试将作业分解为多个作业,其中一些步骤在容器中运行,而其他步骤直接在主机上运行。
如果您在 Github Actions 中执行所有这些步骤,因为您的 docker 构建需要已经创建的二进制文件,我建议您迁移到多阶段构建。第一个阶段是您的 egahmad/php7.3-laravel-apache-development
映像,运行您当前在 GHA 中执行的步骤,然后第二个阶段将从第一个阶段而不是构建上下文进行复制。