-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/gh 131 bootstrap yorc
- Loading branch information
Showing
120 changed files
with
13,008 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ work | |
**/debug.test | ||
**/debug | ||
build/consul | ||
build/*.zip | ||
/doc/_build/* | ||
/doc/.doctrees | ||
/dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. | ||
// | ||
// 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 bootstrap | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/ystia/yorc/commands" | ||
) | ||
|
||
// Variables with an uknown values are initialized in the root Makefile | ||
var ( | ||
alien4cloudVersion = getAlien4CloudVersionFromTOSCATypes() | ||
ansibleVersion = "unknown" | ||
consulVersion = "unknown" | ||
terraformVersion = "unknown" | ||
yorcVersion = "unknown" | ||
) | ||
|
||
func init() { | ||
|
||
// bootstrapViper is the viper configuration for bootstrap command and its children | ||
bootstrapViper = viper.New() | ||
|
||
// bootstrapCmd is the bootstrap base command | ||
bootstrapCmd = &cobra.Command{ | ||
Use: "bootstrap", | ||
Aliases: []string{"boot", "b"}, | ||
Short: "Installs Yorc and its dependencies", | ||
Long: `Installs Yorc and its dependencies on a given infrastructure`, | ||
SilenceErrors: true, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := bootstrap() | ||
if err != nil { | ||
fmt.Println("Bootstrap error", err) | ||
} | ||
}, | ||
} | ||
|
||
commands.RootCmd.AddCommand(bootstrapCmd) | ||
bootstrapCmd.PersistentFlags().StringVarP(&infrastructureType, | ||
"infrastructure", "i", "", "Define the type of infrastructure where to deploy Yorc: google, openstack, aws, hostspool") | ||
viper.BindPFlag("infrastructure", bootstrapCmd.PersistentFlags().Lookup("infrastructure")) | ||
bootstrapCmd.PersistentFlags().StringVarP(&deploymentType, | ||
"deployment_type", "d", "single_node", "Define deployment type: single_node or HA") | ||
viper.BindPFlag("deployment_type", bootstrapCmd.PersistentFlags().Lookup("deployment_type")) | ||
bootstrapCmd.PersistentFlags().StringVarP(&followType, | ||
"follow", "f", "steps", "Follow bootstrap deployment steps, logs, or none") | ||
viper.BindPFlag("follow", bootstrapCmd.PersistentFlags().Lookup("follow")) | ||
bootstrapCmd.PersistentFlags().StringVarP(&inputsPath, | ||
"values", "v", "", "Path to file containing input values") | ||
bootstrapCmd.PersistentFlags().BoolVarP(&reviewInputs, "review", "r", false, | ||
"Review and update input values before starting the bootstrap") | ||
viper.BindPFlag("review", bootstrapCmd.PersistentFlags().Lookup("review")) | ||
bootstrapCmd.PersistentFlags().StringVarP(&resourcesZipFilePath, | ||
"resources_zip", "z", "", "Path to bootstrap resources zip file") | ||
viper.BindPFlag("resources_zip", bootstrapCmd.PersistentFlags().Lookup("resources_zip")) | ||
bootstrapCmd.PersistentFlags().StringVarP(&workingDirectoryPath, | ||
"working_directory", "w", "work", "Working directory where to place deployment files") | ||
viper.BindPFlag("working_directory", bootstrapCmd.PersistentFlags().Lookup("working_directory")) | ||
|
||
viper.SetEnvPrefix(commands.EnvironmentVariablePrefix) | ||
viper.AutomaticEnv() // read in environment variables that match | ||
viper.BindEnv("infrastructure") | ||
viper.BindEnv("deployment_type") | ||
viper.BindEnv("follow") | ||
viper.BindEnv("review") | ||
viper.BindEnv("resources_zip") | ||
viper.BindEnv("working_directory") | ||
|
||
// Adding extra parameters for bootstrap configuration values | ||
args := os.Args | ||
setBootstrapExtraParams(args, bootstrapCmd) | ||
|
||
cleanCmd := &cobra.Command{ | ||
Use: "cleanup", | ||
Short: "Cleans local setup", | ||
Long: `Cleans local setup, without undeploying the bootstrapped Yorc.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return cleanBootstrapSetup(workingDirectoryPath) | ||
}, | ||
} | ||
bootstrapCmd.AddCommand(cleanCmd) | ||
|
||
// Adding flags related to the infrastructure | ||
commands.InitExtraFlags(args, bootstrapCmd) | ||
|
||
// When review is set through an environment variable | ||
// it has to be converted as a boolean or it is not taken into account | ||
// correctly | ||
reviewInputs = viper.GetBool("review") | ||
|
||
} | ||
|
||
var bootstrapCmd *cobra.Command | ||
var bootstrapViper *viper.Viper | ||
var infrastructureType string | ||
var deploymentType string | ||
var followType string | ||
var reviewInputs bool | ||
var resourcesZipFilePath string | ||
var workingDirectoryPath string | ||
var inputsPath string | ||
|
||
func bootstrap() error { | ||
|
||
infrastructureType = strings.ToLower(infrastructureType) | ||
deploymentType = strings.ToLower(deploymentType) | ||
|
||
// Resources, like the topology zip, will be created in a directory under | ||
//the working directory | ||
resourcesDir := filepath.Join(workingDirectoryPath, "bootstrapResources") | ||
if err := os.RemoveAll(resourcesDir); err != nil { | ||
return err | ||
} | ||
|
||
// First extract resources files | ||
if err := extractResources(resourcesZipFilePath, resourcesDir); err != nil { | ||
return err | ||
} | ||
|
||
// Read config if any | ||
viper.SetConfigName("config.yorc") // name of config file (without extension) | ||
viper.AddConfigPath(workingDirectoryPath) | ||
viper.ReadInConfig() | ||
|
||
configuration := commands.GetConfig() | ||
|
||
// Initializing parameters from environment variables, CLI options | ||
// input file, and asking for user input if needed | ||
if err := initializeInputs(inputsPath, resourcesDir, configuration); err != nil { | ||
return err | ||
} | ||
|
||
// Create a topology from resources provided in the resources directory | ||
topologyDir := filepath.Join(resourcesDir, "topology") | ||
if err := createTopology(topologyDir); err != nil { | ||
return err | ||
} | ||
|
||
// Now that the topology is ready, it needs a local Yorc server able to | ||
// deploy it | ||
if err := setupYorcServer(workingDirectoryPath); err != nil { | ||
return err | ||
} | ||
|
||
// A local Yorc server is running, using it to deploy the topology | ||
deploymentID, errDeploy := deployTopology(workingDirectoryPath, topologyDir) | ||
|
||
if errDeploy != nil { | ||
return errDeploy | ||
} | ||
|
||
if err := followDeployment(deploymentID, followType); err != nil { | ||
return err | ||
} | ||
|
||
// err = tearDownYorcServer(workingDirectoryPath) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. | ||
// | ||
// 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 bootstrap | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/ystia/yorc/commands/deployments" | ||
"github.com/ystia/yorc/helper/ziputil" | ||
) | ||
|
||
// deployTopology deploys a topology provided under deploymentDir. | ||
// Return the the ID of the deployment | ||
func deployTopology(workdDir, deploymentDir string) (string, error) { | ||
|
||
// Download Alien4Cloud whose zip is expected to be provided in the | ||
// deployment | ||
// First downloading it in the work dir if not yet there | ||
// like other extenrla downloadable dependencies | ||
url := inputValues.Alien4cloud.DownloadURL | ||
if _, err := download(url, workdDir); err != nil { | ||
return "", err | ||
} | ||
|
||
// Copying this file now to the deployment dir | ||
_, filename := filepath.Split(url) | ||
srcPath := filepath.Join(workdDir, filename) | ||
dstPath := filepath.Join(deploymentDir, filename) | ||
src, err := os.Open(srcPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
dst, err := os.Create(dstPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer dst.Close() | ||
if _, err := io.Copy(dst, src); err != nil { | ||
return "", err | ||
} | ||
|
||
// Create the deployment archive | ||
fmt.Println("Creating the deployment archive") | ||
csarZip, err := ziputil.ZipPath(deploymentDir) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
t := time.Now() | ||
deploymentID := fmt.Sprintf("bootstrap-%d-%02d-%02d--%02d-%02d-%02d", | ||
t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) | ||
client, err := getYorcClient() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
fmt.Println("Deploying...") | ||
_, err = deployments.SubmitCSAR(csarZip, client, deploymentID) | ||
if err != nil { | ||
return "", err | ||
} | ||
return deploymentID, err | ||
} | ||
|
||
// followDeployment follows deployments steps or deploymnet logs | ||
// until the deployment is finished | ||
func followDeployment(deploymentID, followType string) error { | ||
|
||
client, err := getYorcClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if followType == "steps" { | ||
err = deployments.DisplayInfo(client, deploymentID, false, true, 3*time.Second) | ||
} else if followType == "logs" { | ||
deployments.StreamsLogs(client, deploymentID, true, true, false) | ||
} else { | ||
fmt.Printf("Deployment %s submitted", deploymentID) | ||
} | ||
|
||
return err | ||
} |
Oops, something went wrong.