Skip to content

Commit 211b26f

Browse files
committed
feat(registry): prepare images and compose file to be able to use a docker registry for cache
1 parent fed9df7 commit 211b26f

File tree

10 files changed

+45
-53
lines changed

10 files changed

+45
-53
lines changed

.castor/docker.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ function workers_stop(): void
269269
]);
270270
}
271271

272+
#[AsTask(description: 'Push images cache to the registry', namespace: 'docker', name: 'push', aliases: ['push'])]
273+
function push(): void
274+
{
275+
// Ensure docker buildx is enabled
276+
277+
// Generate bake file
278+
$composeFile = context()->data['docker_compose_files'];
279+
280+
foreach ($composeFile as $file) {
281+
$path = variable('root_dir') . '/infrastructure/docker/' . $file;
282+
$content = file_get_contents($path);
283+
// This does not work as we don't have a yaml parser
284+
$data = \yaml_parse($content);
285+
}
286+
287+
// Run bake
288+
}
289+
272290
#[AsContext(default: true)]
273291
function create_default_context(): Context
274292
{

.home/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*
2+
!.gitignore
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
version: '3.7'
22

3-
volumes:
4-
builder-data: {}
5-
63
services:
74
builder:
85
build:
96
context: services/php
107
target: builder
8+
cache_from:
9+
- "type=registry,ref=${REGISTRY:-}builder:cache"
1110
depends_on:
1211
- postgres
12+
user: "${USER_ID}:${USER_ID}"
1313
environment:
1414
- COMPOSER_MEMORY_LIMIT=-1
1515
- UID=${USER_ID}
@@ -19,7 +19,8 @@ services:
1919
- CONTINUOUS_INTEGRATION # Travis CI, Cirrus CI
2020
- BUILD_NUMBER # Jenkins, TeamCity
2121
- RUN_ID # TaskCluster, dsari
22+
- HOME=/home/app
2223
volumes:
23-
- "builder-data:/home/app"
2424
- "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache"
2525
- "../..:/var/www:cached"
26+
- "../../.home:/home/app:cached"

infrastructure/docker/docker-compose.worker.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ x-services-templates:
66
build:
77
context: services/php
88
target: worker
9+
cache_from:
10+
- "${REGISTRY:-}worker:cache"
911
depends_on:
1012
- postgres
1113
#- rabbitmq
14+
user: "${USER_ID}:${USER_ID}"
1215
volumes:
1316
- "../..:/var/www:cached"
17+
- "../../.home:/home/app:cached"
1418
labels:
1519
- "docker-starter.worker.${PROJECT_NAME}=true"
20+
environment:
21+
- HOME=/home/app
1622

1723
# services:
1824
# worker_messenger:

infrastructure/docker/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ services:
1515
build:
1616
context: services/php
1717
target: frontend
18+
cache_from:
19+
- "type=registry,ref=${REGISTRY:-}frontend:cache"
20+
user: "${USER_ID}:${USER_ID}"
1821
depends_on:
1922
- postgres
2023
volumes:
2124
- "../..:/var/www:cached"
25+
- "../../.home:/home/app:cached"
2226
environment:
2327
- "PHP_VERSION=${PHP_VERSION}"
28+
- HOME=/home/app
2429
labels:
2530
- "traefik.enable=true"
2631
- "traefik.http.routers.${PROJECT_NAME}-frontend.rule=Host(${PROJECT_DOMAINS})"

infrastructure/docker/services/php/Dockerfile

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,10 @@ RUN apt-get update \
4040
&& apt-get clean \
4141
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
4242

43-
# Fake user to maps with the one on the host
44-
ARG USER_ID
45-
COPY entrypoint /
46-
RUN addgroup --gid $USER_ID app && \
47-
adduser --system --uid $USER_ID --home /home/app --shell /bin/bash app && \
48-
curl -Ls https://github.com/tianon/gosu/releases/download/1.17/gosu-amd64 | \
49-
install /dev/stdin /usr/local/bin/gosu && \
50-
sed "s/{{ application_user }}/app/g" -i /entrypoint
51-
5243
# Configuration
5344
COPY base/php-configuration /etc/php/${PHP_VERSION}
5445

5546
WORKDIR /var/www
56-
ENTRYPOINT [ "/entrypoint" ]
5747

5848
FROM php-base as frontend
5949

@@ -77,7 +67,7 @@ RUN phpenmod app-default \
7767

7868
EXPOSE 80
7969

80-
CMD ["runsvdir", "-P", "/etc/service"]
70+
CMD ["runsvdir", "-P", "/var/www/infrastructure/docker/services/php/frontend/etc/service"]
8171

8272
FROM php-base as worker
8373

@@ -104,16 +94,9 @@ RUN apt-get update \
10494
# Config
10595
COPY builder/etc/. /etc/
10696
COPY builder/php-configuration /etc/php/${PHP_VERSION}
107-
RUN adduser app sudo \
108-
&& mkdir /var/log/php \
109-
&& chmod 777 /var/log/php \
110-
&& phpenmod app-default \
111-
&& phpenmod app-builder
11297

11398
# Composer
11499
COPY --from=composer/composer:2.7.1 /usr/bin/composer /usr/bin/composer
115-
RUN mkdir -p "/home/app/.composer/cache" \
116-
&& chown app: /home/app/.composer -R
117100

118101
# Third party tools
119102
ENV PATH="$PATH:/var/www/tools/bin"

infrastructure/docker/services/php/entrypoint

Lines changed: 0 additions & 26 deletions
This file was deleted.

infrastructure/docker/services/php/frontend/etc/nginx/nginx.conf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
user nginx;
2-
pid /var/run/nginx.pid;
1+
pid /tmp/nginx.pid;
32
daemon off;
43
error_log /proc/self/fd/2;
54
include /etc/nginx/modules-enabled/*.conf;
@@ -25,6 +24,12 @@ http {
2524
gzip_http_version 1.1;
2625
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
2726

27+
client_body_temp_path /tmp/nginx-client_body_temp_path;
28+
fastcgi_temp_path /tmp/nginx-fastcgi_temp_path;
29+
proxy_temp_path /tmp/nginx-proxy_temp_path;
30+
scgi_temp_path /tmp/nginx-scgi_temp_path;
31+
uwsgi_temp_path /tmp/nginx-uwsgi_temp_path;
32+
2833
server {
2934
listen 0.0.0.0:80;
3035
root /var/www/application/public;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/supervise

infrastructure/docker/services/php/frontend/php-configuration/fpm/php-fpm.conf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
[global]
2-
pid = /var/run/php-fpm.pid
32
error_log = /proc/self/fd/2
43
daemonize = no
54

65
[www]
7-
user = app
8-
group = app
96
listen = 127.0.0.1:9000
107
pm = dynamic
118
pm.max_children = 25

0 commit comments

Comments
 (0)