picostack / pico

A Git-driven task runner built to facilitate GitOps and Infrastructure-as-Code while securely passing secrets to tasks.
https://pico.sh
MIT License
54 stars 6 forks source link

Issues with branches and pico updating them #76

Closed ADRFranklin closed 4 years ago

ADRFranklin commented 4 years ago

For some reason when Pico see's changes in a repo, it somehow manages to run for all repos of the same url even if they have different branches.

For example today, I pushed to my development branch, and CI passed and pushed a staging container, well what happened was that the production server went down and it seems pico was responsible for doing that.


ERROR: for sag-sffw-prod-gm  Cannot create container for service sffw: Conflict. The container name "/sag-sffw-dev-gm" is already in use by container "cff9bb1eb6527bd18a47ca1bf84a9d5bd01729e21cf6f5da520a80fc5c24e36b". You have to remove (or rename) that container to be able to reuse that name.,
ROR: for sffw  Cannot create container for service sffw: Conflict. The container name "/sag-sffw-dev-gm" is already in use by container "cff9bb1eb6527bd18a47ca1bf84a9d5bd01729e21cf6f5da520a80fc5c24e36b". You have to remove (or rename) that container to be able to reuse that name.,
{"level":"error","ts":"2020-08-04T14:22:01.131Z","caller":"executor/cmd.go:40","msg":"executor task unsuccessful","target":"sffw-gamemode-dev","shutdown":false,"error":"exit status 1","stacktrace":"github.com/picostack/pico/executor.(*CommandExecutor).Subscribe\n\t/home/runner/work/pico/pico/executor/cmd.go:40\ngithub.com/picostack/pico/service.(*App).Start.func1\n\t/home/runner/work/pico/pico/service/service.go:116"},
Encountered errors while bringing up the project.

The production repo should not have been touched at all, since no event changes happened to that branch.

Southclaws commented 4 years ago

This is probably because pico receives the event from gitwatcher and then uses the URL to find the relevant target. It should use the url and branch name, or maybe even the path.

Southclaws commented 4 years ago

Problematic function: https://github.com/picostack/pico/blob/3dee36d1459a2c57afc9b28bfcc35756a19166c4/watcher/git.go#L277

Southclaws commented 4 years ago

if t.RepoURL == url just needs to be either a check against the path or a check against both the URL and branch. Either work.

ADRFranklin commented 4 years ago

I think path makes the most sense to do.

ADRFranklin commented 4 years ago

so something like this?

func (w GitWatcher) getTarget(path string) (target task.Target, exists bool) {
    for _, t := range w.state.Targets {
        targetPath := getTargetPath(t)
        if targetPath == path {
            return t, true
        }
    }
    return
}

With the watcher event passing in e.Path

ADRFranklin commented 4 years ago

On second thought, the target struct needs to keep track of the directory it is in, since there is no way to get the full path from just using getTargetPath which is what the tests expect.