Ejemplo n.º 1
0
func main() {
	logger, fs, runner, uuidGen := basicDeps()

	defer logger.HandlePanic("Main")

	config := mustLoadConfig(fs, logger)

	eventLogFactory := bpeventlog.NewFactory(config.EventLog, logger)

	eventLog := eventLogFactory.NewLog()

	mustSetTmpDir(config, fs, eventLog)

	mustCreateReposDir(config, fs, eventLog)

	localBlobstore := boshblob.NewLocalBlobstore(
		fs,
		uuidGen,
		config.Blobstore.Options,
	)

	blobstore := boshblob.NewSHA1VerifiableBlobstore(localBlobstore)

	downloader := bpdload.NewDefaultMuxDownloader(fs, runner, blobstore, logger)

	extractor := bptar.NewCmdExtractor(runner, fs, logger)

	compressor := bptar.NewCmdCompressor(runner, fs, logger)

	renderedArchivesCompiler := bptplcomp.NewRenderedArchivesCompiler(
		fs,
		runner,
		compressor,
		logger,
	)

	jobReaderFactory := bpreljob.NewReaderFactory(
		downloader,
		extractor,
		fs,
		logger,
	)

	reposFactory := NewReposFactory(config.ReposDir, fs, downloader, blobstore, logger)

	blobstoreProvisioner := bpprov.NewBlobstoreProvisioner(
		fs,
		config.Blobstore,
		logger,
	)

	err := blobstoreProvisioner.Provision()
	if err != nil {
		eventLog.WriteErr(bosherr.WrapError(err, "Provisioning blobstore"))
		os.Exit(1)
	}

	templatesCompiler := bptplcomp.NewConcreteTemplatesCompiler(
		renderedArchivesCompiler,
		jobReaderFactory,
		reposFactory.NewJobsRepo(),
		reposFactory.NewTemplateToJobRepo(),
		reposFactory.NewRuntimePackagesRepo(),
		reposFactory.NewTemplatesRepo(),
		blobstore,
		logger,
	)

	packagesCompilerFactory := bppkgscomp.NewConcretePackagesCompilerFactory(
		reposFactory.NewPackagesRepo(),
		reposFactory.NewCompiledPackagesRepo(),
		blobstore,
		eventLog,
		logger,
	)

	updaterFactory := bpinstupd.NewFactory(
		templatesCompiler,
		packagesCompilerFactory,
		eventLog,
		logger,
	)

	releaseReaderFactory := bprel.NewReaderFactory(
		downloader,
		extractor,
		fs,
		logger,
	)

	deploymentReaderFactory := bpdep.NewReaderFactory(fs, logger)

	vagrantVMProvisionerFactory := bpvagrantvm.NewVMProvisionerFactory(
		fs,
		runner,
		config.AssetsDir,
		config.Blobstore.AsMap(),
		config.VMProvisioner,
		eventLog,
		logger,
	)

	vagrantVMProvisioner := vagrantVMProvisionerFactory.NewVMProvisioner()

	releaseCompiler := bpprov.NewReleaseCompiler(
		releaseReaderFactory,
		packagesCompilerFactory,
		templatesCompiler,
		vagrantVMProvisioner,
		eventLog,
		logger,
	)

	instanceProvisioner := bpinstance.NewProvisioner(
		updaterFactory,
		logger,
	)

	singleVMProvisionerFactory := bpprov.NewSingleVMProvisionerFactory(
		deploymentReaderFactory,
		config.DeploymentProvisioner,
		vagrantVMProvisioner,
		releaseCompiler,
		instanceProvisioner,
		eventLog,
		logger,
	)

	deploymentProvisioner := singleVMProvisionerFactory.NewSingleVMProvisioner()

	err = deploymentProvisioner.Provision()
	if err != nil {
		eventLog.WriteErr(bosherr.WrapError(err, "Provisioning deployment"))
		os.Exit(1)
	}
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	logger, fs, runner, uuidGen := basicDeps(*debugOpt)
	defer logger.HandlePanic("Main")

	config, err := NewConfigFromPath(*configPathOpt, fs)
	ensureNoErr(logger, "Loading config", err)

	repos, err := NewRepos(config.Repos, fs, logger)
	ensureNoErr(logger, "Failed building repos", err)

	controllerFactory, err := bhctrls.NewFactory(config.APIKey, repos, runner, logger)
	ensureNoErr(logger, "Failed building controller factory", err)

	downloader := bpdload.NewDefaultMuxDownloader(fs, runner, nil, logger)
	fetcher := bhfetcher.NewConcreteFetcher(fs, downloader, logger)

	{
		watcherFactory, err := bhwatcher.NewFactory(
			config.Watcher, repos, fetcher, logger)
		ensureNoErr(logger, "Failed building watcher factory", err)

		go watcherFactory.Watcher.Watch()
	}

	{
		importerFactory, err := bhimporter.NewFactory(
			config.Importer, repos, fetcher, fs, runner, downloader, uuidGen, logger)
		ensureNoErr(logger, "Failed building importer factory", err)

		go importerFactory.Importer.Import()
	}

	{
		noteImporterFactory, err := bhnoteimporter.NewFactory(config.NoteImporter, repos, logger)
		ensureNoErr(logger, "Failed building note importer factory", err)

		go noteImporterFactory.Importer.Import()
	}

	{
		stemcellImporterFactory := bhstemsimp.NewFactory(config.StemcellImporter, repos, logger)
		ensureNoErr(logger, "Failed building stemcell importer factory", err)

		go stemcellImporterFactory.Importer.Import()
	}

	{
		boshInitBinImporterFactory := bhbibimp.NewFactory(config.BoshInitBinImporter, repos, logger)
		ensureNoErr(logger, "Failed building bosh-init bin importer factory", err)

		go boshInitBinImporterFactory.Importer.Import()
	}

	if config.ActAsWorker {
		select {}
	} else {
		runControllers(controllerFactory, config.Analytics, logger)
	}
}