This repository was archived by the owner on Nov 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile.integration
More file actions
154 lines (130 loc) · 4.01 KB
/
Dockerfile.integration
File metadata and controls
154 lines (130 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Multi-stage build for better caching and smaller final image
FROM php:8.4.8-cli-alpine3.20@sha256:8d60c4303cfc7aad89ab800e9603096c8f630bcb552697401f4761caaec03cfb AS base
# Install only required runtime dependencies
RUN apk add --no-cache \
curl \
libxml2 \
icu-libs
# Build stage for installing extensions
FROM base AS builder
# Install build dependencies
RUN apk add --no-cache \
$PHPIZE_DEPS \
curl-dev \
libxml2-dev \
icu-dev \
oniguruma-dev
# Install only required PHP extensions
RUN docker-php-ext-install -j$(nproc) \
ctype \
mbstring \
curl \
fileinfo \
pcntl \
&& pecl install pcov \
&& docker-php-ext-enable pcov
# Clean up build dependencies
RUN apk del $PHPIZE_DEPS \
&& rm -rf /tmp/* /var/cache/apk/*
# Composer stage
FROM composer:2.8 AS composer-stage
# Dependency installation stage
FROM builder AS dependencies
WORKDIR /app
# Copy composer files for better layer caching
COPY composer.json composer.lock ./
# Copy composer binary from composer stage
COPY --from=composer-stage /usr/bin/composer /usr/bin/composer
# Install dependencies with optimal flags (including dev for tests)
RUN composer install \
--no-interaction \
--no-scripts \
--no-autoloader \
--prefer-dist \
--no-progress \
&& composer clear-cache
# Final stage
FROM base AS final
# Install minimal runtime tools
RUN apk add --no-cache \
git \
unzip
# Copy PHP extensions from builder
COPY --from=builder /usr/local/lib/php/extensions /usr/local/lib/php/extensions
COPY --from=builder /usr/local/etc/php/conf.d /usr/local/etc/php/conf.d
# Configure PHP
RUN echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini \
&& echo "pcov.directory=/app/src" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini \
&& echo "memory_limit=512M" >> /usr/local/etc/php/conf.d/memory-limit.ini
# Ensure composer is executable and in PATH
ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
WORKDIR /app
# Copy dependencies from dependency stage
COPY --from=dependencies /app/vendor /app-vendor/vendor
# Copy application code
COPY . .
# Copy composer for runtime use
COPY --from=composer-stage /usr/bin/composer /usr/bin/composer
# Ensure composer is executable
RUN chmod +x /usr/bin/composer
# Generate optimized autoloader with source files
RUN cp -r /app-vendor/vendor . \
&& /usr/bin/composer dump-autoload --optimize --classmap-authoritative
# Create wait script using printf to avoid heredoc parsing issues
RUN printf '#!/bin/sh\n\
set -e\n\
\n\
# Debug info\n\
echo "Container starting..."\n\
echo "Current directory: $(pwd)"\n\
echo "PHP version: $(php -v | head -n1)"\n\
echo "Composer location: $(which composer || echo "composer not in PATH")"\n\
\n\
# Restore vendor if needed\n\
if [ ! -d "/app/vendor" ] || [ -z "$(ls -A /app/vendor 2>/dev/null)" ]; then\n\
echo "Restoring vendor directory..."\n\
cp -r /app-vendor/vendor /app/\n\
fi\n\
\n\
# Create PEST temp directory to avoid warnings\n\
mkdir -p /app/vendor/pestphp/pest/.temp\n\
\n\
# Parallel service checks\n\
check_openfga() {\n\
echo "Checking OpenFGA..."\n\
timeout=30\n\
until curl -sf http://openfga:8080/healthz >/dev/null 2>&1; do\n\
timeout=$((timeout - 1))\n\
if [ $timeout -le 0 ]; then\n\
echo "OpenFGA failed to start"\n\
return 1\n\
fi\n\
sleep 1\n\
done\n\
echo "OpenFGA ready"\n\
}\n\
\n\
check_otel() {\n\
echo "Checking OTEL Collector (optional)..."\n\
# Just try once - if it'"'"'s not there, that'"'"'s fine\n\
if curl -sf http://otel-collector:13133/ >/dev/null 2>&1; then\n\
echo "OTEL Collector ready"\n\
else\n\
echo "OTEL Collector not available (continuing without it)"\n\
fi\n\
return 0\n\
}\n\
\n\
# Run checks in parallel\n\
check_openfga &\n\
PID1=$!\n\
check_otel &\n\
PID2=$!\n\
\n\
# Wait for critical service\n\
wait $PID1 || exit 1\n\
wait $PID2\n\
\n\
echo "Starting tests..."\n\
exec /usr/bin/composer test:integration:run\n' > /wait-and-test.sh && chmod +x /wait-and-test.sh
CMD ["/wait-and-test.sh"]