Skip to content

feat: parse healthcheck in dockerfile#971

Merged
mergify[bot] merged 6 commits intoaws:masterfrom
seongm-1:healthcheck-parser
Jun 3, 2020
Merged

feat: parse healthcheck in dockerfile#971
mergify[bot] merged 6 commits intoaws:masterfrom
seongm-1:healthcheck-parser

Conversation

@seongm-1
Copy link
Copy Markdown
Contributor

@seongm-1 seongm-1 commented May 27, 2020

The ability to parse Healthcheck options from a user's dockerfile.

Also added, some of Moby buildkit packages for ease of parsing dockerfile.

https://godoc.org/github.com/moby/buildkit/frontend/dockerfile/parser
https://godoc.org/github.com/moby/buildkit/frontend/dockerfile/instructions

Addresses #938

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Binary Size (added Mobykit parsers)
Before: 44.2 MB
After: 44.4 MB

@seongm-1 seongm-1 requested a review from a team as a code owner May 27, 2020 15:43
@seongm-1 seongm-1 requested a review from kohidave May 27, 2020 15:43
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile_test.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Copy link
Copy Markdown
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! mostly some Go best-practices.

Do we need a GetHealthcheck() (*HealthCheck, error) method? I think this PR parses the content but doesn't provide a way for clients to access the HealthCheck.

Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
}

// parse takes a Dockerfile and fills in struct members based on methods like parseExpose and (TODO) parseHealthcheck
// parse takes a Dockerfile and fills in struct members based on methods like parseExpose and parseHealthcheck
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences

Comments should begin with the name of the thing being described and end in a period

This wiki page is pretty neat and contains all sorts of best-practices, if you'd like to take a look when you've time :)

Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile_test.go Outdated
Copy link
Copy Markdown
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 🚀 tiny nits! once addressed feel free to remove the "do-not-merge" label and mergify can auto-merge after 2 approvals 😁.

Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile.go Outdated
Comment thread internal/pkg/docker/dockerfile/dockerfile_test.go Outdated
@efekarakus efekarakus added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 3, 2020
inst := fmt.Sprint(instruction)

// Getting the value at a children will return the Dockerfile directive
switch d := child.Value; d {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like what you did with ParseInstruction! I just realized that the instruction itself is already parsed into a moby type and we don't need to parse it again :D

Can try something like this:

var hc *HealthCheck
switch t := instruction.(type); t {
case *instructions.ExposeCommand:
// Read fields from t.
case *instructions.HealthCheckCommand:
    hc = &HealthCheck{
         interval: uint16(t.Health.Interval.Seconds()),
         // ... same for other fields
    }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked about it offline and it provided a compiler error. Might have to tackle this later on.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good but I think it's worthwhile addressing it because it will significantly remove code from us and will keep it in sync with how Docker parses the file.

Copy link
Copy Markdown
Contributor

@iamhopaul123 iamhopaul123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@seongm-1 seongm-1 removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Jun 3, 2020
@mergify mergify bot merged commit 5b87893 into aws:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants