Skip to content

Commit

Permalink
feat(registry): prepare images and compose file to be able to use a d…
Browse files Browse the repository at this point in the history
…ocker registry for cache
  • Loading branch information
joelwurtz committed Feb 27, 2024
1 parent fed9df7 commit 211b26f
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 53 deletions.
18 changes: 18 additions & 0 deletions .castor/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ function workers_stop(): void
]);
}

#[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
{
Expand Down
2 changes: 2 additions & 0 deletions .home/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*
!.gitignore
9 changes: 5 additions & 4 deletions infrastructure/docker/docker-compose.builder.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
version: '3.7'

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}
Expand All @@ -19,7 +19,8 @@ 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"
6 changes: 6 additions & 0 deletions infrastructure/docker/docker-compose.worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,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

# services:
# worker_messenger:
Expand Down
5 changes: 5 additions & 0 deletions infrastructure/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
labels:
- "traefik.enable=true"
- "traefik.http.routers.${PROJECT_NAME}-frontend.rule=Host(${PROJECT_DOMAINS})"
Expand Down
19 changes: 1 addition & 18 deletions infrastructure/docker/services/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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"
Expand Down
26 changes: 0 additions & 26 deletions infrastructure/docker/services/php/entrypoint

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/supervise
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 211b26f

Please sign in to comment.