Skip to content
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

feat: Update repo schema #260

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var cloneCmd = &cobra.Command{
fatal.Exitf("%s does not have a repo or is a third-party repo\n", serviceName)
}

repoPath := fmt.Sprintf("./%s", strings.Split(s.GitRepo, "/")[1])
err = git.Clone(s.GitRepo, repoPath)
repoPath := fmt.Sprintf("./%s", strings.Split(s.GitRepo.Name, "/")[1])
err = git.Clone(s.GitRepo.Name, repoPath)
if err != nil {
fatal.ExitErr(err, "Could not run git clone command.")
}
Expand Down
24 changes: 15 additions & 9 deletions cmd/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ var nukeCmd = &cobra.Command{

},
Run: func(cmd *cobra.Command, args []string) {
// Passing nothing to compose will shut everything down
err := docker.ComposeStop(make([]string, 0))
if err != nil {
fatal.ExitErr(err, "Failed stopping docker compose services.")
// Run compose stop before nuking any docker related resources
// to ensure no weirdness
if nukeOpts.shouldNukeContainers || nukeOpts.shouldNukeImages ||
nukeOpts.shouldNukeVolumes || nukeOpts.shouldNukeNetworks ||
nukeOpts.shouldNukeAll {
// Passing nothing to compose will shut everything down
err := docker.ComposeStop(make([]string, 0))
if err != nil {
fatal.ExitErr(err, "Failed stopping docker compose services.")
}
}

if nukeOpts.shouldNukeContainers || nukeOpts.shouldNukeAll {
log.Infoln("Stopping running containers...")
err = docker.StopAllContainers()
err := docker.StopAllContainers()
if err != nil {
fatal.ExitErr(err, "Failed stopping docker containers")
}
Expand All @@ -74,7 +80,7 @@ var nukeCmd = &cobra.Command{

if nukeOpts.shouldNukeImages || nukeOpts.shouldNukeAll {
log.Infoln("Removing images...")
err = docker.RmImages()
err := docker.RmImages()
if err != nil {
fatal.ExitErr(err, "Failed removing docker images.")
}
Expand All @@ -83,7 +89,7 @@ var nukeCmd = &cobra.Command{

if nukeOpts.shouldNukeNetworks || nukeOpts.shouldNukeAll {
log.Infoln("Removing networks...")
err = docker.RmNetworks()
err := docker.RmNetworks()
if err != nil {
fatal.ExitErr(err, "Failed removing docker networks.")
}
Expand All @@ -92,7 +98,7 @@ var nukeCmd = &cobra.Command{

if nukeOpts.shouldNukeVolumes || nukeOpts.shouldNukeAll {
log.Infoln("Removing volumes...")
err = docker.RmVolumes()
err := docker.RmVolumes()
if err != nil {
fatal.ExitErr(err, "Failed removing docker volumes.")
}
Expand All @@ -107,7 +113,7 @@ var nukeCmd = &cobra.Command{
for it.HasNext() {
s := it.Next()
if s.HasGitRepo() {
repos = append(repos, s.GitRepo)
repos = append(repos, s.GitRepo.Name)
}
}
repos = util.UniqueStrings(repos)
Expand Down
2 changes: 1 addition & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Examples:
repos := make([]string, 0)
for _, s := range selectedServices {
if s.HasGitRepo() {
repos = append(repos, s.GitRepo)
repos = append(repos, s.GitRepo.Name)
}
}
repos = util.UniqueStrings(repos)
Expand Down
6 changes: 4 additions & 2 deletions compose/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ func TestCreateComposeFile(t *testing.T) {
Ports: []string{
"8081:8080",
},
PreRun: "yarn db:prepare",
GitRepo: "TouchBistro/venue-core-service",
PreRun: "yarn db:prepare",
GitRepo: service.GitRepo{
Name: "TouchBistro/venue-core-service",
},
Build: service.Build{
Args: map[string]string{
"NODE_ENV": "development",
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func CloneMissingRepos() error {
for it.HasNext() {
s := it.Next()
if s.HasGitRepo() {
repos = append(repos, s.GitRepo)
repos = append(repos, s.GitRepo.Name)
}
}
repos = util.UniqueStrings(repos)
Expand Down
2 changes: 1 addition & 1 deletion config/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func parseServices(config legacyServiceConfig) (map[string]service.Service, erro

// Set special service specific vars
if s.HasGitRepo() {
vars["@REPOPATH"] = filepath.Join(ReposPath(), s.GitRepo)
vars["@REPOPATH"] = filepath.Join(ReposPath(), s.GitRepo.Name)
} else {
vars["@REPOPATH"] = ""
}
Expand Down
3 changes: 2 additions & 1 deletion docs/registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ The schema is as follows:
mode: remote | build # What mode to use: remote or build
ports: string[] # List of ports to expose
preRun: string # Script to run before starting the service, e.g. 'yarn db:prepare' to run db migrations
repo: string # The repo name on GitHub, format: org/repo
repo:
name: string # The repo name on GitHub, format: org/repo
build:
args: map<string, string> # List of args to pass to docker build
command: string # Command to run when container starts
Expand Down
2 changes: 1 addition & 1 deletion registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func readServices(r Registry, rootPath, reposPath string) ([]service.Service, se

// Set special service specific vars
if s.HasGitRepo() {
vars["@REPOPATH"] = filepath.Join(reposPath, s.GitRepo)
vars["@REPOPATH"] = filepath.Join(reposPath, s.GitRepo.Name)
} else {
vars["@REPOPATH"] = ""
}
Expand Down
20 changes: 12 additions & 8 deletions registry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ func TestReadRegistries(t *testing.T) {
"HTTP_PORT": "8080",
"DB_HOST": "touchbistro-tb-registry-postgres",
},
Mode: service.ModeRemote,
Ports: []string{"8081:8080"},
PreRun: "yarn db:prepare",
GitRepo: "TouchBistro/venue-core-service",
Mode: service.ModeRemote,
Ports: []string{"8081:8080"},
PreRun: "yarn db:prepare",
GitRepo: service.GitRepo{
Name: "TouchBistro/venue-core-service",
},
Build: service.Build{
Args: map[string]string{
"NODE_ENV": "development",
Expand Down Expand Up @@ -146,10 +148,12 @@ func TestReadRegistries(t *testing.T) {
"HTTP_PORT": "8000",
"POSTGRES_HOST": "examplezone-tb-registry-postgres",
},
Mode: service.ModeRemote,
Ports: []string{"9000:8000"},
PreRun: "yarn db:prepare:dev",
GitRepo: "ExampleZone/venue-example-service",
Mode: service.ModeRemote,
Ports: []string{"9000:8000"},
PreRun: "yarn db:prepare:dev",
GitRepo: service.GitRepo{
Name: "ExampleZone/venue-example-service",
},
Build: service.Build{
Command: "yarn start",
DockerfilePath: "/home/test/.tb/repos/ExampleZone/venue-example-service",
Expand Down
3 changes: 2 additions & 1 deletion registry/testdata/invalid-registry-1/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ services:
ports:
- '5432:8080'
preRun: yarn db:prepare
repo: TouchBistro/venue-core-service
repo:
name: TouchBistro/venue-core-service
build:
args:
NODE_ENV: development
Expand Down
3 changes: 2 additions & 1 deletion registry/testdata/registry-1/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ services:
ports:
- '8081:8080'
preRun: yarn db:prepare
repo: TouchBistro/venue-core-service
repo:
name: TouchBistro/venue-core-service
build:
args:
NODE_ENV: development
Expand Down
3 changes: 2 additions & 1 deletion registry/testdata/registry-2/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ services:
ports:
- '9000:8000'
preRun: yarn db:prepare:dev
repo: ExampleZone/venue-example-service
repo:
name: ExampleZone/venue-example-service
build:
target: build
command: yarn start
Expand Down
8 changes: 6 additions & 2 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ type Build struct {
Volumes []Volume `yaml:"volumes"`
}

type GitRepo struct {
Name string `yaml:"name"`
}

type Remote struct {
Command string `yaml:"command"`
Image string `yaml:"image"`
Expand All @@ -38,7 +42,7 @@ type Service struct {
Entrypoint []string `yaml:"entrypoint"`
EnvFile string `yaml:"envFile"`
EnvVars map[string]string `yaml:"envVars"`
GitRepo string `yaml:"repo"`
GitRepo GitRepo `yaml:"repo"`
Mode string `yaml:"mode"`
Ports []string `yaml:"ports"`
PreRun string `yaml:"preRun"`
Expand All @@ -49,7 +53,7 @@ type Service struct {
}

func (s Service) HasGitRepo() bool {
return s.GitRepo != ""
return s.GitRepo.Name != ""
}

func (s Service) UseRemote() bool {
Expand Down
30 changes: 20 additions & 10 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func createServiceCollection(t *testing.T) *ServiceCollection {
Ports: []string{
"8081:8080",
},
PreRun: "yarn db:prepare:dev",
GitRepo: "TouchBistro/venue-core-service",
PreRun: "yarn db:prepare:dev",
GitRepo: GitRepo{
Name: "TouchBistro/venue-core-service",
},
Build: Build{
Args: map[string]string{
"NODE_ENV": "development",
Expand All @@ -70,8 +72,10 @@ func TestServiceMethods(t *testing.T) {
assert := assert.New(t)

s := Service{
GitRepo: "TouchBistro/venue-core-service",
Mode: ModeRemote,
GitRepo: GitRepo{
Name: "TouchBistro/venue-core-service",
},
Mode: ModeRemote,
Build: Build{
DockerfilePath: ".tb/repos/TouchBistro/venue-core-service",
},
Expand Down Expand Up @@ -104,8 +108,10 @@ func TestNewServiceCollectionOverrides(t *testing.T) {
Ports: []string{
"8081:8080",
},
PreRun: "yarn db:prepare:dev",
GitRepo: "TouchBistro/venue-core-service",
PreRun: "yarn db:prepare:dev",
GitRepo: GitRepo{
Name: "TouchBistro/venue-core-service",
},
Build: Build{
Args: map[string]string{
"NODE_ENV": "development",
Expand Down Expand Up @@ -153,8 +159,10 @@ func TestNewServiceCollectionOverrides(t *testing.T) {
Ports: []string{
"8081:8080",
},
PreRun: "yarn db:prepare",
GitRepo: "TouchBistro/venue-core-service",
PreRun: "yarn db:prepare",
GitRepo: GitRepo{
Name: "TouchBistro/venue-core-service",
},
Build: Build{
Args: map[string]string{
"NODE_ENV": "development",
Expand Down Expand Up @@ -211,8 +219,10 @@ func TestServiceCollectionGetShortName(t *testing.T) {
Ports: []string{
"8081:8080",
},
PreRun: "yarn db:prepare:dev",
GitRepo: "TouchBistro/venue-core-service",
PreRun: "yarn db:prepare:dev",
GitRepo: GitRepo{
Name: "TouchBistro/venue-core-service",
},
Build: Build{
Args: map[string]string{
"NODE_ENV": "development",
Expand Down
Loading