Skip to content

Provide Unison sync support for projects#32

Merged
febbraro merged 19 commits intofeature/rig-projectfrom
feature/unison-sync
May 17, 2017
Merged

Provide Unison sync support for projects#32
febbraro merged 19 commits intofeature/rig-projectfrom
feature/unison-sync

Conversation

@febbraro
Copy link
Member

This PR provides 2 commands, project sync:start and project sync:stop.

These commands will discover the volume name in the following order of fallback.

  1. Argument passed to the command
  2. Configuration in local project .outrigger.yml file (format of config to follow)
  3. Inspecting the docker-compose.yml file (we need to figure out if this file should be configurable, I think it will have to be)
  4. The name of the current directory

The sync command has configuration that can be provided in the .outrigger.yml file in he following format.

version: "1.0"
sync:
  volume: project-sync
  ignores:
    - "Name .gitignore"
    - "Path node_modules"

The ignores follow the unison ignore patterns. http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#ignore

Copy link
Contributor

@grayside grayside left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were avoiding a dependency on docker-sync?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

"strings"

"github.com/phase2/rig/cli/commands/project"
"github.com/phase2/rig/cli/commands/project"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a tab vs/ spaces issue. Please tell me you are setup to use spaces? 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be spaces, but mostly I just run go fmt and commit. Should I study that more?

}

return command
syncStart := ProjectSync{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be slightly more clear to name this syncDefinition

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, should change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


type ProjectSync struct {
Volume string
Ignore []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatted

@@ -0,0 +1,235 @@
package commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe group all the project things to the project sub-package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

"-v", fmt.Sprintf("%s:/unison", volumeName),
"-e", "UNISON_DIR=/unison",
"-l", fmt.Sprintf("com.dnsdock.name=%s", volumeName),
"-l", "com.dnsdock.image=volume.outrigger",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen a period inside a dnsdock image designation before. Is that allowed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some benefit to surfacing a domain to developers, e.g., for troubleshooting purposes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

"-l", fmt.Sprintf("com.dnsdock.name=%s", volumeName),
"-l", "com.dnsdock.image=volume.outrigger",
"--name", volumeName,
"outrigger/unison:latest",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll see what I can do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

// Load the proper compose file
func (cmd *ProjectSync) LoadComposeFile() (*ComposeFile, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


// Load the proper compose file
func (cmd *ProjectSync) LoadComposeFile() (*ComposeFile, error) {
yamlFile, err := ioutil.ReadFile("./docker-compose.yml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this "fallback" doesn't work for the build container?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it doesn't inspect the build.yml file, but both of them need the same exact volumes spec in their files.


// Load the proper compose file
func (cmd *ProjectSync) LoadComposeFile() (*ComposeFile, error) {
yamlFile, err := ioutil.ReadFile("./docker-compose.yml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we respect the COMPOSE_FILE env var, or is that just helpful enough to be confusing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

"-repeat", "watch",
"-prefer", ".",
"-logfile", logFile,
"-ignore", "Name .git",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "Name .git" or "Path .git"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, "Name .git" is correct.

"-repeat", "watch",
"-prefer", ".",
"-logfile", logFile,
"-ignore", "Name .git",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This skates by review, but once we have a docs page for this we should link to it here.

@febbraro febbraro merged commit a4b3693 into feature/rig-project May 17, 2017
@febbraro febbraro deleted the feature/unison-sync branch May 17, 2017 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants