Skip to content

Commit

Permalink
Merge pull request #3441 from rhatdan/dockerignore
Browse files Browse the repository at this point in the history
Remove some references to Docker
  • Loading branch information
openshift-ci[bot] authored Aug 17, 2021
2 parents 067b10a + 0306d9a commit 197b9a1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
6 changes: 3 additions & 3 deletions cmd/buildah/addcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func applyFlagVars(flags *pflag.FlagSet, opts *addCopyResults) {
if err := flags.MarkHidden("decryption-key"); err != nil {
panic(fmt.Sprintf("error marking decryption-key as hidden: %v", err))
}
flags.StringVar(&opts.ignoreFile, "ignorefile", "", "path to .dockerignore file")
flags.StringVar(&opts.ignoreFile, "ignorefile", "", "path to .containerignore file")
flags.StringVar(&opts.contextdir, "contextdir", "", "context directory path")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "don't output a digest of the newly-added/copied content")
flags.BoolVar(&opts.tlsVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing registries when pulling images. TLS verification cannot be used when talking to an insecure registry.")
Expand Down Expand Up @@ -232,7 +232,7 @@ func addAndCopyCmd(c *cobra.Command, args []string, verb string, iopts addCopyRe
if iopts.contextdir != "" {
var excludes []string
if iopts.ignoreFile != "" {
excludes, err = parseDockerignore(iopts.ignoreFile)
excludes, err = parseIgnore(iopts.ignoreFile)
} else {
excludes, err = imagebuilder.ParseDockerignore(contextdir)
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func addAndCopyCmd(c *cobra.Command, args []string, verb string, iopts addCopyRe
return builder.Save()
}

func parseDockerignore(ignoreFile string) ([]string, error) {
func parseIgnore(ignoreFile string) ([]string, error) {
var excludes []string
ignore, err := ioutil.ReadFile(ignoreFile)
if err != nil {
Expand Down
36 changes: 18 additions & 18 deletions cmd/buildah/bud.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type budOptions struct {

func init() {
budDescription := `
Builds an OCI image using instructions in one or more Dockerfiles.
Builds an OCI image using instructions in one or more Containerfiles.
If no arguments are specified, Buildah will use the current working directory
as the build context and look for a Dockerfile. The build fails if no
Dockerfile is present.`
as the build context and look for a Containerfile. The build fails if no
Containerfile nor Dockerfile is present.`

layerFlagsResults := buildahcli.LayerResults{}
budFlagResults := buildahcli.BudResults{}
Expand All @@ -44,7 +44,7 @@ func init() {
budCommand := &cobra.Command{
Use: "bud",
Aliases: []string{"build-using-dockerfile"},
Short: "Build an image using instructions in a Dockerfile",
Short: "Build an image using instructions in a Containerfile",
Long: budDescription,
RunE: func(cmd *cobra.Command, args []string) error {
br := budOptions{
Expand All @@ -57,9 +57,9 @@ func init() {
return budCmd(cmd, args, br)
},
Example: `buildah bud
buildah bud -f Dockerfile.simple .
buildah bud -f Containerfile.simple .
buildah bud --volume /home/test:/myvol:ro,Z -t imageName .
buildah bud -f Dockerfile.simple -f Dockerfile.notsosimple .`,
buildah bud -f Containerfile.simple -f Containerfile.notsosimple .`,
}
budCommand.SetUsageTemplate(UsageTemplate())

Expand All @@ -85,16 +85,16 @@ func init() {
rootCmd.AddCommand(budCommand)
}

func getDockerfiles(files []string) []string {
var dockerfiles []string
func getContainerfiles(files []string) []string {
var containerfiles []string
for _, f := range files {
if f == "-" {
dockerfiles = append(dockerfiles, "/dev/stdin")
containerfiles = append(containerfiles, "/dev/stdin")
} else {
dockerfiles = append(dockerfiles, f)
containerfiles = append(containerfiles, f)
}
}
return dockerfiles
return containerfiles
}

func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
Expand Down Expand Up @@ -140,7 +140,7 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
}
}

dockerfiles := getDockerfiles(iopts.File)
containerfiles := getContainerfiles(iopts.File)
format, err := getFormat(iopts.Format)
if err != nil {
return err
Expand Down Expand Up @@ -189,14 +189,14 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
return err
}

if len(dockerfiles) == 0 {
if len(containerfiles) == 0 {
// Try to find the Containerfile/Dockerfile within the contextDir
dockerFile, err := discoverContainerfile(contextDir)
containerfile, err := discoverContainerfile(contextDir)
if err != nil {
return err
}
dockerfiles = append(dockerfiles, dockerFile)
contextDir = filepath.Dir(dockerFile)
containerfiles = append(containerfiles, containerfile)
contextDir = filepath.Dir(containerfile)
}

contextDir, err = filepath.EvalSymlinks(contextDir)
Expand Down Expand Up @@ -311,7 +311,7 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {

var excludes []string
if iopts.IgnoreFile != "" {
if excludes, err = parseDockerignore(iopts.IgnoreFile); err != nil {
if excludes, err = parseIgnore(iopts.IgnoreFile); err != nil {
return err
}
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func budCmd(c *cobra.Command, inputArgs []string, iopts budOptions) error {
options.ReportWriter = ioutil.Discard
}

id, ref, err := imagebuildah.BuildDockerfiles(getContext(), store, options, dockerfiles...)
id, ref, err := imagebuildah.BuildDockerfiles(getContext(), store, options, containerfiles...)
if err == nil && options.Manifest != "" {
logrus.Debugf("manifest list id = %q, ref = %q", id, ref.String())
}
Expand Down
22 changes: 11 additions & 11 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ symlink(subdir)"

@test "bud-from-scratch-layers" {
target=scratch-image
run_buildah bud --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/from-scratch/Dockerfile2 -t ${target} ${TESTSDIR}/bud/from-scratch
run_buildah bud --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/from-scratch/Dockerfile2 -t ${target} ${TESTSDIR}/bud/from-scratch
run_buildah bud --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/from-scratch/Containerfile2 -t ${target} ${TESTSDIR}/bud/from-scratch
run_buildah bud --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/from-scratch/Containerfile2 -t ${target} ${TESTSDIR}/bud/from-scratch
run_buildah from --quiet ${target}
cid=$output
run_buildah images
Expand Down Expand Up @@ -688,7 +688,7 @@ function _test_http() {
}

@test "bud-http-Dockerfile" {
_test_http from-scratch Dockerfile
_test_http from-scratch Containerfile
}

@test "bud-http-context-with-Dockerfile" {
Expand Down Expand Up @@ -1097,29 +1097,29 @@ function _test_http() {

@test "bud with --cpu-shares flag, no argument" {
target=bud-flag
run_buildah 125 bud --cpu-shares --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah 125 bud --cpu-shares --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Containerfile ${TESTSDIR}/bud/from-scratch
}

@test "bud with --cpu-shares flag, invalid argument" {
target=bud-flag
run_buildah 125 bud --cpu-shares bogus --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah 125 bud --cpu-shares bogus --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Containerfile ${TESTSDIR}/bud/from-scratch
expect_output --substring "invalid argument \"bogus\" for "
}

@test "bud with --cpu-shares flag, valid argument" {
target=bud-flag
run_buildah bud --cpu-shares 2 --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah bud --cpu-shares 2 --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Containerfile ${TESTSDIR}/bud/from-scratch
run_buildah from ${target}
}

@test "bud with --cpu-shares short flag (-c), no argument" {
target=bud-flag
run_buildah 125 bud -c --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah 125 bud -c --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Containerfile ${TESTSDIR}/bud/from-scratch
}

@test "bud with --cpu-shares short flag (-c), invalid argument" {
target=bud-flag
run_buildah 125 bud -c bogus --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah 125 bud -c bogus --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Containerfile ${TESTSDIR}/bud/from-scratch
expect_output --substring "invalid argument \"bogus\" for "
}

Expand Down Expand Up @@ -2294,7 +2294,7 @@ EOM

@test "bud with custom arch" {
run_buildah bud --signature-policy ${TESTSDIR}/policy.json \
-f ${TESTSDIR}/bud/from-scratch/Dockerfile \
-f ${TESTSDIR}/bud/from-scratch/Containerfile \
-t arch-test \
--arch=arm

Expand All @@ -2307,7 +2307,7 @@ EOM

@test "bud with custom os" {
run_buildah bud --signature-policy ${TESTSDIR}/policy.json \
-f ${TESTSDIR}/bud/from-scratch/Dockerfile \
-f ${TESTSDIR}/bud/from-scratch/Containerfile \
-t os-test \
--os=windows

Expand All @@ -2320,7 +2320,7 @@ EOM

@test "bud with custom platform" {
run_buildah bud --signature-policy ${TESTSDIR}/policy.json \
-f ${TESTSDIR}/bud/from-scratch/Dockerfile \
-f ${TESTSDIR}/bud/from-scratch/Containerfile \
-t platform-test \
--platform=windows/arm

Expand Down
1 change: 1 addition & 0 deletions tests/bud/from-scratch/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM scratch
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/formats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function check_imgtype() {
}

@test "bud-formats" {
run_buildah build-using-dockerfile --signature-policy ${TESTSDIR}/policy.json -t scratch-image-default -f Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah build-using-dockerfile --format docker --signature-policy ${TESTSDIR}/policy.json -t scratch-image-docker -f Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah build-using-dockerfile --format oci --signature-policy ${TESTSDIR}/policy.json -t scratch-image-oci -f Dockerfile ${TESTSDIR}/bud/from-scratch
run_buildah build-using-dockerfile --signature-policy ${TESTSDIR}/policy.json -t scratch-image-default -f Containerfile ${TESTSDIR}/bud/from-scratch
run_buildah build-using-dockerfile --format docker --signature-policy ${TESTSDIR}/policy.json -t scratch-image-docker -f Containerfile ${TESTSDIR}/bud/from-scratch
run_buildah build-using-dockerfile --format oci --signature-policy ${TESTSDIR}/policy.json -t scratch-image-oci -f Containerfile ${TESTSDIR}/bud/from-scratch

check_imgtype scratch-image-default oci
check_imgtype scratch-image-oci oci
Expand Down

0 comments on commit 197b9a1

Please sign in to comment.