Skip to content

Commit b4a0f29

Browse files
author
Jonathan Visser
committed
Pre-install magento2-static-deploy binary in Docker image
- Add elgentos/magento2-static-deploy binary to /opt in Dockerfile - Simplify HighPerformanceStaticDeployTask to use pre-installed binary - Remove version configuration and runtime download logic - Update tests to reflect simplified implementation
1 parent f1cf008 commit b4a0f29

3 files changed

Lines changed: 8 additions & 91 deletions

File tree

ci/build/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ RUN curl -sS https://getcomposer.org/installer | php -- --2.2 --filename=compose
117117
# Use version 1 for main composer binary
118118
RUN rm -f /usr/local/bin/composer; ln -s /usr/local/bin/composer2 /usr/local/bin/composer
119119

120+
# Install elgentos magento2-static-deploy binary for high-performance static content deployment
121+
RUN curl -sL -o /opt/magento2-static-deploy \
122+
https://github.com/elgentos/magento2-static-deploy/releases/latest/download/magento2-static-deploy-linux-amd64 \
123+
&& chmod +x /opt/magento2-static-deploy
124+
120125
# Set python3 as default python executable
121126
RUN ln -s /usr/bin/python3 /usr/local/bin/python
122127

src/Deployer/Task/Build/HighPerformanceStaticDeployTask.php

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,22 @@
1919
*/
2020
class HighPerformanceStaticDeployTask extends TaskBase
2121
{
22-
private const BINARY_URL_VERSIONED = 'https://github.com/elgentos/magento2-static-deploy/releases/download/%s/magento2-static-deploy-linux-amd64';
23-
private const BINARY_URL_LATEST = 'https://github.com/elgentos/magento2-static-deploy/releases/latest/download/magento2-static-deploy-linux-amd64';
24-
private const DEFAULT_VERSION = 'latest';
22+
private const BINARY_PATH = '/opt/magento2-static-deploy';
2523

2624
public function configure(Configuration $config): void
2725
{
2826
if (!$this->isEnabled($config)) {
2927
return;
3028
}
3129

32-
$version = $this->getVersion($config);
33-
34-
task('magento:deploy:assets', function () use ($version) {
35-
within('{{release_or_current_path}}', function () use ($version) {
36-
run(sprintf('curl -sL -o /tmp/magento2-static-deploy %s', $this->getBinaryUrl($version)));
37-
run('chmod +x /tmp/magento2-static-deploy');
38-
});
39-
30+
task('magento:deploy:assets', function () {
4031
$themes = get('magento_themes', []);
4132
$themeArgs = $this->buildThemeArgs($themes);
4233
$locales = get('static_content_locales', 'en_US');
4334
$contentVersion = get('content_version', time());
4435

4536
within('{{release_or_current_path}}', function () use ($themeArgs, $locales, $contentVersion) {
46-
run("/tmp/magento2-static-deploy --force --area=frontend --area=adminhtml $themeArgs --content-version=$contentVersion --verbose $locales");
37+
run(self::BINARY_PATH . " --force --area=frontend --area=adminhtml $themeArgs --content-version=$contentVersion --verbose $locales");
4738
});
4839
})->select('stage=build');
4940
}
@@ -58,25 +49,6 @@ public function isEnabled(Configuration $config): bool
5849
?? false;
5950
}
6051

61-
public function getVersion(Configuration $config): string
62-
{
63-
$variables = $config->getVariables();
64-
$buildVariables = $config->getVariables('build');
65-
66-
return $variables['high_performance_static_deploy_version']
67-
?? $buildVariables['high_performance_static_deploy_version']
68-
?? self::DEFAULT_VERSION;
69-
}
70-
71-
public function getBinaryUrl(string $version): string
72-
{
73-
if ($version === 'latest') {
74-
return self::BINARY_URL_LATEST;
75-
}
76-
77-
return sprintf(self::BINARY_URL_VERSIONED, $version);
78-
}
79-
8052
/**
8153
* @param array<string, string> $themes
8254
*/

tests/Unit/Deployer/Task/Build/HighPerformanceStaticDeployTaskTest.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -61,66 +61,6 @@ public function testIsEnabledReturnsFalseWhenExplicitlyDisabled(): void
6161
$this->assertFalse($this->task->isEnabled($config));
6262
}
6363

64-
public function testGetVersionReturnsDefaultWhenNotConfigured(): void
65-
{
66-
$config = $this->createMock(Configuration::class);
67-
$config->method('getVariables')->willReturn([]);
68-
69-
$this->assertSame('latest', $this->task->getVersion($config));
70-
}
71-
72-
public function testGetVersionReturnsConfiguredVersion(): void
73-
{
74-
$config = $this->createMock(Configuration::class);
75-
$config->method('getVariables')
76-
->willReturnCallback(fn(string $stage = 'all') => match ($stage) {
77-
'all' => ['high_performance_static_deploy_version' => '1.0.0'],
78-
default => [],
79-
});
80-
81-
$this->assertSame('1.0.0', $this->task->getVersion($config));
82-
}
83-
84-
public function testGetVersionReturnsBuildVersionWhenNotInAllVariables(): void
85-
{
86-
$config = $this->createMock(Configuration::class);
87-
$config->method('getVariables')
88-
->willReturnCallback(fn(string $stage = 'all') => match ($stage) {
89-
'build' => ['high_performance_static_deploy_version' => '2.0.0'],
90-
default => [],
91-
});
92-
93-
$this->assertSame('2.0.0', $this->task->getVersion($config));
94-
}
95-
96-
public function testGetBinaryUrlReturnsLatestUrl(): void
97-
{
98-
$result = $this->task->getBinaryUrl('latest');
99-
100-
$this->assertSame(
101-
'https://github.com/elgentos/magento2-static-deploy/releases/latest/download/magento2-static-deploy-linux-amd64',
102-
$result
103-
);
104-
}
105-
106-
public function testGetBinaryUrlReturnsVersionedUrl(): void
107-
{
108-
$result = $this->task->getBinaryUrl('0.0.8');
109-
110-
$this->assertSame(
111-
'https://github.com/elgentos/magento2-static-deploy/releases/download/0.0.8/magento2-static-deploy-linux-amd64',
112-
$result
113-
);
114-
}
115-
116-
public function testGetBinaryUrlWithDifferentVersion(): void
117-
{
118-
$result = $this->task->getBinaryUrl('1.2.3');
119-
120-
$this->assertStringContainsString('1.2.3', $result);
121-
$this->assertStringContainsString('magento2-static-deploy-linux-amd64', $result);
122-
}
123-
12464
public function testBuildThemeArgsWithSingleTheme(): void
12565
{
12666
$themes = ['Vendor/theme' => 'nl_NL en_US'];

0 commit comments

Comments
 (0)