-
Notifications
You must be signed in to change notification settings - Fork 4
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
PROP-27 - Implement Registry proxy #32
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
57bcec1
Initial implementation of HTTP to MQTT proxy
nyagamunene 3a10e82
update mqtt client and http client
nyagamunene 2c29619
refactor oras http
nyagamunene b83e12d
add env file and main file
nyagamunene 3fedc22
add env file and main file
nyagamunene 0401587
update go.mod and go.sum file
nyagamunene e2ac8c5
fix failing linter
nyagamunene e9755d2
fix tag align
nyagamunene 16a8e47
fix failing linter
nyagamunene 046a167
fix start method
nyagamunene ee09666
remove white spaces
nyagamunene b442273
fix failing linter
nyagamunene 26a6706
fix failing linter
nyagamunene 48bf08f
address comments and change how data is sent
nyagamunene ebea46b
fix failing linter
nyagamunene 2f4621a
fix failing linter
nyagamunene 7751314
add logging
nyagamunene 182f89f
add documentation and debug connection issue
nyagamunene a86c749
update go mod and go sum file
nyagamunene 1f4b1a5
remove password
nyagamunene 0b323e6
add comments
nyagamunene b1d7f38
fix failing linter
nyagamunene df6c46c
add validation
nyagamunene 7356002
adjust size of data sent via nats
nyagamunene b9a4d20
add contants
nyagamunene f9aa43e
refactor FetchFromReg
nyagamunene 50f4f32
add logging after all chunks were sent sucessfully
nyagamunene fa04558
change chunk_payload type
nyagamunene 4c718e4
update test documentation
nyagamunene 27608f0
update env variables
nyagamunene fb81865
fix failing linter
nyagamunene c31f6d5
update env file
nyagamunene 93cb573
remove proxy read me
nyagamunene 471d22e
intergrate proplet and manager with proxy
nyagamunene b439ca0
remove unused variable
nyagamunene 6c13917
address comments
nyagamunene 03b75aa
remove linter check
nyagamunene a1f4940
address comments
nyagamunene cf7a9eb
remove test.md file
nyagamunene 0f70398
update make install command
nyagamunene febf61c
update make install command
nyagamunene 2da6d97
add comments to make install command
nyagamunene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# Propellerd Build | ||
build | ||
config.toml |
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ linters: | |
- err113 | ||
- noctx | ||
- cyclop | ||
- tagalign | ||
|
||
linters-settings: | ||
gocritic: | ||
|
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,111 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/absmach/propeller/proxy" | ||
"github.com/caarlos0/env/v11" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
const svcName = "proxy" | ||
|
||
type config struct { | ||
LogLevel string `env:"PROXY_LOG_LEVEL" envDefault:"info"` | ||
|
||
BrokerURL string `env:"PROPLET_MQTT_ADDRESS" envDefault:"tcp://localhost:1883"` | ||
PropletKey string `env:"PROPLET_THING_KEY,notEmpty"` | ||
PropletID string `env:"PROPLET_THING_ID,notEmpty" ` | ||
ChannelID string `env:"PROPLET_CHANNEL_ID,notEmpty"` | ||
|
||
ChunkSize int `env:"PROXY_CHUNK_SIZE" envDefault:"512000"` | ||
Authenticate bool `env:"PROXY_AUTHENTICATE" envDefault:"false"` | ||
Token string `env:"PROXY_REGISTRY_TOKEN" envDefault:""` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need token and password or it is either one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its either of the 2 |
||
Username string `env:"PROXY_REGISTRY_USERNAME" envDefault:""` | ||
Password string `env:"PROXY_REGISTRY_PASSWORD" envDefault:""` | ||
RegistryURL string `env:"PROXY_REGISTRY_URL,notEmpty"` | ||
} | ||
|
||
func main() { | ||
g, ctx := errgroup.WithContext(context.Background()) | ||
|
||
cfg := config{} | ||
if err := env.Parse(&cfg); err != nil { | ||
log.Fatalf("failed to load configuration : %s", err.Error()) | ||
} | ||
|
||
var level slog.Level | ||
if err := level.UnmarshalText([]byte(cfg.LogLevel)); err != nil { | ||
log.Fatalf("failed to parse log level: %s", err.Error()) | ||
} | ||
logHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ | ||
Level: level, | ||
}) | ||
logger := slog.New(logHandler) | ||
slog.SetDefault(logger) | ||
|
||
mqttCfg := proxy.MQTTProxyConfig{ | ||
BrokerURL: cfg.BrokerURL, | ||
Password: cfg.PropletKey, | ||
PropletID: cfg.PropletID, | ||
ChannelID: cfg.ChannelID, | ||
} | ||
|
||
httpCfg := proxy.HTTPProxyConfig{ | ||
ChunkSize: cfg.ChunkSize, | ||
Authenticate: cfg.Authenticate, | ||
Token: cfg.Token, | ||
Username: cfg.Username, | ||
Password: cfg.Password, | ||
RegistryURL: cfg.RegistryURL, | ||
} | ||
|
||
logger.Info("successfully initialized MQTT and HTTP config") | ||
|
||
service, err := proxy.NewService(ctx, &mqttCfg, &httpCfg, logger) | ||
if err != nil { | ||
logger.Error("failed to create proxy service", slog.Any("error", err)) | ||
|
||
return | ||
} | ||
|
||
logger.Info("starting proxy service") | ||
|
||
if err := start(ctx, g, service); err != nil { | ||
logger.Error(fmt.Sprintf("%s service exited with error: %s", svcName, err)) | ||
} | ||
} | ||
|
||
func start(ctx context.Context, g *errgroup.Group, s *proxy.ProxyService) error { | ||
if err := s.MQTTClient().Connect(ctx); err != nil { | ||
return fmt.Errorf("failed to connect to MQTT broker: %w", err) | ||
} | ||
|
||
slog.Info("successfully connected to broker") | ||
|
||
defer func() { | ||
if err := s.MQTTClient().Disconnect(ctx); err != nil { | ||
slog.Error("failed to disconnect MQTT client", "error", err) | ||
} | ||
}() | ||
|
||
if err := s.MQTTClient().Subscribe(ctx, s.ContainerChan()); err != nil { | ||
return fmt.Errorf("failed to subscribe to container requests: %w", err) | ||
} | ||
|
||
slog.Info("successfully subscribed to topic") | ||
|
||
g.Go(func() error { | ||
return s.StreamHTTP(ctx) | ||
}) | ||
|
||
g.Go(func() error { | ||
return s.StreamMQTT(ctx) | ||
}) | ||
|
||
return g.Wait() | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible, in order to simplify handling of binaries, to have a subdir
wasm
withinbuild
dir, and put all Wasm binaries there. I guess these binaries are coming from examples, right? If really needed you can also addbuild/bin
andbuild/wasm
, but I do not think that we needbuild/bin
(as most of the time we'll need just Propeller services (and not examples), and they can live directly in the topbuild
dir, for convenience), but if this simplifies copying, then please go ahead and make bothbuild/bin
andbuild/wasm
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, as you would need to prefix each bin anyway - I will merge as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can implement this .