Repository: CodelyTV/php-ddd-example (language: php)

Issue:
Unable to create the "cache" directory
Using ubuntu 20.04, after the `make build` and going http://localhost:8030/health-check, it shows an error:

`Unable to create the "cache" directory (/app/apps/mooc/backend/var/cache/test).`

The exception is thrown at `/app/vendor/symfony/http-kernel/Kernel.php` line 637

The owner of the folders is my user (uid 1000):

```shell
$ docker exec -it codelytv-php_ddd_skeleton-mooc_backend-php /bin/bash
bash-5.1# ls -la /app/apps/mooc/backend
total 28
drwxrwxr-x    7 1000     1000          4096 Dec  5 14:52 .
drwxrwxr-x    4 1000     1000          4096 Oct  2 09:56 ..
drwxrwxr-x    2 1000     1000          4096 Oct  2 09:56 bin
drwxrwxr-x    4 1000     1000          4096 Oct  2 09:56 config
drwxrwxr-x    2 1000     1000          4096 Oct  2 09:56 public
drwxrwxr-x    4 1000     1000          4096 Oct  2 09:56 src
drwxrwxr-x    3 1000     1000          4096 Oct  2 09:56 tests
bash-5.1#
```

I tried to create a folder in a tmp folder with:

```php
mkdir('/tmp/test-folder', 0777);
```

the result:

```shell
$ docker exec -it codelytv-php_ddd_skeleton-mooc_backend-php /bin/bash
bash-5.1# ls -la /tmp
total 16
drwxrwxrwt    1 root     root          4096 Dec  5 15:04 .
drwxr-xr-x    1 root     root          4096 Dec  5 14:51 ..
drwxr-xr-x    3 root     root          4096 Dec  5 14:50 apcu
drwxrwxrwx    2 www-data www-data      4096 Dec  5 15:04 test-folder
```

So it seems like the php proccess is running with www-data user (instead of mine: 1000)

The problem occurs with master and php8.1 branches


Discussion / hints:

Fix patch:
diff --git a/Dockerfile b/Dockerfile
index 096c79bb9..41f981d1c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -27,6 +27,11 @@ RUN docker-php-ext-enable \
         apcu \
         opcache
 
-RUN curl -sS https://get.symfony.com/cli/installer | bash && mv /root/.symfony/bin/symfony /usr/local/bin/symfony
+RUN curl -sS https://get.symfony.com/cli/installer | bash -s - --install-dir /usr/local/bin
 
 COPY etc/infrastructure/php/ /usr/local/etc/php/
+
+# allow non-root users have home
+RUN mkdir -p /opt/home
+RUN chmod 777 /opt/home
+ENV HOME /opt/home
diff --git a/Makefile b/Makefile
index e79984f36..f3139b75b 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ composer-require-module: INTERACTIVE=-ti --interactive
 .PHONY: composer
 composer composer-install composer-update composer-require composer-require-module: composer-env-file
 	@docker run --rm $(INTERACTIVE) --volume $(current-dir):/app --user $(id -u):$(id -g) \
-		composer:2.2.6 $(CMD) \
+		composer:2.2 $(CMD) \
 			--ignore-platform-reqs \
 			--no-ansi
 
@@ -69,7 +69,7 @@ destroy: CMD=down
 # Usage: `make doco CMD="build --parallel --pull --force-rm --no-cache"`
 .PHONY: doco
 doco start stop destroy: composer-env-file
-	@docker-compose $(CMD)
+	UID=${shell id -u} GID=${shell id -g} docker-compose $(CMD)
 
 .PHONY: rebuild
 rebuild: composer-env-file
diff --git a/docker-compose.yml b/docker-compose.yml
index 5c6782794..69e1555b2 100755
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -53,6 +53,7 @@ services:
 
   backoffice_backend_php:
     container_name: codelytv-php_ddd_skeleton-backoffice_backend-php
+    user: "${UID}:${GID}"
     build:
       context: .
       dockerfile: Dockerfile
@@ -70,6 +71,7 @@ services:
 
   backoffice_frontend_php:
     container_name: codelytv-php_ddd_skeleton-backoffice_frontend-php
+    user: "${UID}:${GID}"
     build:
       context: .
       dockerfile: Dockerfile
@@ -88,6 +90,7 @@ services:
 
   mooc_backend_php:
     container_name: codelytv-php_ddd_skeleton-mooc_backend-php
+    user: "${UID}:${GID}"
     build:
       context: .
       dockerfile: Dockerfile


Test patch: