Skip to content

Commit 54f2db5

Browse files
committed
initial commit
0 parents  commit 54f2db5

16 files changed

Lines changed: 650 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v5
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v6
20+
with:
21+
go-version: "1.26"
22+
cache: true
23+
24+
- name: Run unit tests
25+
run: go test ./...
26+
27+
- name: Run golangci-lint
28+
uses: golangci/golangci-lint-action@v9
29+
with:
30+
version: latest

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v5
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v6
20+
with:
21+
go-version: "1.26"
22+
23+
- name: Run GoReleaser
24+
uses: goreleaser/goreleaser-action@v6
25+
with:
26+
version: latest
27+
args: release --clean
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.gocache
2+
shopmon-cli
3+
/composer.lock

.goreleaser.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: 2
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
7+
builds:
8+
- id: shopmon-cli
9+
binary: shopmon-cli
10+
env:
11+
- CGO_ENABLED=0
12+
goos:
13+
- linux
14+
goarch:
15+
- amd64
16+
- arm64
17+
ldflags:
18+
- -s -w
19+
dir: .
20+
21+
archives:
22+
- builds:
23+
- shopmon-cli
24+
format: tar.gz
25+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
26+
files:
27+
- LICENSE*
28+
- README.md
29+
30+
checksum:
31+
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt"
32+
33+
changelog:
34+
sort: desc
35+
filters:
36+
exclude:
37+
- "^docs:"
38+
- "^test:"
39+
40+
release:
41+
github:
42+
owner: friendsofshopware
43+
name: shopmon-cli

README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Shopmon CLI
2+
3+
A command-line tool for monitoring and managing Shopware applications with deployment telemetry.
4+
5+
## Features
6+
7+
- Execute deployment commands with transparent output
8+
- Capture command execution metrics (output, return code, execution time)
9+
- Read composer.json dependencies and include in telemetry
10+
- Send telemetry data to monitoring service
11+
- Support for custom monitoring endpoint via environment variable
12+
- Authorization token support for secure telemetry submission
13+
14+
## Usage
15+
16+
### Basic Usage
17+
18+
```bash
19+
./shopmon-cli deploy -- <command>
20+
```
21+
22+
### Examples
23+
24+
```bash
25+
# Execute a simple command
26+
./shopmon-cli deploy -- echo "Hello World"
27+
28+
# Run PHP artisan commands
29+
./shopmon-cli deploy -- php artisan migrate
30+
31+
# Execute composer commands
32+
./shopmon-cli deploy -- composer install
33+
34+
# Multiple word commands
35+
./shopmon-cli deploy -- npm run build
36+
```
37+
38+
### Environment Variables
39+
40+
- `SHOPMON_BASE_URL`: Override the default monitoring service URL (default: `https://shopmon.fos.gg`)
41+
- `SHOPMON_API_KEY`: Authorization token for the monitoring service (required, sent as Bearer token)
42+
- `SHOPMON_SHOP_ID`: Shop ID to include in telemetry
43+
- `SHOPMON_DEPLOYMENT_VERSION_REFERENCE`: Override the version reference (defaults to `git rev-parse HEAD`)
44+
45+
```bash
46+
# With custom URL
47+
SHOPMON_BASE_URL="http://localhost:8080" \
48+
SHOPMON_API_KEY="your-secret-token" \
49+
./shopmon-cli deploy -- php artisan migrate
50+
51+
# With authorization token
52+
SHOPMON_API_KEY="your-secret-token" ./shopmon-cli deploy -- composer install
53+
```
54+
55+
## Telemetry Payload
56+
57+
The deploy command sends the following JSON payload to the monitoring service endpoint (`/trpc/cli.createDeployment`):
58+
59+
```json
60+
{
61+
"shop_id": 1,
62+
"command": "php foo",
63+
"return_code": 0,
64+
"start_date": "2024-06-01T12:00:00Z",
65+
"end_date": "2024-06-01T12:00:01Z",
66+
"execution_time": 1.23,
67+
"composer": {
68+
"php": ">=8.1",
69+
"shopware/core": "6.5.0.0"
70+
},
71+
"reference": "abc123..."
72+
}
73+
```
74+
75+
When `SHOPMON_API_KEY` is set, the request includes an `Authorization: Bearer <token>` header for authentication.
76+
77+
## Development
78+
79+
### Project Structure
80+
81+
```
82+
shopmon-cli/
83+
├── cmd/ # Command definitions
84+
│ ├── root.go
85+
│ └── deploy.go
86+
├── internal/
87+
│ └── deployment/ # Core deployment logic
88+
│ ├── types.go # Data structures
89+
│ ├── executor.go # Command execution
90+
│ ├── composer.go # Composer.json parsing
91+
│ ├── telemetry.go # Telemetry client
92+
│ └── deployment.go # Main orchestration
93+
├── main.go
94+
├── go.mod
95+
└── go.sum
96+
```
97+
98+
### Building
99+
100+
```bash
101+
# Build the binary
102+
go build -o shopmon-cli .
103+
104+
# Build for different platforms
105+
GOOS=linux GOARCH=amd64 go build -o shopmon-cli-linux
106+
GOOS=darwin GOARCH=amd64 go build -o shopmon-cli-darwin
107+
GOOS=windows GOARCH=amd64 go build -o shopmon-cli.exe
108+
```
109+
110+
## Architecture
111+
112+
1. **cmd/**: CLI command definitions using Cobra
113+
2. **internal/deployment/**: Core logic split into:
114+
- **executor.go**: Runs the user's command and captures output, return code, and timing
115+
- **composer.go**: Reads `composer.json` to extract dependency info
116+
- **telemetry.go**: Sends deployment data to the monitoring service, uploads compressed output
117+
- **deployment.go**: Orchestrates the above into a single `Run()` function
118+
119+
### Key Design Decisions
120+
121+
- **Transparent Execution**: Command output is displayed to the user
122+
- **Error Resilience**: Telemetry failures don't affect command execution
123+
- **Exit Code Preservation**: The CLI exits with the same code as the executed command
124+
125+
## License
126+
127+
MIT

cmd/deploy.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/friendsofshopware/shopmon-cli/internal/deployment"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var deployCmd = &cobra.Command{
12+
Use: "deploy -- <command>",
13+
Short: "Execute and monitor deployment commands",
14+
Long: `Execute deployment commands, capture output, and send telemetry to the monitoring service.`,
15+
Example: " shopmon-cli deploy -- php artisan migrate\n shopmon-cli deploy -- composer install",
16+
DisableFlagParsing: true,
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
if token := os.Getenv("SHOPMON_API_KEY"); token == "" {
19+
return fmt.Errorf("SHOPMON_API_KEY environment variable must be set to use this command")
20+
}
21+
22+
return deployment.Run(args)
23+
},
24+
}

cmd/root.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var rootCmd = &cobra.Command{
8+
Use: "shopmon-cli",
9+
Short: "Shopware Monitoring CLI",
10+
Long: `A CLI tool for monitoring and managing Shopware applications.`,
11+
}
12+
13+
func Execute() error {
14+
return rootCmd.Execute()
15+
}
16+
17+
func init() {
18+
rootCmd.AddCommand(deployCmd)
19+
}

composer.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "shopware/production",
3+
"require": {
4+
"php": ">=8.1",
5+
"shopware/core": "6.5.0.0",
6+
"shopware/administration": "6.5.0.0",
7+
"shopware/storefront": "6.5.0.0"
8+
}
9+
}

go.mod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module github.com/friendsofshopware/shopmon-cli
2+
3+
go 1.26
4+
5+
require (
6+
github.com/klauspost/compress v1.18.4
7+
github.com/spf13/cobra v1.10.2
8+
)
9+
10+
require (
11+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
12+
github.com/spf13/pflag v1.0.10 // indirect
13+
)

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4+
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
5+
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
6+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7+
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
8+
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
9+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
10+
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
11+
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
12+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)