Skip to content

Commit fca4bb2

Browse files
Copilotstnguyen90
andcommitted
Create dedicated Dockerfile.test with multi-stage build for test dependencies
Co-authored-by: stnguyen90 <1477010+stnguyen90@users.noreply.github.com>
1 parent 731125d commit fca4bb2

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,5 @@ jobs:
2323
- name: Run container structure test
2424
run: |
2525
docker build -t appwrite-base-test .
26-
# Create a temporary Dockerfile to add tests to the image for testing
27-
cat > Dockerfile.test <<EOF
28-
FROM appwrite-base-test
29-
COPY tests /tests
30-
EOF
3126
docker build -f Dockerfile.test -t appwrite-base-test-with-tests .
3227
container-structure-test test --image appwrite-base-test-with-tests --config tests.yaml

Dockerfile.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Build stage for Composer dependencies
2+
FROM composer:latest AS composer-stage
3+
4+
WORKDIR /app
5+
6+
# Copy composer.json and install dependencies
7+
COPY tests/composer.json /app/composer.json
8+
RUN composer install --no-dev --no-interaction --optimize-autoloader
9+
10+
# Test image stage - uses the repository's main Dockerfile as base
11+
# The base image will be built and tagged as appwrite-base-test by the workflow
12+
FROM appwrite-base-test AS test
13+
14+
# Copy Composer binary (for reference, though not needed if dependencies are pre-installed)
15+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
16+
17+
# Copy installed dependencies from composer stage
18+
COPY --from=composer-stage /app/vendor /tests/vendor
19+
20+
# Copy test files
21+
COPY tests /tests
22+
23+
# Set working directory
24+
WORKDIR /tests

tests.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ commandTests:
8585
command: "sh"
8686
args: ["/tests/run-image-conversion-test.sh"]
8787
expectedOutput:
88-
- "Installing Composer..."
89-
- "Installing dependencies..."
9088
- "Test 1: Converting PNG to WebP..."
9189
- "✓ PNG to WebP conversion successful"
9290
- "Test 2: Converting WebP to PNG..."

tests/run-image-conversion-test.sh

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
#!/bin/sh
22

3-
# Install Composer if not already installed
4-
if ! command -v composer >/dev/null 2>&1; then
5-
echo "Installing Composer..."
6-
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
3+
# Check if dependencies are already installed
4+
if [ ! -d "/tests/vendor" ]; then
5+
# Install Composer if not already installed
6+
if ! command -v composer >/dev/null 2>&1; then
7+
echo "Installing Composer..."
8+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
9+
if [ $? -ne 0 ]; then
10+
echo "✗ Failed to install Composer"
11+
exit 1
12+
fi
13+
fi
14+
15+
# Install dependencies
16+
echo "Installing dependencies..."
17+
cd /tests
18+
composer install --no-dev --quiet
719
if [ $? -ne 0 ]; then
8-
echo "✗ Failed to install Composer"
20+
echo "✗ Failed to install dependencies"
921
exit 1
1022
fi
1123
fi
1224

13-
# Install dependencies
14-
echo "Installing dependencies..."
15-
cd /tests
16-
composer install --no-dev --quiet
17-
if [ $? -ne 0 ]; then
18-
echo "✗ Failed to install dependencies"
19-
exit 1
20-
fi
21-
2225
# Run the test
2326
php /tests/image-conversion-test.php

0 commit comments

Comments
 (0)