Add environment variables for client OS/arch and client user UID/GID
When using Docker Compose for development setup, you often need to tweak the configuration to vary on Linux, macOS, and Windows. And some services you would like to run with the same UID/GID as your current client user.
To help with that, we introduce four new environment variables while parsing the configuration files:
COMPOSE_CLIENT_OS: set to Go'sruntime.GOOSCOMPOSE_CLIENT_ARCH: set to Go'sruntime.GOARCHCOMPOSE_CLIENT_UID: set to the current users UIDCOMPOSE_CLIENT_GUID: set to the current users GID
This way, we can now have a Docker Compose setup like this:
compose.yaml:
services:
php:
image: php
volumes:
- .:/code
user: ${COMPOSE_CLIENT_UID}:${COMPOSE_CLIENT_GID}
web:
image: apache
extends:
file: compose.${COMPOSE_CLIENT_OS}.yaml
service: web
compose.linux.yaml:
services:
web:
environment:
VIRTUAL_HOST: mysite.local
compose.darwin.yaml:
services:
web:
environment:
VIRTUAL_HOST: mysite.docker
Closes #11820.
This is basically the same I proposed as https://github.com/compose-spec/compose-go/pull/572 which was rejected as this introduce portability issues.
Also, runtime.GOARCH is very specific to golang, I'd prefer we rely on uname values. But I don't understand the use-case for this one. Would you like a Linux container to run with reference to some OSX or Windows -specific file vs the native one?