-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cdeb73
commit 6ad5db9
Showing
18 changed files
with
286 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM golang:latest as build | ||
|
||
ADD . ./src | ||
|
||
WORKDIR /go/src | ||
|
||
RUN mkdir -p ./dist && go build -o ./dist/caster ./cmd/caster/main.go | ||
|
||
FROM ubuntu:22.04 | ||
RUN apt-get update && apt-get install -y ca-certificates openssl | ||
|
||
ARG cert_location=/usr/local/share/ca-certificates | ||
|
||
# Get certificate from "github.com" | ||
RUN openssl s_client -showcerts -connect github.com:443 </dev/null 2>/dev/null|openssl x509 -outform PEM > ${cert_location}/github.crt | ||
# Get certificate from "proxy.golang.org" | ||
RUN openssl s_client -showcerts -connect proxy.golang.org:443 </dev/null 2>/dev/null|openssl x509 -outform PEM > ${cert_location}/proxy.golang.crt | ||
# Update certificates | ||
RUN update-ca-certificates | ||
|
||
COPY --from=build /go/src/dist/caster /tmp/caster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/patrickhuber/caster/internal/global" | ||
"github.com/patrickhuber/caster/internal/initialize" | ||
"github.com/patrickhuber/go-di" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
const ( | ||
InitializeTemplateFlag = "template" | ||
) | ||
|
||
var Initialize = &cli.Command{ | ||
Name: "initialize", | ||
Aliases: []string{"init"}, | ||
Description: "initializes the speified directory or file with the default template", | ||
Usage: "initializes the speified directory or file with the default template", | ||
UsageText: "caster init [DIRECTORY|FIILE]", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: InitializeTemplateFlag, | ||
Aliases: []string{"t"}, | ||
Value: ".", | ||
}, | ||
}, | ||
} | ||
|
||
type InitializeCommand struct { | ||
Options InitializeOptions | ||
Service initialize.Service `inject:""` | ||
} | ||
|
||
type InitializeOptions struct { | ||
Template string | ||
} | ||
|
||
func InitAction(ctx *cli.Context) error { | ||
cmd := &InitializeCommand{} | ||
resolver := ctx.App.Metadata[global.DependencyInjectionContainer].(di.Resolver) | ||
err := di.Inject(resolver, cmd) | ||
if err != nil { | ||
return err | ||
} | ||
return cmd.Execute() | ||
} | ||
|
||
func (cmd *InitializeCommand) Execute() error { | ||
request := &initialize.Request{ | ||
Template: cmd.Options.Template, | ||
} | ||
_, err := cmd.Service.Initialize(request) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package commands | ||
|
||
import "testing" | ||
|
||
func TestInitialize(t *testing.T) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package initialize | ||
|
||
import ( | ||
"github.com/patrickhuber/go-xplat/filepath" | ||
"github.com/patrickhuber/go-xplat/fs" | ||
) | ||
|
||
type Request struct { | ||
Template string `yaml:"omitempty"` | ||
} | ||
|
||
type Response struct{} | ||
|
||
type Service interface { | ||
Initialize(req *Request) (*Response, error) | ||
} | ||
|
||
func NewService(fs fs.FS, path *filepath.Processor) Service { | ||
return &service{ | ||
fs: fs, | ||
path: path, | ||
} | ||
} | ||
|
||
type service struct { | ||
fs fs.FS | ||
path *filepath.Processor | ||
} | ||
|
||
func (s *service) Initialize(req *Request) (*Response, error) { | ||
|
||
// look for relative paths | ||
template, err := s.path.Abs(req.Template) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// is this a file or directory? | ||
stat, err := s.fs.Stat(template) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if stat.IsDir() { | ||
template = s.path.Join(template, ".caster.yml") | ||
} | ||
|
||
content := `files: | ||
- name: hello.txt | ||
content: "hello world"` | ||
|
||
err = s.fs.WriteFile(template, []byte(content), 0666) | ||
return &Response{}, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package initialize_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/patrickhuber/caster/internal/initialize" | ||
"github.com/patrickhuber/go-xplat/filepath" | ||
"github.com/patrickhuber/go-xplat/fs" | ||
"github.com/patrickhuber/go-xplat/os" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestService(t *testing.T) { | ||
o := os.NewLinuxMock() | ||
path := filepath.NewProcessorWithOS(o) | ||
fs := fs.NewMemory(fs.WithProcessor(path)) | ||
|
||
svc := initialize.NewService(fs, path) | ||
|
||
wd, err := o.WorkingDirectory() | ||
require.NoError(t, err) | ||
err = fs.MkdirAll(wd, 0666) | ||
require.NoError(t, err) | ||
|
||
res, err := svc.Initialize(&initialize.Request{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, res) | ||
|
||
filePath := path.Join(wd, ".caster.yml") | ||
ok, err := fs.Exists(filePath) | ||
require.NoError(t, err) | ||
require.True(t, ok) | ||
|
||
content, err := fs.ReadFile(filePath) | ||
require.NoError(t, err) | ||
require.NotNil(t, content) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.