mirror of
https://github.com/fluxerapp/fluxer.git
synced 2026-12-04 16:13:04 -08:00
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package runtime
|
|
|
|
import (
|
|
"context"
|
|
"maps"
|
|
"path"
|
|
|
|
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/deploy"
|
|
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/engine"
|
|
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/envfile"
|
|
)
|
|
|
|
const (
|
|
ContainerObjects = ContainerData + "/objects"
|
|
ContainerNode = ImageRoot + "/bin/node"
|
|
ContainerMigrate = ImageRoot + "/api/dist/MigrateEntrypoint.js"
|
|
objectsEnvFile = ".rexctl-objects.env"
|
|
)
|
|
|
|
func ContainerEnvWith(r Runtime, with map[string]string) (env, secrets map[string]string, err error) {
|
|
c, ok := r.(*containerRT)
|
|
if !ok {
|
|
return nil, nil, ErrUnsupported
|
|
}
|
|
set, err := deploy.ReleaseSet(c.inst)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
st := c.inst.State
|
|
old := st.Settings
|
|
st.Settings = with
|
|
defer func() { st.Settings = old }()
|
|
return c.n.Environment(set)
|
|
}
|
|
|
|
func ExecAPI(ctx context.Context, r Runtime, with map[string]string, o engine.ExecOptions, command ...string) error {
|
|
c, ok := r.(*containerRT)
|
|
if !ok {
|
|
return ErrUnsupported
|
|
}
|
|
e, err := c.engine(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
config := containerEnvFile
|
|
if with != nil {
|
|
env, secrets, err := ContainerEnvWith(r, with)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
all := maps.Clone(secrets)
|
|
maps.Copy(all, env)
|
|
data, err := envfile.MarshalRaw(all)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := e.WriteSingleFiles(ctx, c.name(), checkDir, ContainerUID, ContainerUID, engine.File{Name: objectsEnvFile, Data: data, Mode: 0o600}); err != nil {
|
|
return err
|
|
}
|
|
config = path.Join(checkDir, objectsEnvFile)
|
|
defer func() {
|
|
_ = e.ExecSingle(context.WithoutCancel(ctx), c.name(), engine.ExecOptions{}, "rm", "-f", config)
|
|
}()
|
|
}
|
|
argv := append([]string{"fluxerd", "exec", "--config", config, "api", "--"}, command...)
|
|
return e.ExecSingle(ctx, c.name(), o, argv...)
|
|
}
|