Skip to content

Commit

Permalink
DP-362 - Add Global Docker Compose Stop #13 from wishabi/dp-362
Browse files Browse the repository at this point in the history
* Adding stop to gdc

* Fixed changelog

* Go releaser moved to v2 (no intention of updating in this PR)
  • Loading branch information
dcbickfo authored Jun 12, 2024
1 parent 83484be commit 8b6029c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
version: "~> v1"
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## UNRELEASED

[0.11.0] - 2024-06-12

- Add stop command for docker-compose
- Remove the obsolete version tag from the docker-compose file

[0.10.1] - 2024-05-06

- Fix error on startup

[0.10.0] - 2024-05-02

- Fix for new MySQL 8 images.

[0.9.0] - 2024-03-15
Expand All @@ -19,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Bump version of Redis Insight to V2 and change the exported port to 5540.

[0.7.6] - 2024-03-04

- Bump version to 0.7.6
- Move to insights v2 (#10)

[0.7.5] - 2024-01-18

- Restore Lenses Box image for Kafka as it now works on arm64.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ Or you can build it from source by running the following from the root directory
`global_docker_compose` has multiple sub-commands, most of which should be familiar:

* `global_docker_compose up --service=<service1>,<service2>`: Bring up a list of services as defined by the table below.
* `global_docker_compose down {service}`: Bring down the specificed service, or all services if not provided.
* `global_docker_compose down {service}`: Bring down the specified service, or all services if not provided.
* `global_docker_compose down`: Bring down all services.
* `global_docker_compose stop --service=<service1>,<service2>`: Stop the specified services, or all services if not provided.
* `global_docker_compose stop`: Stop all services.
* `global_docker_compose ps`: Show all running services that were configured using the tool.
* `global_docker_compose config`: Print out the docker compose config file being used.
* `global_docker_compose logs {service}`: Print out logs for the specified service, or all services if not provided.
Expand Down
8 changes: 4 additions & 4 deletions cmd/gdc/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var ComposeFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Version: "0.10.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: `
Version: "0.11.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: `
global_docker_compose can be used to centralize and standardize Docker dependencies used within Flipp.
The idea is to have one tool that can spin up whatever services are needed and keep that tool updated
with fixes and improvements, rather than having a separate docker-compose.yml file in every project.
Expand Down
43 changes: 43 additions & 0 deletions cmd/gdc/commands/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
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"
)

// StopCmd represents the stop command
var StopCmd = &cobra.Command{
Use: "stop",
Short: "Stop Docker containers",
Long: `
Stop either specified or all Docker containers.
Usage: global_docker_compose stop {service}
global_docker_compose stop
`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
info := gdc.NewComposeInfo(ComposeFile, Services)
gdc.Stop(info)
gdc.Cleanup()
},
}

func init() {
rootCmd.AddCommand(StopCmd)
}
1 change: 0 additions & 1 deletion gdc/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.6'
services:

# ---------- DATABASES ----------
Expand Down
12 changes: 11 additions & 1 deletion gdc/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func Up(compose ComposeInfo) {
// Down bring down the Docker containers
func Down(compose ComposeInfo, service string) {
if len(compose.RequestedServices) > 0 {
fmt.Printf("Requsted services ,%v", compose.RequestedServices[0])
fmt.Printf("Requested services ,%v", compose.RequestedServices[0])
var command string
if service != "" {
command = service
Expand All @@ -152,6 +152,16 @@ func Down(compose ComposeInfo, service string) {
}
}

// Stop the Docker containers
func Stop(compose ComposeInfo) {
if len(compose.RequestedServices) > 0 {
fmt.Printf("Requested services ,%v", compose.RequestedServices[0])
RunCommand("%s stop %s", mainCommand(compose), serviceString(compose, "stop"))
} else {
RunCommand("%s stop", mainCommand(compose))
}
}

// Logs show the logs for the selected containers
func Logs(compose ComposeInfo, service string) {
var command string
Expand Down
Binary file modified global_docker_compose
Binary file not shown.

0 comments on commit 8b6029c

Please sign in to comment.