Skip to content
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
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: stable
- name: install buf
run: go install github.com/bufbuild/buf/cmd/buf@latest
- name: install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
- name: install protoc-gen-connect-go
run: go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest
- name: install grpcurl
run: go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
- name: generate proto
run: make build/proto
- name: run goreleaser
uses: goreleaser/goreleaser-action@v6
with:
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/proto:
buf generate
build/server:
go build ./server
build/cli:
go build ./cli

test/server:
go test -v ./server/tests/.../
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

### Server

- Chi Router
- Docker Sdk
- [ConnectRPC](https://connectrpc.com)

## Configuration

Expand Down
9 changes: 9 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v2
plugins:
- local: protoc-gen-go
opt: paths=source_relative
out: .
- local: protoc-gen-connect-go
out: .
opt: paths=source_relative

9 changes: 9 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
lint:
use:
- STANDARD
breaking:
use:
- FILE

136 changes: 0 additions & 136 deletions cli/go.sum

This file was deleted.

56 changes: 25 additions & 31 deletions cli/handlers/docker/create.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package docker

import (
"bytes"
"encoding/json"
"context"
"fmt"
"io"
"net/http"
"time"

"connectrpc.com/connect"
"github.com/charmbracelet/huh/spinner"
"github.com/matfire/pockets/cli/config"
"github.com/matfire/pockets/cli/rpc"
sharedv1 "github.com/matfire/pockets/shared/v1"
)

type CreateRequestBody struct {
Expand All @@ -27,25 +27,25 @@ type ImageCheckResponse struct {

func Create(config *config.App, name string, version string) {
imageExists := false
checkImage := func() {
res, err := http.Get(fmt.Sprintf("%s/v1/image/check/%s", config.Endpoint, version))
var data ImageCheckResponse
client := rpc.GetRPCCLient(config)
checkImage := func() bool {
res, err := client.CheckImage(context.Background(), connect.NewRequest(&sharedv1.CheckImageRequest{
Version: version,
}))
if err != nil {
panic(err)
}
b, err := io.ReadAll(res.Body)
json.Unmarshal(b, &data)
defer res.Body.Close()
imageExists = data.Exists
imageExists = res.Msg.Exists
return res.Msg.Exists
}

createImage := func() {
body := ImageCreateRequestBody{Version: version}
b, err := json.Marshal(body)
_, err := client.CreateImage(context.Background(), connect.NewRequest(&sharedv1.CreateImageRequest{
Version: version,
}))
if err != nil {
panic("could not marshal image create request body")
panic(err)
}
_, err = http.Post(fmt.Sprintf("%s/v1/image/new", config.Endpoint), "application/json", bytes.NewBuffer(b))
}

//TODO customize retries & interval
Expand All @@ -55,15 +55,9 @@ func Create(config *config.App, name string, version string) {
if iterations > 5 {
panic("image is taking too long")
}
res, err := http.Get(fmt.Sprintf("%s/v1/image/check/%s", config.Endpoint, version))
if err != nil {
break
}
var data ImageCheckResponse
b, err := io.ReadAll(res.Body)
json.Unmarshal(b, &data)
defer res.Body.Close()
if data.Exists {

exists := checkImage()
if exists {
break
}
iterations++
Expand All @@ -72,18 +66,18 @@ func Create(config *config.App, name string, version string) {
}

createContainer := func() {
body := CreateRequestBody{Name: name, Version: version}
b, err := json.Marshal(body)
if err != nil {
fmt.Printf("could not marshal body in create request \n")
}
_, err = http.Post(fmt.Sprintf("%s/v1/create", config.Endpoint), "application/json", bytes.NewBuffer(b))
_, err := client.CreateContainer(context.Background(), connect.NewRequest(&sharedv1.CreateContainerRequest{
Name: name,
Version: version,
}))
if err != nil {
fmt.Printf("create request failed with error %v", err)
return
}
}
if err := spinner.New().Title("Checking for image existence...").Action(checkImage).Run(); err != nil {
if err := spinner.New().Title("Checking for image existence...").Action(func() {
checkImage()
}).Run(); err != nil {
fmt.Println(err)
}
if imageExists {
Expand Down
20 changes: 7 additions & 13 deletions cli/handlers/docker/delete.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
package docker

import (
"context"
"fmt"
"net/http"

"connectrpc.com/connect"
"github.com/charmbracelet/huh/spinner"
"github.com/matfire/pockets/cli/config"
"github.com/matfire/pockets/cli/rpc"
sharedv1 "github.com/matfire/pockets/shared/v1"
)

func Delete(config *config.App, name string) {
var err error
client := rpc.GetRPCCLient(config)
stopContainer := func() {
request, requestError := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/v1/delete/%s", config.Endpoint, name), nil)
if requestError != nil {
fmt.Printf("create request failed with error %v", requestError)
return
}
client := &http.Client{}
_, requestError = client.Do(request)
if requestError != nil {
fmt.Printf("create request failed with error %v", requestError)
return
}
err = requestError
_, errr := client.DeleteContainer(context.Background(), connect.NewRequest(&sharedv1.DeleteContainerRequest{Id: name}))
err = errr
}
if spinnerErr := spinner.New().Title("Deleting Container...").Action(stopContainer).Run(); spinnerErr != nil {
fmt.Println(spinnerErr)
Expand Down
20 changes: 9 additions & 11 deletions cli/handlers/docker/list.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package docker

import (
"encoding/json"
"context"
"fmt"
"io"
"net/http"

"connectrpc.com/connect"
"github.com/charmbracelet/huh/spinner"
"github.com/charmbracelet/lipgloss/table"
"github.com/matfire/pockets/cli/config"
"github.com/matfire/pockets/cli/rpc"
sharedv1 "github.com/matfire/pockets/shared/v1"
)

type Container struct {
Expand All @@ -21,17 +22,14 @@ type ListResponse struct {

func List(config *config.App) {
fmt.Print("listing containers")

var data ListResponse
client := rpc.GetRPCCLient(config)
var data *sharedv1.GetContainersResponse
getContainers := func() {
res, err := http.Get(fmt.Sprintf("%s/v1/status", config.Endpoint))
res, err := client.GetContainers(context.Background(), connect.NewRequest(&sharedv1.GetContainersRequest{}))
if err != nil {
panic("could not get data")
panic(err)
}
b, err := io.ReadAll(res.Body)
defer res.Body.Close()
json.Unmarshal(b, &data)

data = res.Msg
}
if err := spinner.New().Title("Fetching containers...").Action(getContainers).Run(); err != nil {
fmt.Println(err)
Expand Down
Loading