diff --git a/.castor/docker.php b/.castor/docker.php index d19b336..1f3162f 100644 --- a/.castor/docker.php +++ b/.castor/docker.php @@ -295,6 +295,24 @@ function workers_stop(): void stop(profiles: ['worker']); } +#[AsTask(description: 'Push images cache to the registry', namespace: 'docker', name: 'push', aliases: ['push'])] +function push(): void +{ + // Ensure docker buildx is enabled + + // Generate bake file + $composeFile = context()->data['docker_compose_files']; + + foreach ($composeFile as $file) { + $path = variable('root_dir') . '/infrastructure/docker/' . $file; + $content = file_get_contents($path); + // This does not work as we don't have a yaml parser + $data = \yaml_parse($content); + } + + // Run bake +} + #[AsContext(default: true)] function create_default_context(): Context { diff --git a/.home/.gitignore b/.home/.gitignore new file mode 100644 index 0000000..f4c3747 --- /dev/null +++ b/.home/.gitignore @@ -0,0 +1,2 @@ +/* +!.gitignore \ No newline at end of file diff --git a/infrastructure/docker/docker-compose.builder.yml b/infrastructure/docker/docker-compose.builder.yml index b4f70d9..017b0e0 100644 --- a/infrastructure/docker/docker-compose.builder.yml +++ b/infrastructure/docker/docker-compose.builder.yml @@ -1,13 +1,13 @@ -volumes: - builder-data: {} - services: builder: build: context: services/php target: builder + cache_from: + - "type=registry,ref=${REGISTRY:-}builder:cache" depends_on: - postgres + user: "${USER_ID}:${USER_ID}" environment: - COMPOSER_MEMORY_LIMIT=-1 - UID=${USER_ID} @@ -17,9 +17,10 @@ services: - CONTINUOUS_INTEGRATION # Travis CI, Cirrus CI - BUILD_NUMBER # Jenkins, TeamCity - RUN_ID # TaskCluster, dsari + - HOME=/home/app volumes: - - "builder-data:/home/app" - "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache" - "../..:/var/www:cached" + - "../../.home:/home/app:cached" profiles: - default diff --git a/infrastructure/docker/docker-compose.worker.yml b/infrastructure/docker/docker-compose.worker.yml index 135f4c6..9ec7312 100644 --- a/infrastructure/docker/docker-compose.worker.yml +++ b/infrastructure/docker/docker-compose.worker.yml @@ -4,11 +4,19 @@ x-services-templates: build: context: services/php target: worker + cache_from: + - "${REGISTRY:-}worker:cache" depends_on: - postgres #- rabbitmq + user: "${USER_ID}:${USER_ID}" volumes: - "../..:/var/www:cached" + - "../../.home:/home/app:cached" + labels: + - "docker-starter.worker.${PROJECT_NAME}=true" + environment: + - HOME=/home/app profiles: - default - worker diff --git a/infrastructure/docker/docker-compose.yml b/infrastructure/docker/docker-compose.yml index 67b3d09..e71c77a 100644 --- a/infrastructure/docker/docker-compose.yml +++ b/infrastructure/docker/docker-compose.yml @@ -15,12 +15,17 @@ services: build: context: services/php target: frontend + cache_from: + - "type=registry,ref=${REGISTRY:-}frontend:cache" + user: "${USER_ID}:${USER_ID}" depends_on: - postgres volumes: - "../..:/var/www:cached" + - "../../.home:/home/app:cached" environment: - "PHP_VERSION=${PHP_VERSION}" + - HOME=/home/app profiles: - default labels: diff --git a/infrastructure/docker/services/php/Dockerfile b/infrastructure/docker/services/php/Dockerfile index 546c1a6..011f8b5 100644 --- a/infrastructure/docker/services/php/Dockerfile +++ b/infrastructure/docker/services/php/Dockerfile @@ -40,20 +40,10 @@ RUN apt-get update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* -# Fake user to maps with the one on the host -ARG USER_ID -COPY entrypoint / -RUN addgroup --gid $USER_ID app && \ - adduser --system --uid $USER_ID --home /home/app --shell /bin/bash app && \ - curl -Ls https://github.com/tianon/gosu/releases/download/1.17/gosu-amd64 | \ - install /dev/stdin /usr/local/bin/gosu && \ - sed "s/{{ application_user }}/app/g" -i /entrypoint - # Configuration COPY base/php-configuration /etc/php/${PHP_VERSION} WORKDIR /var/www -ENTRYPOINT [ "/entrypoint" ] FROM php-base as frontend @@ -77,7 +67,7 @@ RUN phpenmod app-default \ EXPOSE 80 -CMD ["runsvdir", "-P", "/etc/service"] +CMD ["runsvdir", "-P", "/var/www/infrastructure/docker/services/php/frontend/etc/service"] FROM php-base as worker @@ -104,16 +94,9 @@ RUN apt-get update \ # Config COPY builder/etc/. /etc/ COPY builder/php-configuration /etc/php/${PHP_VERSION} -RUN adduser app sudo \ - && mkdir /var/log/php \ - && chmod 777 /var/log/php \ - && phpenmod app-default \ - && phpenmod app-builder # Composer COPY --from=composer/composer:2.7.1 /usr/bin/composer /usr/bin/composer -RUN mkdir -p "/home/app/.composer/cache" \ - && chown app: /home/app/.composer -R # Third party tools ENV PATH="$PATH:/var/www/tools/bin" diff --git a/infrastructure/docker/services/php/entrypoint b/infrastructure/docker/services/php/entrypoint deleted file mode 100755 index 1f15e84..0000000 --- a/infrastructure/docker/services/php/entrypoint +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -e -set -u - -if [ $(id -u) != 0 ]; then - echo "Running this image as non root is not allowed" - exit 1 -fi - -: "${UID:=0}" -: "${GID:=${UID}}" - -if [ "$#" = 0 ]; then - set -- "$(command -v bash 2>/dev/null || command -v sh)" -l -fi - -if [ "$UID" != 0 ]; then - usermod -u "$UID" "{{ application_user }}" >/dev/null 2>/dev/null && { - groupmod -g "$GID" "{{ application_user }}" >/dev/null 2>/dev/null || - usermod -a -G "$GID" "{{ application_user }}" >/dev/null 2>/dev/null - } - set -- gosu "${UID}:${GID}" "${@}" -fi - -exec "$@" diff --git a/infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf b/infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf index 2d69c60..d3d7efa 100644 --- a/infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf +++ b/infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf @@ -1,5 +1,4 @@ -user nginx; -pid /var/run/nginx.pid; +pid /tmp/nginx.pid; daemon off; error_log /proc/self/fd/2; include /etc/nginx/modules-enabled/*.conf; @@ -25,6 +24,12 @@ http { gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml; + client_body_temp_path /tmp/nginx-client_body_temp_path; + fastcgi_temp_path /tmp/nginx-fastcgi_temp_path; + proxy_temp_path /tmp/nginx-proxy_temp_path; + scgi_temp_path /tmp/nginx-scgi_temp_path; + uwsgi_temp_path /tmp/nginx-uwsgi_temp_path; + server { listen 0.0.0.0:80; root /var/www/application/public; diff --git a/infrastructure/docker/services/php/frontend/etc/service/.gitignore b/infrastructure/docker/services/php/frontend/etc/service/.gitignore new file mode 100644 index 0000000..999fe25 --- /dev/null +++ b/infrastructure/docker/services/php/frontend/etc/service/.gitignore @@ -0,0 +1 @@ +*/supervise \ No newline at end of file diff --git a/infrastructure/docker/services/php/frontend/php-configuration/fpm/php-fpm.conf b/infrastructure/docker/services/php/frontend/php-configuration/fpm/php-fpm.conf index 38b5901..3b74d34 100644 --- a/infrastructure/docker/services/php/frontend/php-configuration/fpm/php-fpm.conf +++ b/infrastructure/docker/services/php/frontend/php-configuration/fpm/php-fpm.conf @@ -1,11 +1,8 @@ [global] -pid = /var/run/php-fpm.pid error_log = /proc/self/fd/2 daemonize = no [www] -user = app -group = app listen = 127.0.0.1:9000 pm = dynamic pm.max_children = 25