@@ -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