Skip to content

Commit

Permalink
Verify docker image working on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Nov 12, 2024
1 parent e3deb25 commit b38027c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ jobs:
uses: goreleaser/goreleaser-action@v6
with:
args: release --snapshot
- name: Verify docker images working
run: docker run --rm ghcr.io/chatwork/aws-checkercanary-amd64 aws-checker version
1 change: 1 addition & 0 deletions goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ builds:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X main.Version={{.Version}}
goos:
- darwin
- linux
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var Version = "dev"

func main() {
opts, code := parseFlags(os.Args[1:])
if code != nil {
os.Exit(*code)
}

// Create a channel to receive OS signals
sigs := make(chan os.Signal, 1)
// Register the channel to receive SIGINT, SIGTERM signals
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

if err := Run(ContextWithSignal(context.Background(), sigs)); err != nil {
if err := Run(ContextWithSignal(context.Background(), sigs), opts...); err != nil {
log.Fatalf("Error: %v", err)
}
}
Expand Down
42 changes: 42 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"flag"
"fmt"
)

func parseFlags(args []string) ([]Option, *int) {
fs := flag.NewFlagSet("aws-checker", flag.ContinueOnError)
fs.Usage = func() {
fmt.Fprintf(fs.Output(), "%s is a toolkit for checking availability of AWS services.\n", fs.Name())
fmt.Fprintf(fs.Output(), "Run '%s -help' for usage.\n", fs.Name())
}

var code int

if err := fs.Parse(args); err != nil {
if err != flag.ErrHelp {
code = 2
}
} else {
switch fs.NArg() {
case 0:
return []Option{}, nil
case 1:
switch fs.Arg(0) {
case "version":
fmt.Fprintf(fs.Output(), "%s %s", fs.Name(), Version)
default:
fmt.Fprintf(fs.Output(), "unknown command %q for %q\n", fs.Arg(0), fs.Name())
fmt.Fprintf(fs.Output(), "Run '%s -help' for usage.\n", fs.Name())
code = 2
}
default:
fmt.Fprintf(fs.Output(), "too many arguments\n")
fmt.Fprintf(fs.Output(), "Run '%s -help' for usage.\n", fs.Name())
code = 2
}
}

return nil, &code
}

0 comments on commit b38027c

Please sign in to comment.