Skip to content

Commit a27d978

Browse files
dido18lucarin91
andauthored
feat(arduino-app-cli): Upgrade the docker images and show the logs during the system updgrade (#606)
Co-authored-by: Luca Rinaldi <lucarin@protonmail.com>
1 parent fbbd8a2 commit a27d978

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

cmd/arduino-app-cli/daemon/daemon.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ func NewDaemonCmd(cfg config.Configuration, version string) *cobra.Command {
4545
} else {
4646
slog.Info("Default app started")
4747
}
48-
49-
slog.Info("Try to pull latest docker images in background...")
50-
err = orchestrator.SystemInit(
51-
cmd.Context(),
52-
cfg,
53-
servicelocator.GetStaticStore(),
54-
)
55-
if err != nil {
56-
slog.Error("Auto-pull process failed", slog.String("error", err.Error()))
57-
} else {
58-
slog.Info("Auto-pull process completed.")
59-
}
6048
}()
6149

6250
httpHandler(cmd.Context(), cfg, daemonPort, version)

internal/update/apt/service.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string) (<-chan u
8787
eventsCh <- update.Event{Type: update.UpgradeLineEvent, Data: line}
8888
}
8989

90+
// TEMPORARY PATCH: Install the latest docker images and show the logs to the users.
91+
// TODO: Remove this workaround once docker image versions are no longer hardcoded in arduino-app-cli.
92+
// Tracking issue: https://github.com/bcmi-labs/orchestrator/issues/600
93+
// Currently, we need to launch `arduino-app-cli system init` to pull the latest docker images because
94+
// the version of the docker images are hardcoded in the (new downloaded) version of the arduino-app-cli.
95+
eventsCh <- update.Event{Type: update.UpgradeLineEvent, Data: "Pulling the latest docker images ..."}
96+
streamDocker := pullDockerImages(ctx)
97+
for line, err := range streamDocker {
98+
if err != nil {
99+
eventsCh <- update.Event{
100+
Type: update.ErrorEvent,
101+
Err: err,
102+
Data: "Error upgrading docker images",
103+
}
104+
slog.Error("error upgrading docker images", "error", err)
105+
return
106+
}
107+
eventsCh <- update.Event{Type: update.UpgradeLineEvent, Data: line}
108+
}
109+
90110
eventsCh <- update.Event{Type: update.RestartEvent, Data: "Upgrade completed. Restarting ..."}
91111

92112
err := restartServices(ctx)
@@ -158,6 +178,31 @@ func runUpgradeCommand(ctx context.Context, names []string) iter.Seq2[string, er
158178

159179
}
160180

181+
func pullDockerImages(ctx context.Context) iter.Seq2[string, error] {
182+
return func(yield func(string, error) bool) {
183+
cmd, err := paths.NewProcess(nil, "arduino-app-cli", "system", "init")
184+
if err != nil {
185+
_ = yield("", err)
186+
return
187+
}
188+
stdout := orchestrator.NewCallbackWriter(func(line string) {
189+
if !yield(line, nil) {
190+
err := cmd.Kill()
191+
if err != nil {
192+
slog.Error("Failed to kill 'arduino-app-cli system init' command", slog.String("error", err.Error()))
193+
}
194+
return
195+
}
196+
})
197+
cmd.RedirectStderrTo(stdout)
198+
cmd.RedirectStdoutTo(stdout)
199+
err = cmd.RunWithinContext(ctx)
200+
if err != nil {
201+
return
202+
}
203+
}
204+
}
205+
161206
// RestartServices restarts services that need to be restarted after an upgrade.
162207
// It uses the `needrestart` command to determine which services need to be restarted.
163208
// It returns an error if the command fails to start or if it fails to wait for the command to finish.

0 commit comments

Comments
 (0)