本文整理汇总了Golang中github.com/hashicorp/atlas-go/archive.CreateArchive函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateArchive函数的具体用法?Golang CreateArchive怎么用?Golang CreateArchive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateArchive函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createAppSlug
// createAppSlug makes an archive of the app with (otto-specific exclusions)
// and yields a path to a tempfile containing that archive
//
// TODO: allow customization of the Exclude patterns
func createAppSlug(path string) (string, error) {
archive, err := archive.CreateArchive(path, &archive.ArchiveOpts{
Exclude: []string{".otto", ".vagrant"},
VCS: true,
})
if err != nil {
return "", err
}
defer archive.Close()
// Archive is just a reader, and we need it in a file. The below seems
// fiddly, could there be a better way?
slug, err := ioutil.TempFile("", "otto-slug-")
if err != nil {
return "", err
}
_, err = io.Copy(slug, archive)
cerr := slug.Close()
if err != nil {
return "", err
}
if cerr != nil {
return "", err
}
return slug.Name(), nil
}
开发者ID:mbrodala,项目名称:otto,代码行数:32,代码来源:build.go
示例2: WriteArchive
// WriteArchive writes the contents of the ScriptPack as a tar gzip to the
// given path.
func (s *ScriptPack) WriteArchive(dst string) error {
// Let's just open the file we're going to write to first to verify
// we can write there since everything else is pointless if we can't.
f, err := os.Create(dst)
if err != nil {
return err
}
defer f.Close()
// Create a temporary directory to store the raw ScriptPack data
td, err := ioutil.TempDir("", "otto")
if err != nil {
return err
}
defer os.RemoveAll(td)
// Write the ScriptPack
if err := s.Write(td); err != nil {
return err
}
// Archive this ScriptPack
a, err := archive.CreateArchive(td, &archive.ArchiveOpts{
VCS: false,
})
if err != nil {
return err
}
defer a.Close()
// Write the archive to final path
_, err = io.Copy(f, a)
return err
}
开发者ID:mbrodala,项目名称:otto,代码行数:36,代码来源:scriptpack.go
示例3: Run
//.........这里部分代码省略.........
if err := ctx.Input(c.InputMode()); err != nil {
c.Ui.Error(fmt.Sprintf(
"Error while asking for variable input:\n\n%s", err))
return 1
}
// Now that we've gone through the input walk, we can be sure we have all
// the variables we're going to get.
// We are going to keep these separate from the atlas variables until
// upload, so we can notify the user which local variables we're sending.
serializedVars, err := tfVars(ctx.Variables())
if err != nil {
c.Ui.Error(fmt.Sprintf(
"An error has occurred while serializing the variables for uploading:\n"+
"%s", err))
return 1
}
// Build the archiving options, which includes everything it can
// by default according to VCS rules but forcing the data directory.
archiveOpts := &archive.ArchiveOpts{
VCS: archiveVCS,
Extra: map[string]string{
DefaultDataDir: c.DataDir(),
},
}
if !moduleUpload {
// If we're not uploading modules, then exclude the modules dir.
archiveOpts.Exclude = append(
archiveOpts.Exclude,
filepath.Join(c.DataDir(), "modules"))
}
archiveR, err := archive.CreateArchive(configPath, archiveOpts)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"An error has occurred while archiving the module for uploading:\n"+
"%s", err))
return 1
}
// List of the vars we're uploading to display to the user.
// We always upload all vars from atlas, but only report them if they are overwritten.
var setVars []string
// variables to upload
var uploadVars []atlas.TFVar
// first add all the variables we want to send which have been serialized
// from the local context.
for _, sv := range serializedVars {
_, inOverwrite := overwriteMap[sv.Key]
_, inAtlas := atlasVars[sv.Key]
// We have a variable that's not in atlas, so always send it.
if !inAtlas {
uploadVars = append(uploadVars, sv)
setVars = append(setVars, sv.Key)
}
// We're overwriting an atlas variable.
// We also want to check that we
// don't send the dummy sentry value back to atlas. This could happen
// if it's specified as an overwrite on the cli, but we didn't set a
// new value.
if inAtlas && inOverwrite && sv.Value != atlasVarSentry {
开发者ID:Originate,项目名称:terraform,代码行数:67,代码来源:push.go
示例4: Run
//.........这里部分代码省略.........
}
// Get the configuration
config := ctx.Module().Config()
if name == "" {
if config.Atlas == nil || config.Atlas.Name == "" {
c.Ui.Error(
"The name of this Terraform configuration in Atlas must be\n" +
"specified within your configuration or the command-line. To\n" +
"set it on the command-line, use the `-name` parameter.")
return 1
}
name = config.Atlas.Name
}
// Initialize the client if it isn't given.
if c.client == nil {
// Make sure to nil out our client so our token isn't sitting around
defer func() { c.client = nil }()
// Initialize it to the default client, we set custom settings later
client := atlas.DefaultClient()
if atlasAddress != "" {
client, err = atlas.NewClient(atlasAddress)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing Atlas client: %s", err))
return 1
}
}
if atlasToken != "" {
client.Token = atlasToken
}
c.client = &atlasPushClient{Client: client}
}
// Get the variables we might already have
vars, err := c.client.Get(name)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error looking up previously pushed configuration: %s", err))
return 1
}
for k, v := range vars {
// Local variables override remote ones
if _, exists := ctx.Variables()[k]; exists {
continue
}
ctx.SetVariable(k, v)
}
// Ask for input
if err := ctx.Input(c.InputMode()); err != nil {
c.Ui.Error(fmt.Sprintf(
"Error while asking for variable input:\n\n%s", err))
return 1
}
// Build the archiving options, which includes everything it can
// by default according to VCS rules but forcing the data directory.
archiveOpts := &archive.ArchiveOpts{
VCS: archiveVCS,
Extra: map[string]string{
DefaultDataDir: c.DataDir(),
},
}
if !moduleUpload {
// If we're not uploading modules, then exclude the modules dir.
archiveOpts.Exclude = append(
archiveOpts.Exclude,
filepath.Join(c.DataDir(), "modules"))
}
archiveR, err := archive.CreateArchive(configPath, archiveOpts)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"An error has occurred while archiving the module for uploading:\n"+
"%s", err))
return 1
}
// Upsert!
opts := &pushUpsertOptions{
Name: name,
Archive: archiveR,
Variables: ctx.Variables(),
}
vsn, err := c.client.Upsert(opts)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"An error occurred while uploading the module:\n\n%s", err))
return 1
}
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
"[reset][bold][green]Configuration %q uploaded! (v%d)",
name, vsn)))
return 0
}
开发者ID:solarnz,项目名称:terraform,代码行数:101,代码来源:push.go
示例5: Run
// Run invokes the CLI with the given arguments. The first argument is always
// the name of the application. This method slices accordingly.
func (cli *CLI) Run(args []string) int {
// Initialize the logger to start (overridden later if debug is given)
cli.initLogger(os.Getenv("ATLAS_LOG"))
var debug, version bool
var archiveOpts archive.ArchiveOpts
var uploadOpts UploadOpts
flags := flag.NewFlagSet(Name, flag.ContinueOnError)
flags.SetOutput(cli.errStream)
flags.Usage = func() {
fmt.Fprintf(cli.errStream, usage, Name)
}
flags.BoolVar(&archiveOpts.VCS, "vcs", false,
"use VCS to detect which files to upload")
flags.StringVar(&uploadOpts.URL, "address", "",
"Atlas server address")
flags.StringVar(&uploadOpts.Token, "token", "",
"Atlas API token")
flags.Var((*FlagSliceVar)(&archiveOpts.Exclude), "exclude",
"files/folders to exclude")
flags.Var((*FlagSliceVar)(&archiveOpts.Include), "include",
"files/folders to include")
flags.Var((*FlagMetadataVar)(&uploadOpts.Metadata), "metadata",
"arbitrary metadata to pass along with the request")
flags.BoolVar(&debug, "debug", false,
"turn on debug output")
flags.BoolVar(&version, "version", false,
"display the version")
// Parse all the flags
if err := flags.Parse(args[1:]); err != nil {
return ExitCodeParseFlagsError
}
// Turn on debug mode if requested
if debug {
levelFilter.SetMinLevel(logutils.LogLevel("DEBUG"))
}
// Version
if version {
fmt.Fprintf(cli.errStream, "%s v%s\n", Name, Version)
return ExitCodeOK
}
// Get the parsed arguments (the ones left over after all the flags have been
// parsed)
parsedArgs := flags.Args()
if len(parsedArgs) != 2 {
fmt.Fprintf(cli.errStream, "cli: must specify two arguments - slug, path\n")
flags.Usage()
return ExitCodeBadArgs
}
// Get the name of the app and the path to archive
slug, path := parsedArgs[0], parsedArgs[1]
uploadOpts.Slug = slug
// Get the archive reader
r, err := archive.CreateArchive(path, &archiveOpts)
if err != nil {
fmt.Fprintf(cli.errStream, "error archiving: %s\n", err)
return ExitCodeArchiveError
}
defer r.Close()
// Put a progress bar around the reader
pr := &ioprogress.Reader{
Reader: r,
Size: r.Size,
DrawFunc: ioprogress.DrawTerminalf(os.Stdout, func(p, t int64) string {
return fmt.Sprintf(
"Uploading %s: %s",
slug,
ioprogress.DrawTextFormatBytes(p, t))
}),
}
// Start the upload
doneCh, uploadErrCh, err := Upload(pr, r.Size, &uploadOpts)
if err != nil {
fmt.Fprintf(cli.errStream, "error starting upload: %s\n", err)
return ExitCodeUploadError
}
select {
case err := <-uploadErrCh:
fmt.Fprintf(cli.errStream, "error uploading: %s\n", err)
return ExitCodeUploadError
case version := <-doneCh:
fmt.Printf("Uploaded %s v%d\n", slug, version)
}
return ExitCodeOK
}
开发者ID:cloudstrack,项目名称:atlas-upload-cli,代码行数:99,代码来源:cli.go
示例6: Run
//.........这里部分代码省略.........
tplPath = filepath.Join(tplPath, path)
}
path, err = filepath.Abs(tplPath)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error determining path to archive: %s", err))
return 1
}
}
// Find the Atlas post-processors, if possible
var atlasPPs []packer.RawPostProcessorConfig
for _, list := range tpl.PostProcessors {
for _, pp := range list {
if pp.Type == "atlas" {
atlasPPs = append(atlasPPs, pp)
}
}
}
// Build the upload options
var uploadOpts uploadOpts
uploadOpts.Slug = tpl.Push.Name
uploadOpts.Builds = make(map[string]*uploadBuildInfo)
for _, b := range tpl.Builders {
info := &uploadBuildInfo{Type: b.Type}
// Determine if we're artifacting this build
for _, pp := range atlasPPs {
if !pp.Skip(b.Name) {
info.Artifact = true
break
}
}
uploadOpts.Builds[b.Name] = info
}
// Warn about builds not having post-processors.
var badBuilds []string
for name, b := range uploadOpts.Builds {
if b.Artifact {
continue
}
badBuilds = append(badBuilds, name)
}
if len(badBuilds) > 0 {
c.Ui.Error(fmt.Sprintf(
"Warning! One or more of the builds in this template does not\n"+
"have an Atlas post-processor. Artifacts from this template will\n"+
"not appear in the Atlas artifact registry.\n\n"+
"This is just a warning. Atlas will still build your template\n"+
"and assume other post-processors are sending the artifacts where\n"+
"they need to go.\n\n"+
"Builds: %s\n\n", strings.Join(badBuilds, ", ")))
}
// Create the build config if it doesn't currently exist.
if err := c.create(uploadOpts.Slug, create); err != nil {
c.Ui.Error(err.Error())
return 1
}
// Start the archiving process
r, err := archive.CreateArchive(path, &opts)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error archiving: %s", err))
return 1
}
defer r.Close()
// Start the upload process
doneCh, uploadErrCh, err := c.upload(r, &uploadOpts)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error starting upload: %s", err))
return 1
}
// Make a ctrl-C channel
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
defer signal.Stop(sigCh)
err = nil
select {
case err = <-uploadErrCh:
err = fmt.Errorf("Error uploading: %s", err)
case <-sigCh:
err = fmt.Errorf("Push cancelled from Ctrl-C")
case <-doneCh:
}
if err != nil {
c.Ui.Error(err.Error())
return 1
}
c.Ui.Output(fmt.Sprintf("Push successful to '%s'", tpl.Push.Name))
return 0
}
开发者ID:Jimdo,项目名称:packer,代码行数:101,代码来源:push.go
示例7: Run
//.........这里部分代码省略.........
if err != nil {
c.Ui.Error(fmt.Sprintf("Error determining path to archive: %s", err))
return 1
}
}
// Find the Atlas post-processors, if possible
var atlasPPs []*template.PostProcessor
for _, list := range tpl.PostProcessors {
for _, pp := range list {
if pp.Type == "atlas" {
atlasPPs = append(atlasPPs, pp)
}
}
}
// Build the upload options
var uploadOpts uploadOpts
uploadOpts.Slug = name
uploadOpts.Builds = make(map[string]*uploadBuildInfo)
for _, b := range tpl.Builders {
info := &uploadBuildInfo{Type: b.Type}
// Determine if we're artifacting this build
for _, pp := range atlasPPs {
if !pp.Skip(b.Name) {
info.Artifact = true
break
}
}
uploadOpts.Builds[b.Name] = info
}
// Add the upload metadata
metadata := make(map[string]interface{})
if message != "" {
metadata["message"] = message
}
metadata["template"] = tpl.RawContents
metadata["template_name"] = filepath.Base(args[0])
uploadOpts.Metadata = metadata
// Warn about builds not having post-processors.
var badBuilds []string
for name, b := range uploadOpts.Builds {
if b.Artifact {
continue
}
badBuilds = append(badBuilds, name)
}
if len(badBuilds) > 0 {
c.Ui.Error(fmt.Sprintf(
"Warning! One or more of the builds in this template does not\n"+
"have an Atlas post-processor. Artifacts from this template will\n"+
"not appear in the Atlas artifact registry.\n\n"+
"This is just a warning. Atlas will still build your template\n"+
"and assume other post-processors are sending the artifacts where\n"+
"they need to go.\n\n"+
"Builds: %s\n\n", strings.Join(badBuilds, ", ")))
}
// Start the archiving process
r, err := archive.CreateArchive(path, &opts)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error archiving: %s", err))
return 1
}
defer r.Close()
// Start the upload process
doneCh, uploadErrCh, err := c.upload(r, &uploadOpts)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error starting upload: %s", err))
return 1
}
// Make a ctrl-C channel
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
defer signal.Stop(sigCh)
err = nil
select {
case err = <-uploadErrCh:
err = fmt.Errorf("Error uploading: %s", err)
case <-sigCh:
err = fmt.Errorf("Push cancelled from Ctrl-C")
case <-doneCh:
}
if err != nil {
c.Ui.Error(err.Error())
return 1
}
c.Ui.Say(fmt.Sprintf("Push successful to '%s'", name))
return 0
}
开发者ID:boumenot,项目名称:packer,代码行数:101,代码来源:push.go
示例8: PostProcess
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
if _, err := p.client.Artifact(p.config.user, p.config.name); err != nil {
if err != atlas.ErrNotFound {
return nil, false, fmt.Errorf(
"Error finding artifact: %s", err)
}
// Artifact doesn't exist, create it
ui.Message(fmt.Sprintf("Creating artifact: %s", p.config.Artifact))
_, err = p.client.CreateArtifact(p.config.user, p.config.name)
if err != nil {
return nil, false, fmt.Errorf(
"Error creating artifact: %s", err)
}
}
opts := &atlas.UploadArtifactOpts{
User: p.config.user,
Name: p.config.name,
Type: p.config.Type,
ID: artifact.Id(),
Metadata: p.metadata(artifact),
BuildId: p.config.buildId,
}
if fs := artifact.Files(); len(fs) > 0 {
var archiveOpts archive.ArchiveOpts
// We have files. We want to compress/upload them. If we have just
// one file, then we use it as-is. Otherwise, we compress all of
// them into a single file.
var path string
if len(fs) == 1 {
path = fs[0]
} else {
path = longestCommonPrefix(fs)
if path == "" {
return nil, false, fmt.Errorf(
"No common prefix for achiving files: %v", fs)
}
// Modify the archive options to only include the files
// that are in our file list.
include := make([]string, 0, len(fs))
for i, f := range fs {
include[i] = strings.Replace(f, path, "", 1)
}
archiveOpts.Include = include
}
r, err := archive.CreateArchive(path, &archiveOpts)
if err != nil {
return nil, false, fmt.Errorf(
"Error archiving artifact: %s", err)
}
defer r.Close()
opts.File = r
opts.FileSize = r.Size
}
ui.Message("Uploading artifact version...")
var av *atlas.ArtifactVersion
doneCh := make(chan struct{})
errCh := make(chan error, 1)
go func() {
var err error
av, err = p.client.UploadArtifact(opts)
if err != nil {
errCh <- err
return
}
close(doneCh)
}()
select {
case err := <-errCh:
return nil, false, fmt.Errorf("Error uploading: %s", err)
case <-doneCh:
}
return &Artifact{
Name: p.config.Artifact,
Type: p.config.Type,
Version: av.Version,
}, true, nil
}
开发者ID:Jimdo,项目名称:packer,代码行数:87,代码来源:post-processor.go
注:本文中的github.com/hashicorp/atlas-go/archive.CreateArchive函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论