File: source.go

package info (click to toggle)
golang-github-containers-buildah 1.41.4%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,152 kB
  • sloc: sh: 2,569; makefile: 241; perl: 187; asm: 16; awk: 12; ansic: 1
file content (128 lines) | stat: -rw-r--r-- 5,786 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main

import (
	"context"

	"github.com/containers/buildah/internal/source"
	"github.com/spf13/cobra"
)

var (
	// buildah source
	sourceDescription = `  Create, push, pull and manage source images and associated source artifacts.  A source image contains all source artifacts an ordinary OCI image has been built with.  Those artifacts can be any kind of source artifact, such as source RPMs, an entire source tree or text files.

  Note that the buildah-source command and all its subcommands are experimental and may be subject to future changes.
`
	sourceCommand = &cobra.Command{
		Use:   "source",
		Short: "Manage source containers",
		Long:  sourceDescription,
		RunE: func(_ *cobra.Command, _ []string) error {
			return nil
		},
	}

	// buildah source create
	sourceCreateDescription = `  Create and initialize a source image.  A source image is an OCI artifact; an OCI image with a custom config media type.

  Note that the buildah-source command and all its subcommands are experimental and may be subject to future changes.
`
	sourceCreateOptions = source.CreateOptions{}
	sourceCreateCommand = &cobra.Command{
		Args:    cobra.ExactArgs(1),
		Use:     "create",
		Short:   "Create a source image",
		Long:    sourceCreateDescription,
		Example: "buildah source create /tmp/fedora:latest-source",
		RunE: func(_ *cobra.Command, args []string) error {
			return source.Create(context.Background(), args[0], sourceCreateOptions)
		},
	}

	// buildah source add
	sourceAddOptions     = source.AddOptions{}
	sourceAddDescription = `  Add add a source artifact to a source image.  The artifact will be added as a gzip-compressed tar ball.  Add attempts to auto-tar and auto-compress only if necessary.

  Note that the buildah-source command and all its subcommands are experimental and may be subject to future changes.
`
	sourceAddCommand = &cobra.Command{
		Args:    cobra.ExactArgs(2),
		Use:     "add",
		Short:   "Add a source artifact to a source image",
		Long:    sourceAddDescription,
		Example: "buildah source add /tmp/fedora sources.tar.gz",
		RunE: func(_ *cobra.Command, args []string) error {
			return source.Add(context.Background(), args[0], args[1], sourceAddOptions)
		},
	}

	// buildah source pull
	sourcePullOptions     = source.PullOptions{}
	sourcePullDescription = `  Pull a source image from a registry to a specified path.  The pull operation will fail if the image does not comply with a source-image OCI artifact.

  Note that the buildah-source command and all its subcommands are experimental and may be subject to future changes.
`
	sourcePullCommand = &cobra.Command{
		Args:    cobra.ExactArgs(2),
		Use:     "pull",
		Short:   "Pull a source image from a registry to a specified path",
		Long:    sourcePullDescription,
		Example: "buildah source pull quay.io/sourceimage/example:latest /tmp/sourceimage:latest",
		RunE: func(_ *cobra.Command, args []string) error {
			return source.Pull(context.Background(), args[0], args[1], sourcePullOptions)
		},
	}

	// buildah source push
	sourcePushOptions     = source.PushOptions{}
	sourcePushDescription = `  Push a source image from a specified path to a registry.

  Note that the buildah-source command and all its subcommands are experimental and may be subject to future changes.
`
	sourcePushCommand = &cobra.Command{
		Args:    cobra.ExactArgs(2),
		Use:     "push",
		Short:   "Push a source image from a specified path to a registry",
		Long:    sourcePushDescription,
		Example: "buildah source push /tmp/sourceimage:latest quay.io/sourceimage/example:latest",
		RunE: func(_ *cobra.Command, args []string) error {
			return source.Push(context.Background(), args[0], args[1], sourcePushOptions)
		},
	}
)

func init() {
	// buildah source
	sourceCommand.SetUsageTemplate(UsageTemplate())
	rootCmd.AddCommand(sourceCommand)

	// buildah source create
	sourceCreateCommand.SetUsageTemplate(UsageTemplate())
	sourceCommand.AddCommand(sourceCreateCommand)
	sourceCreateFlags := sourceCreateCommand.Flags()
	sourceCreateFlags.StringVar(&sourceCreateOptions.Author, "author", "", "set the author")
	sourceCreateFlags.BoolVar(&sourceCreateOptions.TimeStamp, "time-stamp", true, "set the \"created\" time stamp")

	// buildah source add
	sourceAddCommand.SetUsageTemplate(UsageTemplate())
	sourceCommand.AddCommand(sourceAddCommand)
	sourceAddFlags := sourceAddCommand.Flags()
	sourceAddFlags.StringArrayVar(&sourceAddOptions.Annotations, "annotation", []string{}, "add an annotation (format: key=value)")

	// buildah source pull
	sourcePullCommand.SetUsageTemplate(UsageTemplate())
	sourceCommand.AddCommand(sourcePullCommand)
	sourcePullFlags := sourcePullCommand.Flags()
	sourcePullFlags.StringVar(&sourcePullOptions.Credentials, "creds", "", "use `[username[:password]]` for accessing the registry")
	sourcePullFlags.BoolVar(&sourcePullOptions.TLSVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry")
	sourcePullFlags.BoolVarP(&sourcePullOptions.Quiet, "quiet", "q", false, "don't output pull progress information")

	// buildah source push
	sourcePushCommand.SetUsageTemplate(UsageTemplate())
	sourceCommand.AddCommand(sourcePushCommand)
	sourcePushFlags := sourcePushCommand.Flags()
	sourcePushFlags.StringVar(&sourcePushOptions.Credentials, "creds", "", "use `[username[:password]]` for accessing the registry")
	sourcePushFlags.StringVar(&sourcePushOptions.DigestFile, "digestfile", "", "after copying the artifact, write the digest of the resulting image to the file")
	sourcePushFlags.BoolVar(&sourcePushOptions.TLSVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry")
	sourcePushFlags.BoolVarP(&sourcePushOptions.Quiet, "quiet", "q", false, "don't output push progress information")
}