generated from coderefinery/word-count
-
Notifications
You must be signed in to change notification settings - Fork 26
Add rollback #209
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
Open
josephsawaya
wants to merge
1
commit into
containers:main
Choose a base branch
from
josephsawaya:rollback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add rollback #209
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| targetConfigs: | ||
| - name: fetchit | ||
| url: http://github.com/containers/fetchit | ||
| raw: | ||
| - name: raw | ||
| targetPath: examples/ci-rollback | ||
| schedule: "*/1 * * * *" | ||
| rollback: true | ||
| trackBadCommits: true | ||
| branch: ci-rollback |
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 |
|---|---|---|
| @@ -1,14 +1,11 @@ | ||
| { | ||
| "Image":"docker.io/mmumshad/simple-webapp-color:latest", | ||
| "Name": "cap2", | ||
| "Env": {"APP_COLOR": "blue", "tree": "trunk"}, | ||
| "Mounts": [], | ||
| "Volumes": [], | ||
| "CapDrop": ["all"], | ||
| "Ports": [{ | ||
| "host_ip": "", | ||
| "container_port": 8080, | ||
| "host_port": 9090, | ||
| "range": 0, | ||
| "protocol": ""}] | ||
| } | ||
| Image: docker.io/mmumshad/simple-webapp-color:latest | ||
| Name: cap2 | ||
| Env: | ||
| APP_COLOR": blue | ||
| tree: trunk | ||
| CapDrop: | ||
| - all | ||
| Ports: | ||
| - container_port: 8080 | ||
| host_port: 9091 | ||
| range: 0 |
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Image: "docker.io/mmumshad/simple-webapp-color:latest" | ||
| Name: "rollback2" | ||
| Env: | ||
| APP_COLOR: "pink" | ||
| tree: "trunk" | ||
| Ports: | ||
| - container_port: 8080 | ||
| host_port: 8081 | ||
| range: 0 |
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Typo below | ||
| Image: "docker.io/mmumshad/simple-webapp-clor:latest" | ||
| Name: "rollback3" | ||
| Env: | ||
| APP_COLOR: "pink" | ||
| tree: "trunk" | ||
| Ports: | ||
| - container_port: 8080 | ||
| host_port: 8080 | ||
| range: 0 |
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Image: "docker.io/mmumshad/simple-webapp-color:latest" | ||
| Name: "rollback1" | ||
| Env: | ||
| APP_COLOR: "pink" | ||
| tree: "trunk" | ||
| Ports: | ||
| - container_port: 8080 | ||
| host_port: 8080 | ||
| range: 0 |
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 |
|---|---|---|
|
|
@@ -7,8 +7,10 @@ import ( | |
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/containers/fetchit/pkg/engine/utils" | ||
| "github.com/go-git/go-git/v5/plumbing" | ||
| "github.com/go-git/go-git/v5/plumbing/object" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| type CommonMethod struct { | ||
|
|
@@ -70,6 +72,11 @@ func getDirectory(target *Target) string { | |
| return filepath.Base(trimDir) | ||
| } | ||
|
|
||
| type empty struct { | ||
| } | ||
|
|
||
| var BadCommitList map[string]map[string]map[plumbing.Hash]empty = make(map[string]map[string]map[plumbing.Hash]empty) | ||
|
|
||
| func currentToLatest(ctx, conn context.Context, m Method, target *Target, tag *[]string) error { | ||
| directory := getDirectory(target) | ||
| if target.disconnected { | ||
|
|
@@ -79,6 +86,7 @@ func currentToLatest(ctx, conn context.Context, m Method, target *Target, tag *[ | |
| localDevicePull(directory, target.device, "", false) | ||
| } | ||
| } | ||
|
|
||
| latest, err := getLatest(target) | ||
| if err != nil { | ||
| return fmt.Errorf("Failed to get latest commit: %v", err) | ||
|
|
@@ -89,10 +97,43 @@ func currentToLatest(ctx, conn context.Context, m Method, target *Target, tag *[ | |
| return fmt.Errorf("Failed to get current commit: %v", err) | ||
| } | ||
|
|
||
| if target.rollback && target.trackBadCommits { | ||
| if _, ok := BadCommitList[directory]; !ok { | ||
| BadCommitList[directory] = make(map[string]map[plumbing.Hash]empty) | ||
| } | ||
|
|
||
| if _, ok := BadCommitList[directory][m.GetKind()]; !ok { | ||
| BadCommitList[directory][m.GetKind()] = make(map[plumbing.Hash]empty) | ||
| } | ||
|
|
||
| if _, ok := BadCommitList[directory][m.GetKind()][latest]; ok { | ||
| klog.Infof("No changes applied to target %s this run, %s currently at %s", directory, m.GetKind(), current) | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| if latest != current { | ||
| if err := m.Apply(ctx, conn, current, latest, tag); err != nil { | ||
| return fmt.Errorf("Failed to apply changes: %v", err) | ||
| if err = m.Apply(ctx, conn, current, latest, tag); err != nil { | ||
| if target.rollback { | ||
| // Roll back automatically | ||
| klog.Errorf("Failed to apply changes, rolling back to %v: %v", current, err) | ||
|
Collaborator
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.
|
||
| if err = checkout(target, current); err != nil { | ||
| return utils.WrapErr(err, "Failed to checkout %s", current) | ||
| } | ||
| if err = m.Apply(ctx, conn, latest, current, tag); err != nil { | ||
| // Roll back failed | ||
| return fmt.Errorf("Roll back failed, state between %s and %s: %v", current, latest, err) | ||
| } | ||
| if target.trackBadCommits { | ||
| BadCommitList[directory][m.GetKind()][latest] = empty{} | ||
| } | ||
| return fmt.Errorf("Rolled back to %v: %v", current, err) | ||
| } else { | ||
| return fmt.Errorf("Failed to apply changes from %v to %v: %v", current, latest, err) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| updateCurrent(ctx, target, latest, m.GetKind(), m.GetName()) | ||
| logger.Infof("Moved %s from %s to %s for git target %s", m.GetName(), current.String()[:hashReportLen], latest, target.url) | ||
| } else { | ||
|
|
||
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
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.
update
klog.Infoftologger.Infof- we transitioned to using zap for logging #225