compose/internal/progress/progress.go
Nicolas De Loof 4f6ed1f893 refactor(provider): move the provider plugin execution to internal/provider
Running a provider plugin (finding its binary, executing it, serving the
JSON messages it sends, applying the variables and endpoints it publishes,
streaming it an image) needs from the engine the Docker API, the event bus,
the Docker CLI that locates the plugin, the preparation of the environment
of a shelled-out command, and the lock that guards the project model every
concurrent provider run mutates.

It now lives in internal/provider behind a Backend interface that
composeService implements in pkg/compose/plugins.go, next to runPlugin, which
stays as a one-line forwarder so none of its callers (up, down, stop, pull)
changes. The relay it deploys goes through internal/relay, whose Backend the
new one extends. The public types and constants of the protocol (JsonMessage,
ProviderMetadata, the *Type message constants...) stay exported from
pkg/compose as aliases of the new package's.

The tests of the plugin protocol move with the code, assertions unchanged;
those of the provider image phase and of the relay link network removal
stay in pkg/compose. The forwarders to the relay that only the plugin code
used are dropped.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-15 09:10:05 +02:00

76 lines
2.1 KiB
Go

/*
Copyright 2020 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package progress builds the progress events Compose reports while it
// operates on resources.
package progress
import (
"github.com/docker/compose/v5/pkg/api"
)
// New builds an event about a resource; reason, if given, is kept as its details.
func New(id string, status api.EventStatus, text string, reason ...string) api.Resource {
r := api.Resource{
ID: id,
Status: status,
Text: text,
}
if len(reason) > 0 {
r.Details = reason[0]
}
return r
}
// Error builds the event of a resource whose operation failed.
func Error(id string, msg string) api.Resource {
return api.Resource{
ID: id,
Status: api.Error,
Text: api.StatusError,
Details: msg,
}
}
// Creating is the event of a resource being created.
func Creating(id string) api.Resource {
return New(id, api.Working, api.StatusCreating)
}
// Created is the event of a resource that was created.
func Created(id string) api.Resource {
return New(id, api.Done, api.StatusCreated)
}
// Removing is the event of a resource being removed.
func Removing(id string) api.Resource {
return New(id, api.Working, api.StatusRemoving)
}
// Removed is the event of a resource that was removed.
func Removed(id string) api.Resource {
return New(id, api.Done, api.StatusRemoved)
}
// Stopping is the event of a resource being stopped.
func Stopping(id string) api.Resource {
return New(id, api.Working, api.StatusStopping)
}
// Stopped is the event of a resource that was stopped.
func Stopped(id string) api.Resource {
return New(id, api.Done, api.StatusStopped)
}