Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup #2

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Validate PRs

on:
pull_request:
branches: [ main ]

jobs:
go:
name: Check sources
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.6

- name: Check go.mod
run: |
go mod tidy
if ! git diff --quiet; then
echo "Go modules need tidying (go mod tidy)"
exit 1
fi

- name: Check format
run: |
go fmt ./...
if ! git diff --quiet; then
echo "Files are not formatted (go fmt ./...)"
exit 1
fi

- name: Check build
run: |
if ! go build; then
echo "Project does not build"
exit 1
fi
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
rootCmd.AddCommand(pull.NewCmdPull())
rootCmd.AddCommand(push.NewCmdPush())
rootCmd.AddCommand(models.NewCmdModels())

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
Expand All @@ -55,5 +55,3 @@ func init() {
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}


2 changes: 1 addition & 1 deletion pkg/artifact/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const (

// Media type for the model config (Jozufile)
ModelConfigMediaType = "application/vnd.jozu.model.config.v1+json"
)
)
11 changes: 3 additions & 8 deletions pkg/artifact/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ package artifact

type Model struct {
Repository string
Tag string
Layers []*ModelLayer
Config *JozuFile
Tag string
Layers []*ModelLayer
Config *JozuFile
}


func NewModel() *Model {
return &Model{}
}
15 changes: 7 additions & 8 deletions pkg/artifact/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type Store struct {

func NewArtifactStore() *Store {

store, error := oci.New(".jozuStore")
if error != nil {
panic(error)
store, err := oci.New(".jozuStore")
if err != nil {
panic(err)
}

return &Store{
Expand All @@ -45,7 +45,6 @@ func (store *Store) saveContentLayer(layer *ModelLayer) (*v1.Descriptor, error)
MediaType: ModelLayerMediaType,
Digest: digest.FromBytes(buf.Bytes()),
Size: int64(buf.Len()),

}
err = store.Storage.Push(ctx, desc, buf)
layer.Descriptor = desc
Expand All @@ -56,7 +55,7 @@ func (store *Store) saveContentLayer(layer *ModelLayer) (*v1.Descriptor, error)
return &desc, nil
}

func (store *Store) saveConfigFile(model *JozuFile) (*v1.Descriptor, error) {
func (store *Store) saveConfigFile(model *JozuFile) (*v1.Descriptor, error) {
ctx := context.Background()
buf, err := model.MarshalToJSON()
if err != nil {
Expand All @@ -78,8 +77,8 @@ func (store *Store) saveModelManifest(model *Model, config *v1.Descriptor) (*v1.
ctx := context.Background()
manifest := v1.Manifest{
Versioned: specs.Versioned{SchemaVersion: 2},
Config: *config,
Layers: []v1.Descriptor{},
Config: *config,
Layers: []v1.Descriptor{},
}
// Add the layers to the manifest
for _, layer := range model.Layers {
Expand Down Expand Up @@ -120,4 +119,4 @@ func (store *Store) SaveModel(model *Model) (*v1.Manifest, error) {
return nil, err
}
return manifest, nil
}
}
11 changes: 5 additions & 6 deletions pkg/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (options *BuildOptions) RunBuild() error {
}
defer modelfile.Close()
jozufile := artifact.NewJozuFile()
jozufile.LoadModel(modelfile)
if err != nil {
if err = jozufile.LoadModel(modelfile); err != nil {
fmt.Println(err)
return err
}
Expand All @@ -99,14 +98,14 @@ func (options *BuildOptions) RunBuild() error {

// 3. Tar the build context and push to local registry
layer := artifact.NewLayer(options.ContextDir)
model := artifact.NewModel()
model := &artifact.Model{}
model.Layers = append(model.Layers, layer)
model.Config = jozufile
model.Config = jozufile

store := artifact.NewArtifactStore()
var manifest *v1.Manifest
manifest, err = store.SaveModel(model)
if(err != nil) {
if err != nil {
fmt.Println(err)
return err
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/cmd/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"testing"

"github.com/spf13/cobra"

"github.com/stretchr/testify/assert"
)


func TestNewCmdBuild(t *testing.T) {
cmd := NewCmdBuild()

Expand Down Expand Up @@ -49,7 +48,6 @@ func TestBuildOptions_RunBuild(t *testing.T) {
}

err := options.RunBuild()


assert.NoError(t, err)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/login/login.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2024 Jozu.com

*/
package login

Expand All @@ -10,7 +9,6 @@ import (
"github.com/spf13/cobra"
)


func NewCmdLogin() *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Expand Down
9 changes: 3 additions & 6 deletions pkg/cmd/models/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2024 Jozu.com

*/
package models

Expand All @@ -11,7 +10,6 @@ import (
)

type ModelsFlags struct {

}
type ModelsOptions struct {
}
Expand Down Expand Up @@ -41,17 +39,16 @@ func NewCmdModels() *cobra.Command {
return
}
options.RunModels()
if err != nil{
if err != nil {
fmt.Println(err)
return
return
}
},
}
modelsFlags.AddFlags(cmd)
modelsFlags.AddFlags(cmd)
return cmd
}


func NewModelsFlags() *ModelsFlags {
return &ModelsFlags{}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/pull/pull.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2024 Jozu.com

*/
package pull

Expand Down
4 changes: 1 addition & 3 deletions pkg/cmd/push/push.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2024 Jozu.com

*/
package push

Expand All @@ -13,7 +12,7 @@ import (
// pushCmd represents the push command

func NewCmdPush() *cobra.Command {

cmd := &cobra.Command{
Use: "push",
Short: "A brief description of your command",
Expand All @@ -30,7 +29,6 @@ func NewCmdPush() *cobra.Command {
return cmd
}


func init() {

// Here you will define your flags and configuration settings.
Expand Down