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

DP-362 - Add Global Docker Compose Stop #13

Merged
merged 5 commits into from
Jun 12, 2024
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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last change goreleaser pushed a v2 that latest started pulling (and failing the CI due to a command removal). I felt updating to v2 of goreleaser was out of scope for this PR so I changed it to pull the most recent version of 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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need license stuff in here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I don't see why it's needed but all the other commands have it at the top so I added it.

Really just a case of if everyone else does it, would you. In this case yes ... yes I would. 😂


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.
Loading