|
| 1 | +# Pilot |
| 2 | + |
| 3 | +A lightweight wrapper to help run PHP projects in Docker. |
| 4 | + |
| 5 | +Pilot wraps the `docker-compose` command line tool to allow you to use `.env` files and inject environment variables into your `docker-compose.yml` and `Dockerfile`, making it easier to set up and run projects. |
| 6 | + |
| 7 | +Pilot includes `Dockerfiles` to set up and run PHP 8.1 and 8.2, although with minimal extensions. You can use your own `docker-compose.yml` and `Dockerfiles` configuration with Pilot if you need more than this. |
| 8 | + |
| 9 | +Pilot is designed to help work with Docker containers in development environments, and is not recommended for use in production. |
| 10 | + |
| 11 | +## Getting started |
| 12 | + |
| 13 | +### Requirements |
| 14 | + |
| 15 | +You will need to have Docker and docker-compose installed on your machine for Pilot to work. |
| 16 | + |
| 17 | +### Installation |
| 18 | + |
| 19 | +Pilot is available through Composer: |
| 20 | + |
| 21 | +``` |
| 22 | +composer require savvywombat\pilot --dev |
| 23 | +``` |
| 24 | + |
| 25 | +To get started, you can copy the `docker-compose.yml` file shipped with Pilot: |
| 26 | + |
| 27 | +``` |
| 28 | +./vendor/bin/pilot install |
| 29 | +``` |
| 30 | + |
| 31 | +Or you can use your own `docker-compose.yml` to configure the services you need for your project. |
| 32 | + |
| 33 | +## Environment variables |
| 34 | + |
| 35 | +If you have a `.env` file in the same location as your `docker-compose.yml`, Pilot will import them, allowing you to use them in `docker-compose.yml` and `Dockerfiles`. |
| 36 | + |
| 37 | +Pilot uses the following environment variables with its default configuration: |
| 38 | + |
| 39 | +* WWWGROUP - the ID of the group to use for file permissions (defaults to the current user's group) |
| 40 | +* WWWUSER - the ID of the user to use for file permissions (defaults to the current user) |
| 41 | +* NODE_VERSION - the version of node installed on the default pilot service (defaults to 18) |
| 42 | +* HTTP_PORT - the external port to access the website hosted by the default pilot service (defaults to 80) |
| 43 | +* VITE_PORT - the external port to access the vite server hosted by the default pilot service (defaults to 5173) |
| 44 | + |
| 45 | +### Environment variables in docker-compose.yml |
| 46 | + |
| 47 | +You can use environment variables within your `docker-compose.yml`. It is recommended that you also define a default value to fall back on in case the variable is not defined in your `.env`. |
| 48 | + |
| 49 | +For example, in the default Pilot configuration, we define the ports on the default service like this: |
| 50 | + |
| 51 | +``` |
| 52 | + ports: |
| 53 | + - '${HTTP_PORT:-80}:80' |
| 54 | + - '${VITE_PORT:-5173}:5173' |
| 55 | +``` |
| 56 | + |
| 57 | +If no `HTTP_PORT` has been defined in the environment when starting the services with `pilot up`, then the port would default to 80. |
| 58 | + |
| 59 | +However, if you defined `HTTP_PORT=8080` in your `.env`, then 8080 be the port exposed for forwarding. |
| 60 | + |
| 61 | +### Environment variables in Dockerfiles |
| 62 | + |
| 63 | +Similarly, it is possible to use environment variables in your Dockerfiles, so that you can build your services to run with specific configurations. |
| 64 | + |
| 65 | +## Commands |
| 66 | + |
| 67 | +### Installing and building services |
| 68 | + |
| 69 | +Copy the default `docker-compose.yml` from Pilot into your project's root directory. |
| 70 | + |
| 71 | +``` |
| 72 | +./vendor/bin/pilot install |
| 73 | +``` |
| 74 | + |
| 75 | +Build the services defined in `docker-compose.yml`. This command is proxy for `docker-compose build` and so will accept the same arguments, such as `--no-cache`. |
| 76 | + |
| 77 | +``` |
| 78 | +./vendor/bin/pilot build-services |
| 79 | +``` |
| 80 | + |
| 81 | + |
| 82 | +### Accessing docker-compose commands |
| 83 | + |
| 84 | +Apart from `build`, all `docker-compose` commands are proxied without modification, and can be used with the same arguments. Using Pilot ensures that environment variables defined in your `.env` are honoured when running these commands. |
| 85 | + |
| 86 | +Run the services, or start them in listening mode: |
| 87 | + |
| 88 | +``` |
| 89 | +./vendor/bin/pilot up |
| 90 | +./vendor/bin/pilot up -d |
| 91 | +``` |
| 92 | + |
| 93 | +Stop the services. |
| 94 | + |
| 95 | +``` |
| 96 | +./vendor/bin/pilot down |
| 97 | +``` |
| 98 | + |
| 99 | +Stop the services and remove any volumes used by them: |
| 100 | + |
| 101 | +``` |
| 102 | +./vendor/bin/pilot down -v |
| 103 | +``` |
| 104 | + |
| 105 | +### Building and serving assets and content |
| 106 | + |
| 107 | +To build any assets in your project: |
| 108 | + |
| 109 | +``` |
| 110 | +./vendor/bin/pilot build |
| 111 | +``` |
| 112 | + |
| 113 | +To serve content as your develop: |
| 114 | + |
| 115 | +``` |
| 116 | +./vendor/bin/pilot serve |
| 117 | +``` |
| 118 | + |
| 119 | +### Additional commands |
| 120 | + |
| 121 | +Open a terminal session on the main service: |
| 122 | + |
| 123 | +``` |
| 124 | +./vendor/bin/pilot bash |
| 125 | +``` |
| 126 | + |
| 127 | +Run a php script on the main service: |
| 128 | + |
| 129 | +``` |
| 130 | +./vendor/bin/pilot php ... |
| 131 | +``` |
| 132 | + |
| 133 | +Run a Composer commands on the main service: |
| 134 | + |
| 135 | +``` |
| 136 | +./vendor/bin/pilot composer ... |
| 137 | +``` |
| 138 | + |
| 139 | +Run an npm command on the node service (this is by default the main service, but you can define a separate service in your `docker-compose.yml` for Node and set `NODE_SERVICE` to the name of your Node service): |
| 140 | + |
| 141 | +``` |
| 142 | +./vendor/bin/pilot npm ... |
| 143 | +``` |
| 144 | + |
| 145 | +## Support |
| 146 | + |
| 147 | +Please report issues using the [GitHub issue tracker](https://github.com/SavvyWombat/pilot/issues). You are also welcome to fork the repository and submit a pull request. |
| 148 | + |
| 149 | +## Licence |
| 150 | + |
| 151 | +This package is licensed under [The MIT License (MIT)](https://github.com/SavvyWombat/pilot/blob/master/LICENSE). |
0 commit comments