Provide Unison sync support for projects#32
Conversation
…launch and checking for readiness
…lural made sense to do that in the first palce, but commands like project sync:start / sync:stop make sense to live in the same struct
grayside
left a comment
There was a problem hiding this comment.
Overall this looks like a strong starting place, and I think we could probably move forward on this basis. I had a lot of comments, some petty, some about making this more robust or expanding on the DX. Those could be captured as follow-ups for the most part.
Once we merge this, we should make sure all further changes to the rig project branch are added by PRs, as I think that existing branch will become too unwieldy to review.
| depends_on "docker-compose" | ||
| depends_on "docker-machine-nfs" | ||
| depends_on "unison" | ||
| depends_on "eugenmayer/dockersync/unox" |
There was a problem hiding this comment.
I thought we were avoiding a dependency on docker-sync?
There was a problem hiding this comment.
It's not really dockersync, it is just a utility that does the fswatching that he put in a brew tap called dockersync. We are not actually using dockersync
cli/commands/project.go
Outdated
| "strings" | ||
|
|
||
| "github.com/phase2/rig/cli/commands/project" | ||
| "github.com/phase2/rig/cli/commands/project" |
There was a problem hiding this comment.
Looks like a tab vs/ spaces issue. Please tell me you are setup to use spaces? 😄
There was a problem hiding this comment.
Should be spaces, but mostly I just run go fmt and commit. Should I study that more?
cli/commands/project.go
Outdated
| } | ||
|
|
||
| return command | ||
| syncStart := ProjectSync{} |
There was a problem hiding this comment.
Might be slightly more clear to name this syncDefinition
|
|
||
| type ProjectSync struct { | ||
| Volume string | ||
| Ignore []string |
| @@ -0,0 +1,235 @@ | |||
| package commands | |||
There was a problem hiding this comment.
Should we maybe group all the project things to the project sub-package?
There was a problem hiding this comment.
There is really no concept of sub packages. They are all "Standalone" I did this previously, but since there is a BaseCommand we extend, I then got an error with cyclical imports. It was a mess, but no way around it. Since there are not subpackages it seems like it would just be easier if project_config.go was just moved into the main commands package.
cli/commands/project_sync.go
Outdated
| "-v", fmt.Sprintf("%s:/unison", volumeName), | ||
| "-e", "UNISON_DIR=/unison", | ||
| "-l", fmt.Sprintf("com.dnsdock.name=%s", volumeName), | ||
| "-l", "com.dnsdock.image=volume.outrigger", |
There was a problem hiding this comment.
I haven't seen a period inside a dnsdock image designation before. Is that allowed?
There was a problem hiding this comment.
Yeah it is. Turns out we dont ever use that domain name though, so really it can just go away. I inspect the containers and use the IP address due to that cgo issue we rolled back
There was a problem hiding this comment.
Is there some benefit to surfacing a domain to developers, e.g., for troubleshooting purposes?
There was a problem hiding this comment.
I guess it is easier if folks want to point a local run unison process at it for some reason, but I dunno, it maybe just confusing, or it may just help people understand what thecontainer is even there for, Thoughts?
cli/commands/project_sync.go
Outdated
| "-l", fmt.Sprintf("com.dnsdock.name=%s", volumeName), | ||
| "-l", "com.dnsdock.image=volume.outrigger", | ||
| "--name", volumeName, | ||
| "outrigger/unison:latest", |
There was a problem hiding this comment.
Given unison needs the client and server on a fairly exact version, should we add a very specific Docker Tag to our image and then derive the tag based on the detected version available in the local system? That's a good opportunity to catch an error and provide guidance.
There was a problem hiding this comment.
Good idea. I'll see what I can do.
| } | ||
|
|
||
| // Load the proper compose file | ||
| func (cmd *ProjectSync) LoadComposeFile() (*ComposeFile, error) { |
There was a problem hiding this comment.
Custom parsing the compose file means any of the docker-compose magic such as variable handling will not be available. Would it be worth seeing if we can add a dependency on a golang library for this? I believe docker/libcompose is deprecated but maybe there's something else we can use?
There was a problem hiding this comment.
I tried. Non of the libraries include either the most recent version of compose (v3) or the "overriding rules" that come from multiple files. They just dont have compose file parsing such that it is a library to use at the moment. Happy to transition over to one when it exists though.
cli/commands/project_sync.go
Outdated
|
|
||
| // Load the proper compose file | ||
| func (cmd *ProjectSync) LoadComposeFile() (*ComposeFile, error) { | ||
| yamlFile, err := ioutil.ReadFile("./docker-compose.yml") |
There was a problem hiding this comment.
So this "fallback" doesn't work for the build container?
There was a problem hiding this comment.
Well, it doesn't inspect the build.yml file, but both of them need the same exact volumes spec in their files.
cli/commands/project_sync.go
Outdated
|
|
||
| // Load the proper compose file | ||
| func (cmd *ProjectSync) LoadComposeFile() (*ComposeFile, error) { | ||
| yamlFile, err := ioutil.ReadFile("./docker-compose.yml") |
There was a problem hiding this comment.
Should we respect the COMPOSE_FILE env var, or is that just helpful enough to be confusing?
There was a problem hiding this comment.
Maybe confusing. Also if we do the docker-compose.overrride.yml thing as our "Dev" env we'd actually need to read that file instead.
cli/commands/project_sync.go
Outdated
| "-repeat", "watch", | ||
| "-prefer", ".", | ||
| "-logfile", logFile, | ||
| "-ignore", "Name .git", |
There was a problem hiding this comment.
Should this be "Name .git" or "Path .git"?
There was a problem hiding this comment.
Nevermind, "Name .git" is correct.
cli/commands/project_sync.go
Outdated
| "-repeat", "watch", | ||
| "-prefer", ".", | ||
| "-logfile", logFile, | ||
| "-ignore", "Name .git", |
There was a problem hiding this comment.
Shouldn't there be some processing to combine this with the sync configuration for ignores I see in the project.ProjectSync struct?
| cmd.out.Error.Println(err) | ||
| } | ||
|
|
||
| cmd.out.Error.Fatal("Unable to determine a name for the sync volume") |
There was a problem hiding this comment.
This skates by review, but once we have a docs page for this we should link to it here.
This PR provides 2 commands,
project sync:startandproject sync:stop.These commands will discover the volume name in the following order of fallback.
.outrigger.ymlfile (format of config to follow)docker-compose.ymlfile (we need to figure out if this file should be configurable, I think it will have to be)The sync command has configuration that can be provided in the
.outrigger.ymlfile in he following format.The ignores follow the unison ignore patterns. http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#ignore