I'm building a workflow to test, build a docker image and push it to GitHub private repository.
I used to run the action on ububntu-latest and use a specific PHP version and some environment builds but there were some problems due to the fact that it's not identical to the production build.
I wanted to use the same environment as production so I have used a container that utilizes php7.3 and I called that after running the action on ubuntu-latest
The issue I'm facing now is after a successful composer update I can't call the default step tp build docker image. I get this error on "Set up QEMU" step
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.
Here's my action
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 }}
The
dockercommand is not available onegahmad/php7.3-laravel-apache-development, and I don't believe the qemu steps are designed to run within a container (they're making changes to the kernel). To run the qemu steps on theubuntu-latesthost, I believe you'd need to remove the container section. If steps require this environment, you can try breaking up the job into multiple jobs, with some steps running in the container, and others running directly on the host.If you're going through all these steps in Github Actions because your docker build needs the binaries already created, I'd recommend migrating to a multi-stage build. The first stage would be your
egahmad/php7.3-laravel-apache-developmentimage, running the steps you currently perform in GHA, and then the second stage would copy from that first stage rather than the build context.