diff --git a/README.md b/README.md index 1651e1c..4df64a9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # global_docker_compose -`global_docker_compose` is a centralized way to manage your external dependencies across multiple projects. You start up your Docker services once, and all relevant ports are exposed so that you can use them in your apps. You don't need special `docker-compose.yml` files in each app, nor do you have multiple versions of MySQL or Kafka running around. +`global_docker_compose` is a centralized way to manage your external dependencies across multiple projects. You start up your Docker services once, and all relevant ports are exposed so that you can use them in your apps. You don't need special `docker-compose.yml` files in each app, nor do you have multiple versions of MySQL or Kafka running around. The idea behind `global_docker_compose` is to have everything *but* your app running in a Docker container. `global_docker_compose` is the central place to manage making those containers "good", including volumes, correct port exposure, hostnames, etc. @@ -31,6 +31,8 @@ Or you can build it from source by running the following from the root directory * `global_docker_compose exec ` Execute a command on an existing service. * `global_docker_compose mysql --service= {input_file}` Start a MySQL client against whatever MySQL service is provided (e.g. `mysql56`). If an input file is provided, execute the statements in the input file. Additional services can be specified in the `` parameter; they will be ignored. * `global_docker_compose redis_cli` Start the Redis CLI (assuming `redis` is running) +* `global_docker_compose build {service}` Build the target service image +* `global_docker_compose build --no-cache {service}` Build the target service image without caching build steps The recommended usage of this command is via a shell script that lives in your project which automatically passes through the services that the app cares about. For example, in an executable file called `gdc`: @@ -51,7 +53,7 @@ All services are exposed with the host IP of `127.0.0.1`. If you use `localhost` ## Additional Compose Files -`global_docker_compose` allows to supply an additional docker-compose file to augment the built-in ones with the `--compose_file` option. This file will be merged with the built-in ones using [docker-compose's merging rules](https://docs.docker.com/compose/extends/#adding-and-overriding-configuration). +`global_docker_compose` allows to supply an additional docker-compose file to augment the built-in ones with the `--compose_file` option. This file will be merged with the built-in ones using [docker-compose's merging rules](https://docs.docker.com/compose/extends/#adding-and-overriding-configuration). Note that if you define new services with this file, you must pass in the service name with the `--services` option along with the other ones. @@ -189,7 +191,7 @@ The steps to add a new service are: ## Troubleshooting -If you are on an M* macOS machine, you might run into trouble getting GDC to run. +If you are on an M* macOS machine, you might run into trouble getting GDC to run. ### Error: `no matching manifest for linux/arm64/v8 in the manifest list entries` @@ -218,5 +220,5 @@ ln -sfn $(brew --prefix)/opt/docker-compose/bin/docker-compose ~/.docker/cli-plu We also made sure `colima`, `docker`, `docker-compose` and `XCode` were all up to date. -[Fadmin Troubleshooting docs]([url](https://flippit.atlassian.net/wiki/spaces/CTLR/pages/10448437272/End-to-end+Fadmin+WES+local+setup#Troubleshooting)https://flippit.atlassian.net/wiki/spaces/CTLR/pages/10448437272/End-to-end+Fadmin+WES+local+setup#Troubleshooting) +[Fadmin Troubleshooting docs]([url](https://flippit.atlassian.net/wiki/spaces/CTLR/pages/10448437272/End-to-end+Fadmin+WES+local+setup#Troubleshooting)https://flippit.atlassian.net/wiki/spaces/CTLR/pages/10448437272/End-to-end+Fadmin+WES+local+setup#Troubleshooting) diff --git a/cmd/gdc/commands/build.go b/cmd/gdc/commands/build.go new file mode 100644 index 0000000..ad00012 --- /dev/null +++ b/cmd/gdc/commands/build.go @@ -0,0 +1,48 @@ +/* +Package commands Copyright © 2021 NAME HERE + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package commands + +import ( + "github.com/spf13/cobra" + "github.com/wishabi/global-docker-compose/gdc" +) + +var NoCache bool + +// UpCmd represents the up command +var BuildCmd = &cobra.Command{ + Use: "build", + Short: "Build a target service", + Long: `Build the image for the given target service. When --no-cache is added, the image will be built without using the cache.`, + Args: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return cobra.MinimumNArgs(1)(cmd, args) + } + if len(args) > 1 { + return cobra.MaximumNArgs(1)(cmd, args) + } + return nil + }, + Run: func(cmd *cobra.Command, args []string) { + info := gdc.NewComposeInfo(ComposeFile, Services) + gdc.Build(args[0], info, NoCache) + }, +} + +func init() { + BuildCmd.Flags().BoolVarP(&NoCache, "no-cache", "n", false, "Build the image without using the cache") + rootCmd.AddCommand(BuildCmd) +} diff --git a/cmd/gdc/commands/root.go b/cmd/gdc/commands/root.go index f80f769..58d4e85 100644 --- a/cmd/gdc/commands/root.go +++ b/cmd/gdc/commands/root.go @@ -19,7 +19,7 @@ var ComposeFile string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Version: "0.8.0", + Version: "0.9.0", Use: "global_docker_compose (command) --services service1 service2 --compose_file ../docker-compose.yml", Short: "Generate JSON files to use with the Flipp platform deploy scripts", Long: ` diff --git a/gdc/docker.go b/gdc/docker.go index 06f47b8..ddb39bb 100644 --- a/gdc/docker.go +++ b/gdc/docker.go @@ -114,10 +114,24 @@ func executeDockerCommand(compose ComposeInfo, service string, command string, i } } +func ecrLogin() { + RunCommands("aws ecr get-login-password", "docker login --password-stdin -u AWS 421990735784.dkr.ecr.us-east-1.amazonaws.com") +} + +func Build(service string, compose ComposeInfo, noCache bool) { + cmd := fmt.Sprintf("%s build", mainCommand(compose)) + if noCache { + cmd = fmt.Sprintf("%s --no-cache", cmd) + } + + ecrLogin() + RunCommand("%s %s", cmd, service) +} + // Up bring up the Docker containers func Up(compose ComposeInfo) { str := serviceString(compose, "up") - RunCommands("aws ecr get-login-password", "docker login --password-stdin -u AWS 421990735784.dkr.ecr.us-east-1.amazonaws.com") + ecrLogin() RunCommand("%s up -d %s", mainCommand(compose), str) }