This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Add a new feature to configure windows freezing deployment #283
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d3b016c
Add IsFreezed method
74046d4
Add the verfication for a frozen window
46d863b
Add comments for deployment.go
784214f
Fix the name of field
afdcb1c
Add documentations
fb5fb58
Fix test
50def92
Upgrade the version
e319427
Fix the typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ import ( | |
"go.uber.org/zap" | ||
) | ||
|
||
// IsApproved verifies that the request is approved or not. | ||
// It is approved if there is an approval of reviews at least, but | ||
// it is rejected if there is a reject of reviews. | ||
func (i *Interactor) IsApproved(ctx context.Context, d *ent.Deployment) bool { | ||
rvs, _ := i.Store.ListReviews(ctx, d) | ||
|
||
|
@@ -32,8 +35,12 @@ func (i *Interactor) IsApproved(ctx context.Context, d *ent.Deployment) bool { | |
return false | ||
} | ||
|
||
// Deploy posts a new deployment to SCM with the payload. | ||
// But if it requires a review, it saves the payload on the DB | ||
// and waits until reviewed. | ||
// It returns an error for a undeployable payload. | ||
func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, env *extent.Env) (*ent.Deployment, error) { | ||
if ok, err := i.isDeployable(ctx, u, r, d, env); !ok { | ||
if err := i.isDeployable(ctx, u, r, d, env); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -114,7 +121,9 @@ func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *en | |
return d, nil | ||
} | ||
|
||
// DeployToRemote create a new remote deployment after the deployment was approved. | ||
// DeployToRemote posts a new deployment to SCM with the saved payload | ||
// after review has finished. | ||
// It returns an error for a undeployable payload. | ||
func (i *Interactor) DeployToRemote(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, env *extent.Env) (*ent.Deployment, error) { | ||
if d.Status != deployment.StatusWaiting { | ||
return nil, e.NewErrorWithMessage( | ||
|
@@ -124,7 +133,7 @@ func (i *Interactor) DeployToRemote(ctx context.Context, u *ent.User, r *ent.Rep | |
) | ||
} | ||
|
||
if ok, err := i.isDeployable(ctx, u, r, d, env); !ok { | ||
if err := i.isDeployable(ctx, u, r, d, env); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -171,21 +180,30 @@ func (i *Interactor) createRemoteDeployment(ctx context.Context, u *ent.User, r | |
return i.SCM.CreateRemoteDeployment(ctx, u, r, d, env) | ||
} | ||
|
||
func (i *Interactor) isDeployable(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, env *extent.Env) (bool, error) { | ||
if ok, err := env.IsDeployableRef(d.Ref); err != nil { | ||
return false, err | ||
} else if !ok { | ||
return false, e.NewErrorWithMessage(e.ErrorCodeEntityUnprocessable, "The ref is not matched with 'deployable_ref'.", nil) | ||
func (i *Interactor) isDeployable(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, env *extent.Env) error { | ||
// Skip verifications for roll back. | ||
if !d.IsRollback { | ||
if ok, err := env.IsDeployableRef(d.Ref); !ok { | ||
return e.NewErrorWithMessage(e.ErrorCodeEntityUnprocessable, "The ref is not matched with 'deployable_ref'.", nil) | ||
} else if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Check that the environment is locked. | ||
if locked, err := i.Store.HasLockOfRepoForEnv(ctx, r, d.Env); locked { | ||
return false, e.NewError(e.ErrorCodeDeploymentLocked, err) | ||
return e.NewError(e.ErrorCodeDeploymentLocked, err) | ||
} else if err != nil { | ||
return err | ||
} | ||
|
||
if freezed, err := env.IsFreezed(time.Now().UTC()); freezed { | ||
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. Verify the time is in the deploy freeze window or not. |
||
return e.NewError(e.ErrorCodeDeploymentFreezed, err) | ||
} else if err != nil { | ||
return false, e.NewError(e.ErrorCodeInternalError, err) | ||
return err | ||
} | ||
|
||
return true, nil | ||
return nil | ||
} | ||
|
||
func (i *Interactor) runClosingInactiveDeployment(stop <-chan struct{}) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add a condition to skip verifications works only for deployment.