Skip to content

Commit ba03851

Browse files
committed
First version of functionality for building Docker images. Still requires adding datadir to my.cnf. Must be tested with big databases.
1 parent 73b6cd4 commit ba03851

File tree

13 files changed

+294
-93
lines changed

13 files changed

+294
-93
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ auth.json
1111
!/var/log/
1212
/var/log/*
1313
!/var/log/.gitkeep
14+
!/var/tmp/
15+
/var/tmp/*
16+
!/var/tmp/.gitkeep
1417
/vendor/*

src/AWS/S3/Environment.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace DefaultValue\Dockerizer\AWS\S3;
66

77
/**
8-
* @FUTURE: Replace with Enum when system requirements change to PHP 8.1+
8+
* @TODO: Replace with Enum when system requirements change to PHP 8.1+
99
*/
1010
class Environment
1111
{

src/Console/Command/Composition/AbstractTestCommand.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ protected function cleanUp(string $projectRoot): void
8888
}
8989

9090
// Works much faster than `$this->filesystem->remove([$projectRoot]);`. Better for using in tests.
91-
$this->shell->run("rm -rf $projectRoot");
92-
$this->logger->info('Shutdown completed!');
91+
if (is_dir($projectRoot)) {
92+
$this->shell->mustRun("rm -rf $projectRoot");
93+
}
94+
95+
$this->logger->info('Cleanup completed!');
9396
}
9497

9598
/**

src/Console/Command/Docker/Mysql/GenerateMetadata.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected function configure(): void
8585
protected function execute(InputInterface $input, OutputInterface $output): int
8686
{
8787
$dockerContainerName = $input->getArgument(self::COMMAND_ARGUMENT_CONTAINER_NAME);
88+
/** @var array<string, mixed> $containerMetadata */
8889
$containerMetadata = $this->docker->containerInspect($dockerContainerName);
8990
$mysql = $this->mysql->initialize($dockerContainerName);
9091
$dbImage = $this->getDbImageFromEnv($mysql, $containerMetadata);
@@ -94,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9495
MysqlMetadataKeys::DB_IMAGE => $dbImage,
9596
MysqlMetadataKeys::ENVIRONMENT => $this->getEnvironment($containerMetadata),
9697
MysqlMetadataKeys::MY_CNF => $this->getMyCnf($mysql, $containerMetadata),
97-
MysqlMetadataKeys::DOCKER_IMAGE => $this->getTargetRegistry($input, $output, $mysql)
98+
MysqlMetadataKeys::CONTAINER_REGISTRY => $this->getTargetRegistry($input, $output, $mysql)
9899
];
99100

100101
$output->setVerbosity($output::VERBOSITY_NORMAL);
@@ -164,6 +165,7 @@ private function getMyCnf(Mysql $mysql, array $containerMetadata): string
164165

165166
if (str_ends_with($mount['Destination'], 'my.cnf')) {
166167
$process = $mysql->mustRun("cat {$mount['Destination']}", Shell::EXECUTION_TIMEOUT_SHORT, false);
168+
167169
return trim($process->getOutput());
168170
}
169171
}
@@ -198,7 +200,7 @@ private function getTargetRegistry(InputInterface $input, OutputInterface $outpu
198200
$output->writeln('Trying to determine Docker registry domain for this DB image...');
199201

200202
// Get from Docker image environment variables
201-
if ($registry = $mysql->getEnvironmentVariable(MysqlMetadataKeys::DOCKER_IMAGE)) {
203+
if ($registry = $mysql->getEnvironmentVariable(MysqlMetadataKeys::CONTAINER_REGISTRY)) {
202204
$output->writeln("Registry path defined in the Docker environment variables: $registry");
203205

204206
if ($input->isInteractive()) {
@@ -238,6 +240,9 @@ private function getTargetRegistry(InputInterface $input, OutputInterface $outpu
238240
private function askForImageRegistry(InputInterface $input, OutputInterface $output, Mysql $mysql): string
239241
{
240242
if (!$input->isInteractive()) {
243+
# === FOR TESTS ONLY ===
244+
return 'localhost:5000/' . uniqid('', false);
245+
241246
throw new \InvalidArgumentException(
242247
'In the non-interactive mode you must pass Docker registry to push image to!'
243248
);
@@ -251,7 +256,7 @@ private function askForImageRegistry(InputInterface $input, OutputInterface $out
251256
} catch (\Exception) {
252257
// phpcs:disable Generic.Files.LineLength.TooLong
253258
$output->writeln(
254-
'<warning>Environment variable "REGISTRY_DOMAIN" is not set! Enter full image name including a domain if needed!</warning>'
259+
'<error>Environment variable "REGISTRY_DOMAIN" is not set! Enter full image name including a domain if needed!</error>'
255260
);
256261
// phpcs:enable
257262
}
@@ -261,6 +266,8 @@ private function askForImageRegistry(InputInterface $input, OutputInterface $out
261266
'index .Config.Labels "com.docker.compose.project.working_dir"'
262267
);
263268

269+
// Check in the docker-compose.yaml. Just in case the user has not restarted composition
270+
// OR
264271
// Find repository, suggest pushing there
265272
if ($dockerComposeWorkdir) {
266273
try {
@@ -280,9 +287,10 @@ private function askForImageRegistry(InputInterface $input, OutputInterface $out
280287

281288
}
282289

290+
283291
// Just temporary test to see how it looks
284292
$output->writeln(
285-
'<warning>Environment variable "REGISTRY_DOMAIN" is not set! Enter full image name including a domain if needed!</warning>'
293+
'<error>Environment variable "REGISTRY_DOMAIN" is not set! Enter full image name including a domain if needed!</error>'
286294
);
287295
$foo = false;
288296

0 commit comments

Comments
 (0)