Skip to content

Commit 445d253

Browse files
committed
Attempt to use Docker for ImageMagick in CI
1 parent 8d6a118 commit 445d253

File tree

5 files changed

+72
-31
lines changed

5 files changed

+72
-31
lines changed

.github/workflows/php.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v2
2020

21-
- name: Install ImageMagick
22-
run: |
23-
sudo apt-get update
24-
sudo apt-get upgrade -y libjpeg-dev libpng-dev libgif-dev make wget
25-
wget https://www.imagemagick.org/download/ImageMagick.tar.gz
26-
tar xvzf ImageMagick.tar.gz
27-
cd ImageMagick-*
28-
./configure
29-
make
30-
sudo make install
31-
sudo ldconfig /usr/local/lib
32-
3321
- uses: shivammathur/setup-php@v2
3422
with:
3523
php-version: "${{ matrix.php-version }}"
@@ -46,8 +34,10 @@ jobs:
4634
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
4735
restore-keys: ${{ runner.os }}-composer-
4836

49-
- run: composer install
37+
- name: Setup
38+
run: |
39+
make install
5040
51-
- run: |
52-
# export IMAGEMAGICK_PATH="docker run --rm --volume `pwd`:`pwd` --workdir=`pwd` --entrypoint="`pwd`/docker_entrypoint.sh" --user=$UID:$GID dpokidov/imagemagick:latest magick"
53-
vendor/bin/phpunit
41+
- name: Test
42+
run: |
43+
make test

Makefile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SHELL := /bin/bash
2+
3+
IMAGEMAGICK_DOCKER_IMAGE = orbitale-imphp
4+
5+
# Helper vars
6+
_TITLE := "\033[32m[%s]\033[0m %s\n"
7+
_ERROR := "\033[31m[%s]\033[0m %s\n"
8+
9+
.DEFAULT_GOAL := help
10+
help: ## Show this help.
11+
@printf "\n Available commands:\n\n"
12+
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-25s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m## */[33m/'
13+
.PHONY: help
14+
15+
install: vendor imagemagick-docker ## Install composer dependencies and Docker image for testing
16+
.PHONY: install
17+
18+
start: ## Start Docker image for testing
19+
@docker start $(IMAGEMAGICK_DOCKER_IMAGE)
20+
.PHONY: start
21+
22+
stop: ## Stop testing Docker image
23+
@docker stop $(IMAGEMAGICK_DOCKER_IMAGE)
24+
.PHONY: stop
25+
26+
test: start ## Start Docker image for testing
27+
export IMAGEMAGICK_PATH="docker exec $(IMAGEMAGICK_DOCKER_IMAGE) `pwd`/docker_entrypoint.sh magick" && \
28+
vendor/bin/phpunit
29+
$(MAKE) stop
30+
.PHONY: test
31+
32+
vendor:
33+
@printf $(_TITLE) "Install" "Installing Composer dependencies"
34+
@composer update
35+
.PHONY: vendor
36+
37+
imagemagick-docker:
38+
@printf $(_TITLE) "Install" "Removing existing Docker image"
39+
@docker rm --force --volumes $(IMAGEMAGICK_DOCKER_IMAGE)
40+
@printf $(_TITLE) "Install" "Creating ImageMagick Docker image for development"
41+
@docker create \
42+
--name=$(IMAGEMAGICK_DOCKER_IMAGE) \
43+
--volume `pwd`:`pwd` \
44+
--workdir=`pwd` \
45+
--entrypoint="`pwd`/docker_entrypoint.sh" \
46+
dpokidov/imagemagick:latest \
47+
sleep 99999 \
48+
>/dev/null
49+
.PHONY: imagemagick-docker

Tests/CommandTest.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,18 @@ class CommandTest extends AbstractTestCase
2323
*/
2424
public function testWrongConvertDirs($path, $expectedMessage, $expectedException): void
2525
{
26-
$exception = '';
27-
$exceptionClass = '';
28-
2926
$path = \str_replace('\\', '/', $path);
3027
$expectedMessage = \str_replace('\\', '/', $expectedMessage);
31-
try {
32-
new Command($path);
33-
} catch (\Exception $e) {
34-
$exception = $e->getMessage();
35-
$exceptionClass = \get_class($e);
36-
}
37-
static::assertStringContainsString($expectedMessage, $exception);
38-
static::assertEquals($expectedException, $exceptionClass);
28+
$this->expectExceptionMessage($expectedMessage);
29+
$this->expectException($expectedException);
30+
31+
new Command($path);
3932
}
4033

4134
public function provideWrongConvertDirs(): ?\Generator
4235
{
43-
yield ['/this/is/a/dummy/dir', 'The specified path (/this/is/a/dummy/dir) is not a file.', MagickBinaryNotFoundException::class];
44-
yield ['./', 'The specified path (.) is not a file.', MagickBinaryNotFoundException::class];
36+
yield ['/this/is/a/dummy/dir', "ImageMagick does not seem to work well, the test command resulted in an error.\nExecution returned message: \"Command not found\"\nTo solve this issue, please run this command and check your error messages to see if ImageMagick was correctly installed:\n/this/is/a/dummy/dir -version", MagickBinaryNotFoundException::class];
37+
yield ['./', "The specified path (\"ImageMagick does not seem to work well, the test command resulted in an error.\nExecution returned message: \"Misuse of shell builtins\"\nTo solve this issue, please run this command and check your error messages to see if ImageMagick was correctly installed:\n. -version\") is not a file.\nYou must set the \"magickBinaryPath\" parameter as the main \"magick\" binary installed by ImageMagick.", MagickBinaryNotFoundException::class];
4538
}
4639

4740
/**

docker_entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
"$@"

src/Command.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ public function __construct(?string $magickBinaryPath = '')
8585
try {
8686
$code = $process->run();
8787
} catch (\Throwable $e) {
88-
throw new \RuntimeException('Could not check ImageMagick version', 1, $e);
88+
throw new MagickBinaryNotFoundException('Could not check ImageMagick version', 1, $e);
8989
}
9090

9191
if (0 !== $code || !$process->isSuccessful()) {
92-
throw new \InvalidArgumentException(\sprintf("ImageMagick does not seem to work well, the test command resulted in an error.\n"."Execution returned message: \"{$process->getExitCodeText()}\"\n"."To solve this issue, please run this command and check your error messages to see if ImageMagick was correctly installed:\n%s", $magickBinaryPath.' -version'));
92+
throw new MagickBinaryNotFoundException(\sprintf("ImageMagick does not seem to work well, the test command resulted in an error.\n"."Execution returned message: \"{$process->getExitCodeText()}\"\n"."To solve this issue, please run this command and check your error messages to see if ImageMagick was correctly installed:\n%s", $magickBinaryPath.' -version'));
9393
}
9494

9595
$this->ref = new References();
@@ -272,6 +272,13 @@ public function run(): CommandResponse
272272
}
273273
});
274274

275+
if ($code !== 0) {
276+
echo "\n>>> Command-line: « {$process->getCommandLine()} » \n";
277+
echo "\n>>> Output:\n>{$output}\n";
278+
echo "\n>>> Error:\n>{$error}\n";
279+
}
280+
281+
275282
return new CommandResponse($process, $code, $output, $error);
276283
}
277284

0 commit comments

Comments
 (0)