github.com/apptainer/singularity@v3.1.1+incompatible/cmd/internal/cli/build_linux.go (about)

     1  // Copyright (c) 2019, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package cli
     7  
     8  import (
     9  	"context"
    10  	"os"
    11  
    12  	"github.com/spf13/cobra"
    13  	"github.com/sylabs/singularity/internal/pkg/build"
    14  	"github.com/sylabs/singularity/internal/pkg/build/remotebuilder"
    15  	"github.com/sylabs/singularity/internal/pkg/sylog"
    16  	"github.com/sylabs/singularity/pkg/build/types"
    17  )
    18  
    19  func run(cmd *cobra.Command, args []string) {
    20  	buildFormat := "sif"
    21  	if sandbox {
    22  		buildFormat = "sandbox"
    23  	}
    24  
    25  	dest := args[0]
    26  	spec := args[1]
    27  
    28  	// check if target collides with existing file
    29  	if ok := checkBuildTarget(dest, update); !ok {
    30  		os.Exit(1)
    31  	}
    32  
    33  	if remote {
    34  		// Submiting a remote build requires a valid authToken
    35  		if authToken == "" {
    36  			sylog.Fatalf("Unable to submit build job: %v", authWarning)
    37  		}
    38  
    39  		def, err := definitionFromSpec(spec)
    40  		if err != nil {
    41  			sylog.Fatalf("Unable to build from %s: %v", spec, err)
    42  		}
    43  
    44  		b, err := remotebuilder.New(dest, libraryURL, def, detached, force, builderURL, authToken)
    45  		if err != nil {
    46  			sylog.Fatalf("Failed to create builder: %v", err)
    47  		}
    48  		err = b.Build(context.TODO())
    49  		if err != nil {
    50  			sylog.Fatalf("While performing build: %v", err)
    51  		}
    52  	} else {
    53  
    54  		err := checkSections()
    55  		if err != nil {
    56  			sylog.Fatalf(err.Error())
    57  		}
    58  
    59  		authConf, err := makeDockerCredentials(cmd)
    60  		if err != nil {
    61  			sylog.Fatalf("While creating Docker credentials: %v", err)
    62  		}
    63  
    64  		b, err := build.NewBuild(
    65  			spec,
    66  			dest,
    67  			buildFormat,
    68  			libraryURL,
    69  			authToken,
    70  			types.Options{
    71  				TmpDir:           tmpDir,
    72  				Update:           update,
    73  				Force:            force,
    74  				Sections:         sections,
    75  				NoTest:           noTest,
    76  				NoHTTPS:          noHTTPS,
    77  				NoCleanUp:        noCleanUp,
    78  				DockerAuthConfig: authConf,
    79  			})
    80  		if err != nil {
    81  			sylog.Fatalf("Unable to create build: %v", err)
    82  		}
    83  
    84  		if err = b.Full(); err != nil {
    85  			sylog.Fatalf("While performing build: %v", err)
    86  		}
    87  	}
    88  }