diff --git a/cmd/clone.go b/cmd/clone.go index 87125730..1aeb7e77 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -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.") } diff --git a/cmd/nuke.go b/cmd/nuke.go index 4fd944d6..c11b0a76 100644 --- a/cmd/nuke.go +++ b/cmd/nuke.go @@ -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") } @@ -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.") } @@ -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.") } @@ -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.") } @@ -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) diff --git a/cmd/up.go b/cmd/up.go index 8119ba21..cba33695 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -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) diff --git a/compose/compose_test.go b/compose/compose_test.go index c71d2a42..9c63d8b2 100644 --- a/compose/compose_test.go +++ b/compose/compose_test.go @@ -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", diff --git a/config/config.go b/config/config.go index 1022a239..0d7d9162 100644 --- a/config/config.go +++ b/config/config.go @@ -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) diff --git a/config/legacy.go b/config/legacy.go index 985345ef..b8b3d0af 100644 --- a/config/legacy.go +++ b/config/legacy.go @@ -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"] = "" } diff --git a/docs/registries.md b/docs/registries.md index 22d567bb..a4b74a6b 100644 --- a/docs/registries.md +++ b/docs/registries.md @@ -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 # List of args to pass to docker build command: string # Command to run when container starts diff --git a/registry/registry.go b/registry/registry.go index 82354e83..8ce1f91a 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -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"] = "" } diff --git a/registry/registry_test.go b/registry/registry_test.go index 6d5803e7..2eaf5740 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -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", @@ -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", diff --git a/registry/testdata/invalid-registry-1/services.yml b/registry/testdata/invalid-registry-1/services.yml index d2c006a7..195c4d2b 100644 --- a/registry/testdata/invalid-registry-1/services.yml +++ b/registry/testdata/invalid-registry-1/services.yml @@ -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 diff --git a/registry/testdata/registry-1/services.yml b/registry/testdata/registry-1/services.yml index e57054fc..ae86193b 100644 --- a/registry/testdata/registry-1/services.yml +++ b/registry/testdata/registry-1/services.yml @@ -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 diff --git a/registry/testdata/registry-2/services.yml b/registry/testdata/registry-2/services.yml index 651c3b6d..93254be3 100644 --- a/registry/testdata/registry-2/services.yml +++ b/registry/testdata/registry-2/services.yml @@ -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 diff --git a/service/service.go b/service/service.go index a29aa1a0..9707012b 100644 --- a/service/service.go +++ b/service/service.go @@ -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"` @@ -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"` @@ -49,7 +53,7 @@ type Service struct { } func (s Service) HasGitRepo() bool { - return s.GitRepo != "" + return s.GitRepo.Name != "" } func (s Service) UseRemote() bool { diff --git a/service/service_test.go b/service/service_test.go index 95a2c9cf..9e9c2922 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -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", @@ -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", }, @@ -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", @@ -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", @@ -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", diff --git a/static/services.yml b/static/services.yml index 1653181b..ec14a308 100644 --- a/static/services.yml +++ b/static/services.yml @@ -38,7 +38,8 @@ services: ports: - '8700:8080' preRun: yarn db:prepare - repo: TouchBistro/backoffice-customer-service + repo: + name: TouchBistro/backoffice-customer-service build: <<: *build-node-dev volumes: @@ -61,7 +62,8 @@ services: mode: remote ports: - '3000:3000' - repo: TouchBistro/cloud-server + repo: + name: TouchBistro/cloud-server build: dockerfilePath: ${@REPOPATH} remote: @@ -86,7 +88,8 @@ services: mode: remote ports: - '8080:80' - repo: TouchBistro/cloud-server-frontend + repo: + name: TouchBistro/cloud-server-frontend build: args: USE_INSECURE_COOKIE: insecure @@ -102,7 +105,8 @@ services: mode: build ports: - '9001:80' - repo: TouchBistro/dotnet-depot + repo: + name: TouchBistro/dotnet-depot build: dockerfilePath: ${@REPOPATH}/api dotnet-manage: @@ -113,7 +117,8 @@ services: mode: build ports: - '9000:80' - repo: TouchBistro/dotnet-depot + repo: + name: TouchBistro/dotnet-depot build: dockerfilePath: ${@REPOPATH}/Manage health-clinic: @@ -121,7 +126,8 @@ services: mode: remote ports: - '8089:8089' - repo: TouchBistro/health-clinic + repo: + name: TouchBistro/health-clinic build: command: 'tail -f /dev/null' dockerfilePath: ${@REPOPATH} @@ -144,7 +150,8 @@ services: ports: - '8777:8080' preRun: yarn db:prepare - repo: TouchBistro/identity-user-service + repo: + name: TouchBistro/identity-user-service build: <<: *build-node-dev remote: @@ -165,7 +172,8 @@ services: mode: remote ports: - '9090:9090' - repo: TouchBistro/identity-home-frontend + repo: + name: TouchBistro/identity-home-frontend build: args: NPM_TOKEN: $NPM_TOKEN @@ -186,7 +194,8 @@ services: ports: - '8073:8080' preRun: yarn db:prepare - repo: TouchBistro/infrastructure-auth-service + repo: + name: TouchBistro/infrastructure-auth-service build: <<: *build-node-dev volumes: @@ -206,7 +215,8 @@ services: ports: - '8181:8080' preRun: yarn db:prepare - repo: TouchBistro/infrastructure-scratchpad-service + repo: + name: TouchBistro/infrastructure-scratchpad-service build: <<: *build-node-dev volumes: @@ -225,7 +235,8 @@ services: mode: remote ports: - '8101:8080' - repo: TouchBistro/legacy-bridge-cloud-service + repo: + name: TouchBistro/legacy-bridge-cloud-service build: <<: *build-node-dev volumes: @@ -246,7 +257,8 @@ services: mode: remote ports: - '8999:8080' - repo: TouchBistro/legacy-bridge-manage-service + repo: + name: TouchBistro/legacy-bridge-manage-service build: <<: *build-node-dev remote: @@ -262,7 +274,8 @@ services: ports: - '1433:1433' preRun: yarn db:prepare - repo: TouchBistro/legacy-database + repo: + name: TouchBistro/legacy-database build: args: NODE_ENV: development @@ -291,7 +304,8 @@ services: mode: remote ports: - '8009:8080' - repo: TouchBistro/legacy-upload-service + repo: + name: TouchBistro/legacy-upload-service build: <<: *build-node-dev volumes: @@ -331,7 +345,8 @@ services: ports: - '8600:8080' preRun: yarn db:prepare - repo: TouchBistro/loyalty-gateway-service + repo: + name: TouchBistro/loyalty-gateway-service build: <<: *build-node-dev volumes: @@ -351,7 +366,8 @@ services: preRun: yarn db:prepare ports: - '9453:8080' - repo: TouchBistro/partners-auth-service + repo: + name: TouchBistro/partners-auth-service build: <<: *build-node-dev volumes: @@ -394,7 +410,8 @@ services: ports: - '9443:8080' preRun: yarn db:prepare - repo: TouchBistro/mokta + repo: + name: TouchBistro/mokta build: <<: *build-node-dev remote: @@ -415,7 +432,8 @@ services: ports: - '8010:8080' preRun: yarn db:prepare - repo: TouchBistro/ordering-demo-frontend + repo: + name: TouchBistro/ordering-demo-frontend build: <<: *build-node-dev volumes: @@ -438,7 +456,8 @@ services: mode: build ports: - '8020:8080' - repo: TouchBistro/ordering-demo-frontend + repo: + name: TouchBistro/ordering-demo-frontend build: <<: *build-node-dev volumes: @@ -466,7 +485,8 @@ services: mode: remote ports: - '8610:8080' - repo: TouchBistro/ordering-engine-service + repo: + name: TouchBistro/ordering-engine-service build: <<: *build-node-dev volumes: @@ -486,7 +506,8 @@ services: mode: remote ports: - '8611:8080' - repo: TouchBistro/ordering-online-frontend + repo: + name: TouchBistro/ordering-online-frontend build: <<: *build-node-dev volumes: @@ -505,7 +526,8 @@ services: mode: remote ports: - '8030:8080' - repo: TouchBistro/ordering-gateways-frontend + repo: + name: TouchBistro/ordering-gateways-frontend build: <<: *build-node-dev volumes: @@ -576,7 +598,8 @@ services: ports: - '8005:8080' preRun: yarn db:prepare - repo: TouchBistro/ordering-ooa-service + repo: + name: TouchBistro/ordering-ooa-service build: <<: *build-node-dev volumes: @@ -620,7 +643,8 @@ services: ports: - '8090:8080' preRun: yarn db:prepare - repo: TouchBistro/partners-config-service + repo: + name: TouchBistro/partners-config-service build: <<: *build-node-dev volumes: @@ -657,7 +681,8 @@ services: ports: - '8888:8080' preRun: yarn db:prepare - repo: TouchBistro/partners-etl-service + repo: + name: TouchBistro/partners-etl-service build: <<: *build-node-dev volumes: @@ -679,7 +704,8 @@ services: ports: - '8008:8080' preRun: yarn db:prepare - repo: TouchBistro/payments-gateway-service + repo: + name: TouchBistro/payments-gateway-service build: <<: *build-node-dev remote: @@ -690,7 +716,8 @@ services: mode: remote ports: - '3306:3306' - repo: TouchBistro/singleapp-database + repo: + name: TouchBistro/singleapp-database build: dockerfilePath: ${@REPOPATH} volumes: @@ -717,7 +744,8 @@ services: mode: remote ports: - '9002:9002' - repo: TouchBistro/venue-admin-frontend + repo: + name: TouchBistro/venue-admin-frontend build: args: NPM_TOKEN: $NPM_TOKEN @@ -758,7 +786,8 @@ services: - '9903:8090' # rtail log server # - '8089:8089' # Not used? preRun: yarn db:prepare - repo: TouchBistro/venue-core-service + repo: + name: TouchBistro/venue-core-service build: <<: *build-node-dev volumes: @@ -782,7 +811,8 @@ services: ports: - '8666:8080' preRun: yarn db:prepare - repo: TouchBistro/venue-provisioning-service + repo: + name: TouchBistro/venue-provisioning-service build: <<: *build-node-dev remote: @@ -795,7 +825,8 @@ services: mode: build ports: - '8023:80' - repo: TouchBistro/yp-singleapp-api + repo: + name: TouchBistro/yp-singleapp-api build: args: HOMEBREW_GITHUB_API_TOKEN: $HOMEBREW_GITHUB_API_TOKEN