Skip to content

Commit

Permalink
Merge pull request #108 from powli/main
Browse files Browse the repository at this point in the history
Generate images for 6.5
  • Loading branch information
shyim authored Aug 21, 2023
2 parents b9ef4cc + 212b90f commit 8d8434a
Show file tree
Hide file tree
Showing 93 changed files with 873 additions and 1,484 deletions.
680 changes: 232 additions & 448 deletions .github/workflows/shopware.yml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Dockerfile_65.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ghcr.io/shyim/shopware-nginx:${PHP_VERSION}

COPY --from=composer/composer:2-bin /composer /usr/local/bin/composer

RUN cd /var/www/ &&\
rm -rf /var/www/html && \
composer create-project shopware/production:${SHOPWARE_VERSION} /var/www/html && \
cd /var/www/html && \
mkdir /state && \
touch /var/www/html/install.lock && \
echo "${SHOPWARE_VERSION}" > /shopware_version && \
chown -R www-data:www-data /var/www

VOLUME /state /var/www/html/custom/plugins /var/www/html/files /var/www/html/var/log /var/www/html/public/theme /var/www/html/public/media /var/www/html/public/bundles /var/www/html/public/sitemap /var/www/html/public/thumbnail /var/www/html/config/jwt
138 changes: 91 additions & 47 deletions generate_shopware.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
<?php

$opts = [
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: PHP'
]
]
];
$context = stream_context_create($opts);
$shopwareTags = json_decode(
file_get_contents('https://api.github.com/repos/shopware/platform/tags', false, $context),
true
);

$shopwareVersions = $shopwareVersions = json_decode(
file_get_contents('https://update-api.shopware.com/v1/releases/install?major=6'),
true
);;

$findShopwareDL = static function ($version) use ($shopwareVersions): string {
foreach ($shopwareVersions as $shopwareVersion) {
if ($shopwareVersion['version'] === $version) {
return $shopwareVersion['uri'];
}
}

return "";
};

$phpMatrix = [
'6.5.0.0' => ['8.1', '8.2'],
'6.4.18.0' => ['8.0', '8.1', '8.2'],
'6.4.7.0' => ['8.0', '8.1'],
'6.4.1.2' => ['8.0'],
'default' => [],
];
$phpIndex = json_decode(file_get_contents('index_php.json'), true);

$dockerTpl = file_get_contents('Dockerfile.template');
$shopwareVersions = json_decode(file_get_contents('https://update-api.shopware.com/v1/releases/install?major=6'), true);
$usedTags = [];


Expand All @@ -28,25 +55,33 @@

exec('rm -rf shopware');

foreach($shopwareVersions as $shopwareVersion) {
// skip very old versions
if (version_compare('6.4.2.0', $shopwareVersion['version'], '>')) {
foreach ($shopwareTags as $shopwareTag) {
$dockerTpl = file_get_contents('Dockerfile.template');
$tagName = ltrim($shopwareTag['name'], 'v');

// skip rc versions
if (str_contains($tagName, '-rc')) {
continue;
}

if (!version_compare('6.5.0', $shopwareVersion['version'], '>=')) {
// skip very old versions
if (version_compare('6.4.10.0', $tagName, '>')) {
continue;
}

if (version_compare('6.5.0.0', $tagName, '<=')) {
$dockerTpl = file_get_contents('Dockerfile_65.template');
}

$versionTags = [];

if (!isset($usedTags['latest'])) {
$usedTags['latest'] = 1;
$versionTags[] = 'latest';
}

preg_match('/^\d+\.\d+/', $shopwareVersion['version'], $majorVersion);
preg_match('/^\d+\.\d+.\d+/', $shopwareVersion['version'], $minorVersion);
preg_match('/^\d+\.\d+/', $tagName, $majorVersion);
preg_match('/^\d+\.\d+.\d+/', $tagName, $minorVersion);

if (!isset($usedTags[$majorVersion[0]])) {
$versionTags[] = $majorVersion[0];
Expand All @@ -58,34 +93,43 @@
$usedTags[$minorVersion[0]] = 1;
}

if (!isset($usedTags[$shopwareVersion['version']])) {
$versionTags[] = $shopwareVersion['version'];
if (!isset($usedTags[$tagName])) {
$versionTags[] = $tagName;
}

$phpVersions = [];

foreach($phpMatrix as $matrix => $versions) {
if ($matrix === 'default' || version_compare($shopwareVersion['version'], $matrix, ">=")) {
foreach ($phpMatrix as $matrix => $versions) {
if ($matrix === 'default' || version_compare($tagName, $matrix, ">=")) {
$phpVersions = $versions;
break;
}
}

foreach($phpVersions as $i => $php) {
$folder = 'shopware/' . $php . '/' . $shopwareVersion['version'];
foreach ($phpVersions as $i => $php) {
$folder = 'shopware/' . $php . '/' . $tagName;

if (!file_exists($folder)) {
mkdir($folder, 0777, true);
if (!mkdir($folder, 0777, true) && !is_dir($folder)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $folder));
}
}

$replacements = [
'${PHP_VERSION}' => $phpIndex[$php] ?? $php,
'${SHOPWARE_VERSION}' => $shopwareVersion['version'],
'${SHOPWARE_DL}' => $shopwareVersion['uri'],
'${SHOPWARE_VERSION}' => $tagName,
'${SHOPWARE_DL}' => $findShopwareDL($tagName),
];

file_put_contents($folder . '/Dockerfile', str_replace(array_keys($replacements), $replacements, $dockerTpl));
file_put_contents($folder . '/Dockerfile.cli', str_replace(array_keys($replacements), $replacements, $dockerTpl) . PHP_EOL . 'ENV RUN_NGINX=0' . PHP_EOL . 'HEALTHCHECK NONE');
file_put_contents(
$folder . '/Dockerfile.cli',
str_replace(
array_keys($replacements),
$replacements,
$dockerTpl
) . PHP_EOL . 'ENV RUN_NGINX=0' . PHP_EOL . 'HEALTHCHECK NONE'
);

$workflowTpl = <<<'TPL'
Expand Down Expand Up @@ -115,43 +159,43 @@
run: docker buildx build -f #DOCKER_FILE#.cli --platform linux/amd64,linux/arm64 #CLI_TAGS# --push .
TPL;

$tags = '';
$cliTags = '';
$tags = '';
$cliTags = '';

foreach($versionTags as $tag) {
// default php version is always lowest
if ($i === 0 ) {
$tags .= '--tag ghcr.io/shyim/shopware:' . $tag . ' ';
$tags .= '--tag shyim/shopware:' . $tag . ' ';
foreach ($versionTags as $tag) {
// default php version is always lowest
if ($i === 0) {
$tags .= '--tag ghcr.io/shyim/shopware:' . $tag . ' ';
$tags .= '--tag shyim/shopware:' . $tag . ' ';

$cliTags .= '--tag ghcr.io/shyim/shopware:cli-' . $tag . ' ';
$cliTags .= '--tag shyim/shopware:cli-' . $tag . ' ';
}
$cliTags .= '--tag ghcr.io/shyim/shopware:cli-' . $tag . ' ';
$cliTags .= '--tag shyim/shopware:cli-' . $tag . ' ';
}

$tags .= '--tag ghcr.io/shyim/shopware:' . $tag . '-php' . $php . ' ';
$tags .= '--tag shyim/shopware:' . $tag . '-php' . $php . ' ';
$tags .= '--tag ghcr.io/shyim/shopware:' . $tag . '-php' . $php . ' ';
$tags .= '--tag shyim/shopware:' . $tag . '-php' . $php . ' ';

$cliTags .= '--tag ghcr.io/shyim/shopware:cli-' . $tag . '-php' . $php . ' ';
$cliTags .= '--tag shyim/shopware:cli-' . $tag . '-php' . $php . ' ';
$cliTags .= '--tag ghcr.io/shyim/shopware:cli-' . $tag . '-php' . $php . ' ';
$cliTags .= '--tag shyim/shopware:cli-' . $tag . '-php' . $php . ' ';

if ($php !== $phpIndex[$php] ?? $php) {
$tags .= '--tag ghcr.io/shyim/shopware:' . $tag . '-php' . $phpIndex[$php] . ' ';
$tags .= '--tag shyim/shopware:' . $tag . '-php' . $phpIndex[$php] . ' ';
if ($php !== $phpIndex[$php] ?? $php) {
$tags .= '--tag ghcr.io/shyim/shopware:' . $tag . '-php' . $phpIndex[$php] . ' ';
$tags .= '--tag shyim/shopware:' . $tag . '-php' . $phpIndex[$php] . ' ';

$cliTags .= '--tag ghcr.io/shyim/shopware:cli-' . $tag . '-php' . $phpIndex[$php] . ' ';
$cliTags .= '--tag shyim/shopware:cli-' . $tag . '-php' . $phpIndex[$php] . ' ';
$cliTags .= '--tag ghcr.io/shyim/shopware:cli-' . $tag . '-php' . $phpIndex[$php] . ' ';
$cliTags .= '--tag shyim/shopware:cli-' . $tag . '-php' . $phpIndex[$php] . ' ';
}
}
}

$replacements = [
'#JOBKEY#' => str_replace('.', '_', 'shopware-' . $shopwareVersion['version'] . '-' . $php),
'#NAME#' => $shopwareVersion['version'] . ' with PHP ' . $php,
'#TAGS#' => $tags,
'#CLI_TAGS#' => $cliTags,
'#DOCKER_FILE#' => './' . $folder . '/Dockerfile'
];
$replacements = [
'#JOBKEY#' => str_replace('.', '_', 'shopware-' . $shopwareTag['name'] . '-' . $php),
'#NAME#' => $shopwareTag['name'] . ' with PHP ' . $php,
'#TAGS#' => $tags,
'#CLI_TAGS#' => $cliTags,
'#DOCKER_FILE#' => './' . $folder . '/Dockerfile'
];

$workflow .= str_replace(array_keys($replacements), $replacements, $workflowTpl);
$workflow .= str_replace(array_keys($replacements), $replacements, $workflowTpl);
}
}

Expand Down
17 changes: 0 additions & 17 deletions shopware/8.0/6.4.10.0/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions shopware/8.0/6.4.10.0/Dockerfile.cli

This file was deleted.

17 changes: 0 additions & 17 deletions shopware/8.0/6.4.10.1/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions shopware/8.0/6.4.10.1/Dockerfile.cli

This file was deleted.

17 changes: 0 additions & 17 deletions shopware/8.0/6.4.11.0/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions shopware/8.0/6.4.11.0/Dockerfile.cli

This file was deleted.

17 changes: 0 additions & 17 deletions shopware/8.0/6.4.11.1/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions shopware/8.0/6.4.11.1/Dockerfile.cli

This file was deleted.

Loading

0 comments on commit 8d8434a

Please sign in to comment.