mirror of
https://github.com/mudler/luet.git
synced 2025-08-12 04:32:11 +00:00
As those checks are not consuming any digest, we just use them to assess if we need to build or not certain packages. The backend will refuse the image if not configured appropriately
83 lines
2.1 KiB
Go
83 lines
2.1 KiB
Go
// Copyright © 2020 Ettore Di Giacinto <mudler@gentoo.org>
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package backend
|
|
|
|
import (
|
|
"os/exec"
|
|
|
|
"github.com/google/go-containerregistry/pkg/crane"
|
|
"github.com/mudler/luet/pkg/api/core/types"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const (
|
|
ImgBackend = "img"
|
|
DockerBackend = "docker"
|
|
)
|
|
|
|
func imageAvailable(image string) bool {
|
|
// We use crane.insecure as we just check if the image is available
|
|
// It's the daemon duty to use it or not based on the host settings
|
|
_, err := crane.Digest(image, crane.Insecure)
|
|
return err == nil
|
|
}
|
|
|
|
type Options struct {
|
|
ImageName string
|
|
SourcePath string
|
|
DockerFileName string
|
|
Destination string
|
|
Context string
|
|
BackendArgs []string
|
|
}
|
|
|
|
func runCommand(ctx types.Context, cmd *exec.Cmd) error {
|
|
output := ""
|
|
buffered := !ctx.GetConfig().General.ShowBuildOutput
|
|
writer := NewBackendWriter(buffered, ctx)
|
|
|
|
cmd.Stdout = writer
|
|
cmd.Stderr = writer
|
|
|
|
if buffered {
|
|
ctx.Spinner()
|
|
defer ctx.SpinnerStop()
|
|
}
|
|
|
|
err := cmd.Start()
|
|
if err != nil {
|
|
return errors.Wrap(err, "Failed starting command")
|
|
}
|
|
|
|
err = cmd.Wait()
|
|
if err != nil {
|
|
output = writer.GetCombinedOutput()
|
|
return errors.Wrapf(err, "Failed running command: %s", output)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func genBuildCommand(opts Options) []string {
|
|
context := opts.Context
|
|
|
|
if context == "" {
|
|
context = "."
|
|
}
|
|
buildarg := append(opts.BackendArgs, "-f", opts.DockerFileName, "-t", opts.ImageName, context)
|
|
return append([]string{"build"}, buildarg...)
|
|
}
|