Goal
We want the ecs-cli-v2 to be able to parse healthcheck options from the user’s Dockerfile. There are total of four options you can specify (otherwise will result into default values) and an optional command.
Overview
Options
- interval
- timeout
- start-period
- retries
Types of Healthcheck formats
- No command
HEALTHCHECK --interval=5m --timeout=3s
- No options
HEALTHCHECK CMD curl -f http://localhost/ || exit 1
- Options and command in the same line
HEALTHCHECK --interval=5m --timeout=3s CMD curl -f http://localhost/ || exit 1
- Options and command in different lines
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost/ || exit 1
- No healthcheck
Design Proposal
Building on top of the parsing ports on a Dockerfile #747, we can create a Healthcheck struct to group all of the options and command. In addition, a separate method for parsing Healthcheck.
Programming Model
type HealthCheck struct {
interval uint16
timeout uint16
startPeriod uint16
retries uint16
command string
}
func parseHealthcheck(line string) []healthcheck {
}
Parsing Method
Currently, the way ecs-cli-v2 reads the user's Dockerfile by scanning line by line. We can use regex to parse the health check options as they will always follow the same format.
Example
healthcheckRegexPattern := "--([^\\s]+)" // this will grab all strings that start with --
We can also use regex to parse out the command
healtchcheckCMDRegexPattern := "CMD.*" //this will grab CMD until the end of the line
Issue
An issue arises when CMD is put on a different line (No. 4 on Types of Healtcheck formats). Because the scanner reads one line at a time, it will not be able to pick up CMD on the second line. I propose a healthcheckCMD flag where it will insert the following CMD line into the healthcheck struct if command in the healthcheck struct is empty and if the CMD line is right after HEALTHCHECK.
Goal
We want the ecs-cli-v2 to be able to parse healthcheck options from the user’s Dockerfile. There are total of four options you can specify (otherwise will result into default values) and an optional command.
Overview
Options
Types of Healthcheck formats
Design Proposal
Building on top of the parsing ports on a Dockerfile #747, we can create a Healthcheck struct to group all of the options and command. In addition, a separate method for parsing Healthcheck.
Programming Model
Parsing Method
Currently, the way ecs-cli-v2 reads the user's Dockerfile by scanning line by line. We can use regex to parse the health check options as they will always follow the same format.
Example
We can also use regex to parse out the command
Issue
An issue arises when CMD is put on a different line (No. 4 on Types of Healtcheck formats). Because the scanner reads one line at a time, it will not be able to pick up CMD on the second line. I propose a healthcheckCMD flag where it will insert the following CMD line into the healthcheck struct if command in the healthcheck struct is empty and if the CMD line is right after HEALTHCHECK.