-
Notifications
You must be signed in to change notification settings - Fork 0
inject preview deployments into nested stacks #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6960aba
30595c6
ae63644
2ad9cac
9c85319
1814c20
eb9f56e
6f795f5
ceee2cd
a504e9b
d2825e2
a2f526e
c4719b6
1aeb7bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package cache | ||
|
|
||
| // Previews returns all cached service release artifacts that are defined as | ||
| // preview deployments. | ||
| func (c *Cache) Previews(doc string) []Object { | ||
| { | ||
| c.mut.Lock() | ||
| defer c.mut.Unlock() | ||
| } | ||
|
|
||
| var lis []Object | ||
|
|
||
| for _, x := range c.ser { | ||
| if bool(x.Release.Deploy.Preview) && x.Release.Docker.String() == doc { | ||
| lis = append(lis, x) | ||
| } | ||
| } | ||
|
|
||
| return lis | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package hash | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "encoding/hex" | ||
|
|
||
| "golang.org/x/text/cases" | ||
| "golang.org/x/text/language" | ||
| ) | ||
|
|
||
| type Hash struct { | ||
| // dsh is the dashed prefix version of Upp. | ||
| // | ||
| // -1D0FD508 | ||
| // | ||
| dsh []byte | ||
| // low is the lower case version of Upp. | ||
| // | ||
| // 1d0fd508 | ||
| // | ||
| low []byte | ||
| // upp is the upper case version of this hash. | ||
| // | ||
| // 1D0FD508 | ||
| // | ||
| upp []byte | ||
| } | ||
|
|
||
| func New(str string) Hash { | ||
| var hsh string | ||
| { | ||
| hsh = newHsh(str) | ||
| } | ||
|
|
||
| var low string | ||
| var upp string | ||
| { | ||
| low = cases.Lower(language.English).String(hsh) | ||
| upp = cases.Upper(language.English).String(hsh) | ||
| } | ||
|
|
||
| return Hash{ | ||
| dsh: []byte("-" + upp), | ||
| low: []byte(low), | ||
| upp: []byte(upp), | ||
| } | ||
| } | ||
|
Comment on lines
+42
to
+47
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are hashing branch names for identifying preview deployments inside all of AWS. We also have to create the preview deployment domain using some kind of deterministic identifier based on the preview branch. Turned out we cannot just use branch names in preview domains because branch names have a far wider character set than domain names allow for. E.g. the domain |
||
|
|
||
| func (h Hash) Dashed() string { | ||
| return string(h.dsh) | ||
| } | ||
|
|
||
| func (h Hash) Empty() bool { | ||
| return h.dsh == nil && h.low == nil && h.upp == nil | ||
| } | ||
|
|
||
| func (h Hash) Lower() string { | ||
| return string(h.low) | ||
| } | ||
|
|
||
| func (h Hash) Upper() string { | ||
| return string(h.upp) | ||
| } | ||
|
|
||
| func newHsh(str string) string { | ||
| sum := sha256.Sum256([]byte(str)) | ||
| enc := hex.EncodeToString(sum[:]) | ||
|
|
||
| return enc[:8] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,12 @@ func (o *Operator) Chain() [][]handler.Ensure { | |
| // reconciliation loops. | ||
| {o.release}, | ||
|
|
||
| // Inject any potential preview deployments into our internal list of | ||
| // release definitions so that we can render and expose any additional | ||
| // development services during testing. Note that this worker handler is | ||
| // only active within the testing environment. | ||
| {o.preview}, | ||
|
Comment on lines
+18
to
+22
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we register the new conditional worker handler. |
||
|
|
||
| // Run the next steps in parallel in order to find the current and | ||
| // desired state of the release artifacts that we are tasked to | ||
| // managed. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package cloudformation | ||
|
|
||
| // Active defines this worker handler to always be executed. | ||
| func (c *CloudFormation) Active() bool { | ||
| return true | ||
| } | ||
|
Comment on lines
+3
to
+6
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are marking almost all worker handlers in Kayron as always active. The alternative would be to wrap every worker handler in a proxy worker handler, but I thought this approach here is more explicit. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package container | ||
|
|
||
| // Active defines this worker handler to always be executed. | ||
| func (c *Container) Active() bool { | ||
| return true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,14 @@ func (c *Container) cache(ima []image) { | |
| for _, x := range c.cac.Services() { | ||
| var tag string | ||
| { | ||
| tag = curTag(ima, x.Release.Docker.String()) | ||
| tag = curTag(ima, x.Release.Labels.Hash.Upper(), x.Release.Docker.String()) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point we have potentially many ECS Services using the same |
||
| } | ||
|
|
||
| c.log.Log( | ||
| "level", "debug", | ||
| "message", "caching current state", | ||
| "docker", x.Release.Docker.String(), | ||
| "preview", x.Release.Deploy.Preview.String(), | ||
| "current", musStr(tag), | ||
| ) | ||
|
|
||
|
|
@@ -32,9 +33,9 @@ func (c *Container) cache(ima []image) { | |
| } | ||
| } | ||
|
|
||
| func curTag(ima []image, ser string) string { | ||
| func curTag(ima []image, hsh string, doc string) string { | ||
| for _, x := range ima { | ||
| if x.ser == ser { | ||
| if x.pre == hsh && x.ser == doc { | ||
| return x.tag | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly, but this enables us to reuse some information in one place, which we already fetched from the Github API in another place. E.g. the
previewworker handler resets the preview flag of the release artifact of any main release that defines preview releases for its entire repository. I don't know how to make this better at this point in time.