Skip to content

Commit

Permalink
fix run with named service
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuda committed Aug 1, 2024
1 parent cf7afd3 commit c6e3f7d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 28 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and Release

on:
workflow_run:
workflows: ["Go"] # Name of the workflow to listen for
types:
- completed # Trigger this workflow when the Go workflow completes

jobs:
build:
if: ${{ github.event.workflow_run.conclusion == 'success' }} # Only run if the Go workflow succeeded
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21' # Set your Go version

- name: Extract version
id: get_version
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV # Use the branch/tag name

- name: Build for Linux
run: |
GOOS=linux GOARCH=amd64 go build -o dockermi-linux-${{ env.VERSION }} main.go
tar -czvf dockermi-linux-${{ env.VERSION }}.tar.gz dockermi-linux-${{ env.VERSION }}
- name: Build for macOS
run: |
GOOS=darwin GOARCH=amd64 go build -o dockermi-macos-${{ env.VERSION }} main.go
tar -czvf dockermi-macos-${{ env.VERSION }}.tar.gz dockermi-macos-${{ env.VERSION }}
- name: Build for Windows
run: |
GOOS=windows GOARCH=amd64 go build -o dockermi-${{ env.VERSION }}.exe main.go
zip dockermi-${{ env.VERSION }}.zip dockermi-${{ env.VERSION }}.exe
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag: ${{ github.ref_name }} # Use the branch/tag name
files: |
dockermi-linux-${{ env.VERSION }}.tar.gz
dockermi-macos-${{ env.VERSION }}.tar.gz
dockermi-${{ env.VERSION }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 15 additions & 20 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
#!/bin/bash

# Function to build the application for Linux or macOS
build_app() {
echo "Building for $1..."
GOOS="$1" GOARCH=amd64 go build -o dockermi main.go
echo "Build completed! The executable is dockermi."
}

# Function to install the application
install_app() {
case "$1" in
linux)
echo "Installing dockermi on Linux..."
cp dockermi /usr/local/bin/dockermi
chmod +x /usr/local/bin/dockermi
echo "dockermi installed! You can run it by typing 'dockermi' in your terminal."
;;
darwin)
echo "Installing dockermi on macOS..."
cp dockermi /usr/local/bin/dockermi
chmod +x /usr/local/bin/dockermi
echo "dockermi installed! You can run it by typing 'dockermi' in your terminal."
;;
*)
echo "Unsupported operating system for installation: $1"
exit 1
;;
esac
echo "Installing dockermi on $1..."
cp dockermi /usr/local/bin/dockermi
chmod +x /usr/local/bin/dockermi
echo "dockermi installed! You can run it by typing 'dockermi' in your terminal."
}

# Detect the operating system
# Detect the operating system and perform actions
OS="$(uname -s)"
case "$OS" in
Linux)
build_app linux
install_app linux
;;
Darwin)
build_app darwin
install_app darwin
;;
*)
echo "This script only supports Linux and macOS."
exit 1
;;
esac
esac
6 changes: 3 additions & 3 deletions internal/script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func CreateDockermiScript(scriptPath string, services DockermiTypes.ServiceScrip
defer dockermiScript.Close()

dockermiScript.WriteString("#!/bin/bash\n\n")
dockermiScript.WriteString("# Usage: ./dockermi.sh [up|down] [options]\n\n")
dockermiScript.WriteString("# Usage: dockermi [up|down] [options]\n\n")

// Sort services for starting (ascending order)
sort.Slice(services, func(i, j int) bool {
Expand All @@ -35,7 +35,7 @@ func CreateDockermiScript(scriptPath string, services DockermiTypes.ServiceScrip

for _, service := range services {
dockermiScript.WriteString(fmt.Sprintf(" echo \"Starting %s...\"\n", service.ServiceName))
dockermiScript.WriteString(fmt.Sprintf(" docker-compose -f \"%s\" up \"$@\" \n", service.ComposeFile)) // Pass additional options
dockermiScript.WriteString(fmt.Sprintf(" docker-compose -f \"%s\" up \"%s\" \"$@\"\n", service.ComposeFile, service.ServiceName)) // Pass additional options and specify the service name
color.Cyan("\n Creating script for %v", service.ServiceName)
bar.Add(1)

Expand All @@ -50,7 +50,7 @@ func CreateDockermiScript(scriptPath string, services DockermiTypes.ServiceScrip
})
for _, service := range services {
dockermiScript.WriteString(fmt.Sprintf(" echo \"Stopping %s...\"\n", service.ServiceName))
dockermiScript.WriteString(fmt.Sprintf(" docker-compose -f \"%s\" down \"$@\"\n", service.ComposeFile)) // Pass additional options
dockermiScript.WriteString(fmt.Sprintf(" docker-compose -f \"%s\" down \"%s\" \"$@\"\n", service.ComposeFile, service.ServiceName))
bar.Add(1)
time.Sleep(500 * time.Millisecond) // Simulate delay for demonstration
}
Expand Down
15 changes: 10 additions & 5 deletions pkg/dockermi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/fatih/color"
)

const version = "0.1.0"
const version = "0.1.1"

// RunDockermi executes the main logic of the dockermi command. It takes a
// projectDir parameter, which specifies the directory where the function
Expand All @@ -29,14 +29,19 @@ const version = "0.1.0"
// - string: Path location of created dockermi.sh
// - error: if any errors occur during the execution, they are returned
func RunDockermi(projectDir string) (string, error) {
if len(os.Args) > 1 && os.Args[1] == "--version" {
// Define flags for help and version
help := flag.Bool("help", false, "Display help information")
versionFlag := flag.Bool("version", false, "Display version information")
// Short version flag
shortVersionFlag := flag.Bool("v", false, "Display version information")
flag.Parse()

// Check for version flags
if *versionFlag || *shortVersionFlag {
fmt.Println("Dockermi version:", version)
os.Exit(0)
}

help := flag.Bool("help", false, "Display help information")
flag.Parse()

if *help {
dockermiUtils.DisplayHelp()
return "", nil
Expand Down

0 comments on commit c6e3f7d

Please sign in to comment.