Skip to content

Commit 64609c3

Browse files
authored
MCLOUD-5603: [Investigation] Build images on travis for testing (#190)
1 parent bd8d388 commit 64609c3

File tree

11 files changed

+107
-25
lines changed

11 files changed

+107
-25
lines changed

.travis.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ language: php
1717
stages:
1818
- static-unit
1919
- integration
20+
- build-images
2021
- test
2122

2223
jobs:
@@ -47,6 +48,29 @@ jobs:
4748
php: '7.3'
4849
env:
4950
- TEST_SUITE=integration
51+
- stage: build-images
52+
env:
53+
- TEST_SUITE=build-images
54+
script:
55+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh tls; fi;
56+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh varnish; fi;
57+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh elasticsearch; fi;
58+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh nginx; fi;
59+
- script:
60+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh php 7.1-cli; fi;
61+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh php 7.1-fpm; fi;
62+
env:
63+
- TEST_SUITE=build-images
64+
- script:
65+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh php 7.2-cli; fi;
66+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh php 7.2-fpm; fi;
67+
env:
68+
- TEST_SUITE=build-images
69+
- script:
70+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh php 7.3-cli; fi;
71+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ]; then ./tests/travis/images.sh php 7.3-fpm; fi;
72+
env:
73+
- TEST_SUITE=build-images
5074
- stage: test
5175
php: '7.1'
5276
dist: xenial
@@ -60,10 +84,12 @@ jobs:
6084
env:
6185
- TEST_SUITE=functional
6286

63-
install: composer update
87+
install: if [[ $TEST_SUITE != "build-images" ]]; then composer update; fi;
6488

6589
before_script:
66-
- sudo sysctl -w vm.max_map_count=262144
90+
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ] && [ $TEST_SUITE == "build-images" ]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; fi;
91+
- if [ $TEST_SUITE == "functional" ]; then sudo sysctl -w vm.max_map_count=262144; fi;
92+
- if [ $TEST_SUITE == "functional" ]; then cp codeception.dist.yml codeception.yml && sed -i "s/use_generated_images:\ false/use_generated_images:\ true/" codeception.yml; fi;
6793

6894
script:
6995
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ] && [ $TEST_SUITE == "functional" ]; then ./tests/travis/functional.sh; fi;

codeception.dist.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ modules:
2424
composer_magento_username: "%REPO_USERNAME%"
2525
composer_magento_password: "%REPO_PASSWORD%"
2626
composer_github_token: "%GITHUB_TOKEN%"
27+
use_generated_images: false
28+
version_generated_images: "%TRAVIS_BUILD_NUMBER%"
2729
printOutput: false
2830
Magento\CloudDocker\Test\Functional\Codeception\Docker:
2931
system_magento_dir: "%Magento.docker.settings.system.magento_dir%"

images/redis/3.2/Dockerfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

images/redis/4.0/Dockerfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

images/redis/5.0/Dockerfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Test/Functional/Acceptance/AbstractCest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function _before(\CliTester $I): void
3131
$I->addDependencyToComposer('magento/magento-cloud-docker', '1.1.99');
3232

3333
$I->addEceToolsGitRepoToComposer();
34-
$I->addDependencyToComposer('magento/ece-tools', 'dev-develop as 2002.01.99');
34+
$I->addDependencyToComposer('magento/ece-tools', 'dev-develop as 2002.1.99');
3535

3636
$I->composerUpdate();
3737
}

src/Test/Functional/Acceptance/AcceptanceCest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AcceptanceCest extends AbstractCest
2121
public function testProductionMode(\CliTester $I): void
2222
{
2323
$I->runEceDockerCommand('build:compose --mode=production');
24+
$I->replaceImagesWithGenerated();
2425
$I->startEnvironment();
2526
$I->runDockerComposeCommand('run build cloud-build');
2627
$I->runDockerComposeCommand('run deploy cloud-deploy');
@@ -43,6 +44,7 @@ public function testCustomHost(\CliTester $I): void
4344
$I->runEceDockerCommand('build:compose --mode=production --host=magento2.test --port=8080'),
4445
'Command build:compose failed'
4546
);
47+
$I->replaceImagesWithGenerated();
4648
$I->startEnvironment();
4749
$I->assertTrue($I->runDockerComposeCommand('run build cloud-build'), 'Build phase failed');
4850
$I->assertTrue($I->runDockerComposeCommand('run deploy cloud-deploy'), 'Deploy phase failed');

src/Test/Functional/Acceptance/ElasticsearchCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function testElasticsearch(CliTester $I, Example $data)
4141
$command .= " --es-env-var={$data['param']['key']}={$data['param']['value']}";
4242
}
4343
$I->runEceDockerCommand($command);
44+
$I->replaceImagesWithGenerated();
4445
$I->startEnvironment();
4546
$I->runDockerComposeCommand('exec -T elasticsearch ps aux | grep elasticsearch');
4647
$I->seeInOutput('-Xms' . $data['xms']);

src/Test/Functional/Acceptance/SplitDbCest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function testSplitDbOnProductionMode(\CliTester $I): void
6262
$I->getExposedPort(MagentoDb::KEY_DB_QUOTE),
6363
$I->getExposedPort(MagentoDb::KEY_DB_SALES)
6464
));
65+
$I->replaceImagesWithGenerated();
6566
$I->startEnvironment();
6667
$I->runDockerComposeCommand('run build cloud-build');
6768
$I->runDockerComposeCommand('run deploy cloud-deploy');

tests/functional/Codeception/TestInfrastructure.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,33 @@ public function runEceDockerCommand(string $command): bool
390390
->wasSuccessful();
391391
}
392392

393+
/**
394+
* Replace magento images with cloud FT images in docker-compose.yml
395+
*
396+
* @return bool
397+
*/
398+
public function replaceImagesWithGenerated(): bool
399+
{
400+
401+
if (true === $this->_getConfig('use_generated_images')) {
402+
$this->debug('Tests use new generatedx Docker images');
403+
$path = $this->getWorkDirPath() . DIRECTORY_SEPARATOR . 'docker-compose.yml';
404+
405+
return (bool)file_put_contents(
406+
$path,
407+
preg_replace(
408+
'/(magento\/magento-cloud-docker-(\w+)):((\d+\.\d+|latest)(\-fpm|\-cli)?(\-\d+\.\d+))/i',
409+
'cloudft/$2:$4$5-' . $this->_getConfig('version_generated_images'),
410+
file_get_contents($path)
411+
)
412+
);
413+
}
414+
415+
$this->debug('Tests use default Docker images');
416+
417+
return true;
418+
}
419+
393420
/**
394421
* Runs composer update
395422
*

0 commit comments

Comments
 (0)