예제 #1
0
func NewFactory(
	options FactoryOptions,
	repos FactoryRepos,
	fetcher bhfetcher.Fetcher,
	fs boshsys.FileSystem,
	runner boshsys.CmdRunner,
	downloader bpdload.Downloader,
	uuidGen boshuuid.Generator,
	logger boshlog.Logger,
) (Factory, error) {
	if !options.Enabled {
		return Factory{Importer: NewNoopImporter(logger)}, nil
	}

	var tarballReleaseFactory bhfetcher.TarballReleaseFactory

	{
		blobstoreProvider := bhfetcher.NewBlobstoreProvider(fs, runner, uuidGen, logger)

		blobstore, err := blobstoreProvider.Get(options.BlobstoreType, options.BlobstoreOptions)
		if err != nil {
			return Factory{}, bosherr.WrapError(err, "Building blobstore")
		}

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

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

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

		tarballReleaseFactory = bhfetcher.NewTarballReleaseFactory(
			fs,
			runner,
			blobstore,
			releaseReaderFactory,
			jobReaderFactory,
			repos.ReleasesRepo(),
			repos.ReleaseVersionsRepo(),
			repos.JobsRepo(),
			logger,
		)
	}

	periodicImporter := NewQueueImporter(
		options.Period,
		make(chan struct{}),
		tarballReleaseFactory,
		repos.ReleasesRepo(),
		repos.ImportsRepo(),
		repos.ImportErrsRepo(),
		fetcher,
		logger,
	)

	return Factory{Importer: periodicImporter}, nil
}
예제 #2
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)
	}
}