feat: add build command + build,images config
This commit is contained in:
parent
4c3887857f
commit
b5408fda1a
4 changed files with 60 additions and 1 deletions
31
cli/build.go
Normal file
31
cli/build.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"log"
|
||||
podman "spud/podman"
|
||||
service_definition "spud/service_definition"
|
||||
)
|
||||
|
||||
var build = &cobra.Command{
|
||||
Use: "build",
|
||||
Short: "Build service images.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
pathProvided := args[0]
|
||||
def, err := service_definition.GetServiceDefinitionFromFile(pathProvided)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
imagesToBuild := def.Build.Images
|
||||
|
||||
if len(imagesToBuild) == 0 {
|
||||
log.Print("No images defined - nothing to build!")
|
||||
}
|
||||
|
||||
for _, imageDef := range imagesToBuild {
|
||||
podman.Build(imageDef)
|
||||
}
|
||||
},
|
||||
}
|
|
@ -10,6 +10,8 @@ var allCommands = []*cobra.Command{
|
|||
start,
|
||||
// cli/stop_service.go
|
||||
stop,
|
||||
// cli/build.go
|
||||
build,
|
||||
}
|
||||
|
||||
// Creates the root of the CLI, with all available commands
|
||||
|
|
|
@ -3,8 +3,8 @@ package podman
|
|||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
service_definition "spud/service_definition"
|
||||
)
|
||||
|
||||
|
@ -141,3 +141,19 @@ func CreateContainer(definition service_definition.ContainerDefinition, knownVol
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Builds a container image.
|
||||
func Build(imageDefinition service_definition.BuildImage) error {
|
||||
args := []string{"build", "-f", imageDefinition.Path, "-t", imageDefinition.TagPrefix}
|
||||
|
||||
command := exec.Command("podman", args...)
|
||||
|
||||
command.Stdout = os.Stdout
|
||||
command.Stderr = os.Stderr
|
||||
|
||||
if err := command.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,6 +6,15 @@ import (
|
|||
"github.com/goccy/go-yaml"
|
||||
)
|
||||
|
||||
type BuildImage struct {
|
||||
Path string `yaml:"path"`
|
||||
TagPrefix string `yaml:"tag"`
|
||||
}
|
||||
|
||||
type BuildConfiguration struct {
|
||||
Images []BuildImage
|
||||
}
|
||||
|
||||
type VolumeDefinition struct {
|
||||
Name string `yaml:"name"`
|
||||
}
|
||||
|
@ -33,6 +42,7 @@ type ContainerDefinition struct {
|
|||
|
||||
type ServiceDefinition struct {
|
||||
Name string `yaml:"name"`
|
||||
Build BuildConfiguration `yaml:"build"`
|
||||
Volumes []VolumeDefinition `yaml:"volumes"`
|
||||
Containers []ContainerDefinition `yaml:"containers"`
|
||||
Ports []PortMapping `yaml:"ports"`
|
||||
|
|
Loading…
Reference in a new issue