DockerCommands
extends AbstractCommands
in package
Provides commands to update docker-compose.yml based on project's configurations.
Table of Contents
Constants
- DC_YML_FILE = 'docker-compose.yml'
- DC_YML_FILE_PREVIOUS = 'docker-compose.yml.prev'
- DEV_SUFFIX = '-dev'
- OPTS_YML_FILE = '.opts.yml'
Methods
- dockerRefreshConfiguration() : int
- Update docker-compose.yml file based on project's configurations.
- getConfigurationFile() : string
- Path to YAML configuration file containing command defaults.
- getJson() : array<string|int, mixed>
- Returns the JSON parsed content.
- getWorkingDir() : string
- Returns the current working directory.
- isWebsiteInstalled() : bool
- Check if the website is installed.
- getBin() : string
- Validate and return the path to given bin.
- getBinPath() : string
- Return the path to given bin.
- getConfigValue() : mixed|null
- Return the configuration value.
- getNodeBin() : string
- Validate and return the path to given bin from node packages.
- getNodeBinPath() : string
- Return the path to given bin from node packages.
- isJunit() : bool
- Check whether Junit option is being used, or env var is set.
- isSimulating() : bool
- Check if current command is being executed with option simulate.
- taskExecute() : CollectionBuilder
- Execute a command.
- taskProcess() : ReplaceBlock|CollectionBuilder
- Process the file.
- taskReplaceBlock() : ReplaceBlock|CollectionBuilder
- Replace block in a file.
- backupDockerComposeFile() : void
- Backup current docker-compose.yml to docker-compose.yml.prev.
- copyDockerComposeDefaultToProject() : void
- Copy ./resources/docker/default.yml file to docker-compose.yml inside project root directory.
- extractMajorMinorVersion() : string
- Converts from semantic version to "major.minor" version.
- getFinalImages() : array<string|int, string>
- Get final images to update docker-compose.yml.
- getProjectPhpFromWebsite() : array<string|int, mixed>
- Returns the Project's php service version information from the endpoint.
- getServiceDetailsFromResources() : array<string|int, string>
- Return the details for a service from ./resources/docker.
- getServiceImage() : string
- Get service image with version.
- getServicesImagesFromDockerCompose() : array<string|int, string>
- Get array of services with images and versions from docker-compose.yml.
- getServicesVersionsFromRequirements() : array<string|int, mixed>
- Get final services names with versions from requirements.
- getWarningMessages() : array<string|int, string>
- Get warning messages for versions on .opts.yml that not respect the minimum requirements.
- getWebsiteRequirements() : array<string|int, mixed>
- Returns the toolkit requirements from the endpoint.
- removeUnusedDcServices() : array<string|int, string>
- Remove services that do not exist in project info, requirements or .opts.yml.
- updateDockerComposeFile() : void
- Update docker-compose.yml.
- writeWarningMessages() : void
- Write all available warning messages.
Constants
DC_YML_FILE
public
mixed
DC_YML_FILE
= 'docker-compose.yml'
DC_YML_FILE_PREVIOUS
private
mixed
DC_YML_FILE_PREVIOUS
= 'docker-compose.yml.prev'
DEV_SUFFIX
private
mixed
DEV_SUFFIX
= '-dev'
OPTS_YML_FILE
private
mixed
OPTS_YML_FILE
= '.opts.yml'
Methods
dockerRefreshConfiguration()
Update docker-compose.yml file based on project's configurations.
public
dockerRefreshConfiguration() : int
This command allows developers to update the docker-compose.yml file taking in consideration:
- The service versions on the .opts.yml file (php_version, mysql_version, selenium_version, solr_version).
- The service versions currently on client's production.
- Quality Assurance minimum version requirements and defaults (https://digit-dqa.fpfis.tech.ec.europa.eu/requirements).
Notes: If a version is provided in .opts.yml, this one must be used (a warning message is displayed if the versions are non-compliant or outdated with Quality Assurance requirements) If no opts.yml is provided, the newer version from QA requirements or project production version will be used. In case of some information is not available, the images will be updated based on Quality Assurance default values.
Tags
Return values
int —The docker Refresh configuration status.
getConfigurationFile()
Path to YAML configuration file containing command defaults.
public
getConfigurationFile() : string
Command classes should implement this method.
Return values
string —Configuration file path.
getJson()
Returns the JSON parsed content.
public
getJson(string $filename[, bool $throwException = true ]) : array<string|int, mixed>
Parameters
- $filename : string
- $throwException : bool = true
-
If the file is not found.
Return values
array<string|int, mixed> —Json parsed content.
getWorkingDir()
Returns the current working directory.
public
getWorkingDir() : string
Return values
string —The current working directory.
isWebsiteInstalled()
Check if the website is installed.
public
isWebsiteInstalled() : bool
Return values
boolgetBin()
Validate and return the path to given bin.
protected
getBin(string $name) : string
Parameters
- $name : string
-
The bin to look for.
Tags
Return values
string —The bin path.
getBinPath()
Return the path to given bin.
protected
getBinPath(string $name) : string
Parameters
- $name : string
Return values
string —The path to given binary.
getConfigValue()
Return the configuration value.
protected
getConfigValue(string $key[, mixed|null $default = null ]) : mixed|null
Parameters
- $key : string
-
The config item to look up.
- $default : mixed|null = null
-
Default configuration value for the key item if neither has value nor exists.
Return values
mixed|null —The configuration value.
getNodeBin()
Validate and return the path to given bin from node packages.
protected
getNodeBin(string $name) : string
Parameters
- $name : string
-
The bin to look for.
Tags
Return values
string —The bin path.
getNodeBinPath()
Return the path to given bin from node packages.
protected
getNodeBinPath(string $name) : string
Parameters
- $name : string
Return values
string —The path to given binary.
isJunit()
Check whether Junit option is being used, or env var is set.
protected
isJunit() : bool
Return values
boolisSimulating()
Check if current command is being executed with option simulate.
protected
isSimulating() : bool
Return values
bool —True if using --simulate, false otherwise.
taskExecute()
Execute a command.
protected
taskExecute(array<string|int, string> $tasks) : CollectionBuilder
Parameters
- $tasks : array<string|int, string>
-
An array with tasks to execute.
Return values
CollectionBuilder —The task executed.
taskProcess()
Process the file.
protected
taskProcess(string $source[, string $destination = '' ]) : ReplaceBlock|CollectionBuilder
Parameters
- $source : string
-
The source file to process.
- $destination : string = ''
-
The destination file.
Return values
ReplaceBlock|CollectionBuilder —The file task processed.
taskReplaceBlock()
Replace block in a file.
protected
taskReplaceBlock([string $filename = '' ]) : ReplaceBlock|CollectionBuilder
Parameters
- $filename : string = ''
-
The file to process.
Return values
ReplaceBlock|CollectionBuilder —The file replaced.
backupDockerComposeFile()
Backup current docker-compose.yml to docker-compose.yml.prev.
private
backupDockerComposeFile() : void
Return values
void —The backup docker-compose file.
copyDockerComposeDefaultToProject()
Copy ./resources/docker/default.yml file to docker-compose.yml inside project root directory.
private
copyDockerComposeDefaultToProject() : void
Return values
void —The docker-compose file copied into project.
extractMajorMinorVersion()
Converts from semantic version to "major.minor" version.
private
extractMajorMinorVersion(string $version) : string
Parameters
- $version : string
-
The version to convert.
Return values
string —The major minor version.
getFinalImages()
Get final images to update docker-compose.yml.
private
getFinalImages(array<string|int, mixed> $requirements, array<string|int, mixed> $websiteRequirements, array<string|int, mixed> $optsFileContent) : array<string|int, string>
Parameters
- $requirements : array<string|int, mixed>
-
The requirements.
- $websiteRequirements : array<string|int, mixed>
-
The website requirements.
- $optsFileContent : array<string|int, mixed>
-
The .opts.yml file content.
Return values
array<string|int, string> —The final images to update the docker-compose.yml file.
getProjectPhpFromWebsite()
Returns the Project's php service version information from the endpoint.
private
getProjectPhpFromWebsite(string $projectId) : array<string|int, mixed>
Parameters
- $projectId : string
-
The project id.
Return values
array<string|int, mixed> —The project service.
getServiceDetailsFromResources()
Return the details for a service from ./resources/docker.
private
getServiceDetailsFromResources(string $serviceName) : array<string|int, string>
Parameters
- $serviceName : string
-
The service name.
Return values
array<string|int, string> —The service detail.
getServiceImage()
Get service image with version.
private
getServiceImage(string $service, string $image, string $version) : string
Parameters
- $service : string
-
The image service.
- $image : string
-
The image.
- $version : string
-
The image version.
Return values
string —The service image version.
getServicesImagesFromDockerCompose()
Get array of services with images and versions from docker-compose.yml.
private
getServicesImagesFromDockerCompose(array<string|int, mixed> $dcContent) : array<string|int, string>
Parameters
- $dcContent : array<string|int, mixed>
-
The docker-compose content.
Return values
array<string|int, string> —The images and versions array services.
getServicesVersionsFromRequirements()
Get final services names with versions from requirements.
private
getServicesVersionsFromRequirements(array<string|int, mixed> $content) : array<string|int, mixed>
Parameters
- $content : array<string|int, mixed>
-
The requirement content to be checked.
Return values
array<string|int, mixed> —The services version.
getWarningMessages()
Get warning messages for versions on .opts.yml that not respect the minimum requirements.
private
getWarningMessages(array<string|int, mixed> $optsFileContent, array<string|int, mixed> $websiteRequirements) : array<string|int, string>
Parameters
- $optsFileContent : array<string|int, mixed>
-
The .opts.yml content.
- $websiteRequirements : array<string|int, mixed>
-
The website requirements.
Return values
array<string|int, string> —The warning messages.
getWebsiteRequirements()
Returns the toolkit requirements from the endpoint.
private
getWebsiteRequirements() : array<string|int, mixed>
Return values
array<string|int, mixed> —The toolkit requirements.
removeUnusedDcServices()
Remove services that do not exist in project info, requirements or .opts.yml.
private
removeUnusedDcServices(array<string|int, string> $dcServices, array<string|int, string> $finalServicesImages) : array<string|int, string>
Parameters
- $dcServices : array<string|int, string>
-
The services to be removed.
- $finalServicesImages : array<string|int, string>
-
The final services that should exist.
Return values
array<string|int, string> —The array services updated.
updateDockerComposeFile()
Update docker-compose.yml.
private
updateDockerComposeFile(array<string|int, mixed> $dcContent, array<string|int, string> $finalServicesImages) : void
Parameters
- $dcContent : array<string|int, mixed>
-
The docker-compose content.
- $finalServicesImages : array<string|int, string>
-
The service images.
Return values
void —The docker-compose file updated.
writeWarningMessages()
Write all available warning messages.
private
writeWarningMessages(array<string|int, string> $messages) : void
Parameters
- $messages : array<string|int, string>
-
Messages to print.
Return values
void —The warning messages.