Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
chore: repo setup (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanduur authored Aug 2, 2023
1 parent 11d69a1 commit e442550
Show file tree
Hide file tree
Showing 21 changed files with 193 additions and 54 deletions.
33 changes: 33 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; https://editorconfig.org/

root = true

[*]
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
indent_style = tab
indent_size = 4

[*.{py}]
indent_style = space
indent_size = 4

# 2 space indentation
[*.{js,json,y{a,}ml}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
eclint_indent_style = unset

[Dockerfile]
indent_size = 4
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATES/bug_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Bug Report
description: You encountered bug? Unexpected behavior? Open this one.
title: "[BUG]: <title>"
labels:
- kind/bug
body:
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also, what did you expect to happen?
placeholder: Put your description here.
validations:
required: true
- type: textarea
id: logs
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: Text
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATES/feature_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Feature Request
description: You encountered bug? Unexpected behavior? Open this one.
title: "[FEATURE]: <title>"
labels:
- kind/feature
body:
- type: dropdown
id: contributor
attributes:
label: Are you interested in contributing to the development of this feature?
description: This will help us categorize the issue.
options:
- Yes
- No
validations:
required: true
- type: markdown
attributes:
label: Is your feature request related to a problem? Please describe.
description: A clear and concise description of what the problem is.
validations:
required: true
- type: markdown
attributes:
label: Describe the solution you'd like.
description: A clear and concise description of what you want to happen.
validations:
required: true
- type: markdown
attributes:
label: Describe alternatives you've considered.
description: A clear and concise description of any alternative solutions or features you've considered.
validations:
required: true
- type: input
id: additional_info
attributes:
label: Additional Information
description: Any other relevant information about the feature request.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ A Container Object Storage Interface (COSI) library and other helpful utilities
The following example illustrates using `gocosi` Object Storage Plugin bootstrapper to create a new COSI Object Storage Plugin from scratch:

```bash
mkdir -p cosi-osp && cd cosi-osp
go run \
github.com/doomshrine/gocosi/cmd/generate@main \
example.com/your/cosi-osp
github.com/doomshrine/gocosi/cmd/bootstrap@main \
-module example.com/your/cosi-osp \
-dir cosi-osp
```

You will obtain the following file structure in the `cosi-osp` folder:
Expand Down
51 changes: 32 additions & 19 deletions cmd/generate/main.go → cmd/bootstrap/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,10 +16,12 @@ package main

import (
"errors"
"flag"
"fmt"
"log"
"os"
"os/exec"
"path"
"text/template"
)

Expand All @@ -28,50 +30,60 @@ type Config struct {
GoVersion string
}

var (
modPath string
directory string
)

func main() {
if err := realMain(); err != nil {
flag.StringVar(&modPath, "module", "example.com/cosi-osp", "Provide name for your new module.")
flag.StringVar(&directory, "dir", "cosi-osp", "Location, where the module will be created.")
flag.Parse()

if err := realMain(modPath, directory); err != nil {
log.Fatal(err)
}
}

func realMain() error {
if len(os.Args) < 2 {
return errors.New("no name specified")
func realMain(modPath, location string) error {
if modPath == "" || location == "" {
return errors.New("invalid argument")
}

cfg := Config{
ModPath: os.Args[1],
ModPath: modPath,
GoVersion: "1.20",
}

err := os.MkdirAll("./servers/provisioner", 0o755)
if err != nil {
return fmt.Errorf("unable to create './servers/provisioner' directory: %w", err)
}

err = os.MkdirAll("./servers/identity", 0o755)
if err != nil {
return fmt.Errorf("unable to create './servers/identity' directory: %w", err)
for _, dir := range []string{
location,
path.Join(location, "servers/provisioner"),
path.Join(location, "servers/identity"),
} {
err := os.MkdirAll(dir, 0o755)
if err != nil {
return fmt.Errorf("unable to create '%s' directory: %w", dir, err)
}
}

for _, tpl := range []struct {
filepath string
template string
}{
{
filepath: "go.mod",
filepath: path.Join(location, "go.mod"),
template: goMod,
},
{
filepath: "main.go",
filepath: path.Join(location, "main.go"),
template: mainGo,
},
{
filepath: "./servers/provisioner/provisioner.go",
filepath: path.Join(location, "./servers/provisioner/provisioner.go"),
template: provisionerGo,
},
{
filepath: "./servers/identity/identity.go",
filepath: path.Join(location, "./servers/identity/identity.go"),
template: identityGo,
},
} {
Expand All @@ -82,10 +94,11 @@ func realMain() error {
}

cmd := exec.Command("go", "mod", "tidy")
cmd.Dir = location
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout

err = cmd.Run()
err := cmd.Run()
if err != nil {
return fmt.Errorf("failed running 'go mod tidy': %w", err)
}
Expand Down
41 changes: 41 additions & 0 deletions cmd/bootstrap/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"bytes"
"context"
"os"
"os/exec"
"testing"

"github.com/doomshrine/testcontext"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const TestModPath = "main.test/module"

func TestRealMain(t *testing.T) {
t.Parallel()

ctx, cancel := testcontext.FromT(context.Background(), t)
defer cancel()

dir, err := os.MkdirTemp("", "*")
require.NoError(t, err)

defer os.RemoveAll(dir)

err = realMain(TestModPath, dir)
require.NoError(t, err)

bufOut := new(bytes.Buffer)
bufErr := new(bytes.Buffer)

cmd := exec.CommandContext(ctx, "go", "build")
cmd.Dir = dir
cmd.Stderr = bufErr
cmd.Stdout = bufOut

err = cmd.Run()
assert.NoError(t, err, "stdout: >>>%s<<<, stderr: >>>%s<<<", bufOut.String(), bufErr.String())
}
4 changes: 2 additions & 2 deletions cmd/generate/templates.go → cmd/bootstrap/templates.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *Server) DriverGetInfo(_ context.Context, _ *cosi.DriverGetInfoRequest)
return &cosi.DriverGetInfoResponse{
Name: s.name,
}, nil
}
}
`

const provisionerGo = `package provisioner
Expand Down
27 changes: 10 additions & 17 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -18,29 +18,22 @@
//
// The following example illustrates using `gocosi` Object Storage Plugin bootstrapper to create a new COSI Object Storage Plugin from scratch:
//
// ```bash
// mkdir -p cosi-osp && cd cosi-osp
//
// go run \
// github.com/doomshrine/gocosi/cmd/generate@main \
// example.com/your/cosi-osp
//
// ```
// github.com/doomshrine/gocosi/cmd/bootstrap@main \
// -module example.com/your/cosi-osp \
// -dir cosi-osp
//
// You will obtain the following file structure in the `cosi-osp` folder:
//
// ```
// cosi-osp
// ├── go.mod
// ├── go.sum
// ├── main.go
// └── servers
//
// cosi-osp
// ├── go.mod
// ├── go.sum
// ├── main.go
// └── servers
// ├── identity
// │ └── identity.go
// └── provisioner
// └── provisioner.go
//
// 4 directories, 5 files
// ```
// 4 directories, 5 files
package gocosi
2 changes: 1 addition & 1 deletion endpoint.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion endpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion env.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion env_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion gocosi.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion gocosi_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion grpc/handlers/handlers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion grpc/log/log.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion metrics.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion mocking.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion testutils/mkdir.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 doomshrine and gocosi authors. All Rights Reserved.
// Copyright © 2023 gocosi authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down

0 comments on commit e442550

Please sign in to comment.