Skip to content

Commit

Permalink
build command (#12)
Browse files Browse the repository at this point in the history
* build command

* updated version

---------

Co-authored-by: Edward Tam <[email protected]>
  • Loading branch information
etam-pro and Edward Tam authored Mar 15, 2024
1 parent 3d03872 commit d3ebcc7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -31,6 +31,8 @@ Or you can build it from source by running the following from the root directory
* `global_docker_compose exec <service> <command>` Execute a command on an existing service.
* `global_docker_compose mysql --service=<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 `<service>` 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`:

Expand All @@ -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.

Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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)

48 changes: 48 additions & 0 deletions cmd/gdc/commands/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Package commands Copyright © 2021 NAME HERE <EMAIL ADDRESS>
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)
}
2 changes: 1 addition & 1 deletion cmd/gdc/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down
16 changes: 15 additions & 1 deletion gdc/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit d3ebcc7

Please sign in to comment.