This is a test repository that I'm using to document the process of building a Github Action that builds a customised Docker image, according to the action's input.
The example repository that uses this action is located here: https://github.com/g105b/example-test-docker-build-action.
This technique is used in php-actions so that each action can specify its own version of PHP, which extensions are installed, and the version of the component being run inside the action (Composer, PHPUnit, etc.). It is greatly simplified in this repository to help me and others when building similar actions.
- Inputs
php_version
andname
are specified in theaction.yml
of this repository. - The inputs are passed to two bash scripts that execute within the context of the repository.
- The first script,
docker-build.bash
creates aDockerfile
on-the-fly, which sets the environment for the runner according to the inputs. In this case, it sets theGREETER_NAME
environment variable according to the passed in actioninput.name
. - The first script then builds the customised Docker image, tags it with a unique tag name and pushes it to Github Container Registry.
- The second script,
greet.bash
simply runs the Docker image with the specific tag, which should be pre-cached in Github's action runner. The Docker image executes a PHP script that greets the user according to what is stored within the environment variable.
This is a very trivial example, but it covers the basic requirements of what is needed within the php-actions repositories: a slightly customised Docker image according to action input, and caching of the custom Docker image for fast builds.
If you found this repository helpful, please consider [sponsoring the developer][sponsor].