Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Release (#16)
Browse files Browse the repository at this point in the history
* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Revendor (#6)

* remove old vendor dependencies

* re-vendor dependencies

* Revendor (#7)

* remove old vendor dependencies

* re-vendor dependencies

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Revendor (#8)

* remove old vendor dependencies

* re-vendor dependencies

* Project import generated by Copybara.

PiperOrigin-RevId: 159017565

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Revendor (#15)

* remove old vendor dependencies

* re-vendor dependencies

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017

* Project import generated by Copybara.

PiperOrigin-RevId: 162346017
  • Loading branch information
Philmod authored Jul 21, 2017
1 parent f687ee5 commit 91f5648
Show file tree
Hide file tree
Showing 1,054 changed files with 253,651 additions and 442 deletions.
2 changes: 1 addition & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ steps:
find . -type d -maxdepth 1 | grep -Ev "vendor|.git|gopath" | xargs /builder/bin/go.bash test
# Binary creation.
- name: 'gcr.io/cloud-builders/go:wheezy'
args: ['install', 'github.com/GoogleCloudPlatform/container-builder-local']
args: ['build', '-o', 'container-builder-local', 'github.com/GoogleCloudPlatform/container-builder-local']

2 changes: 1 addition & 1 deletion cloudbuild_tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ steps:
find . -type d -maxdepth 1 | grep -Ev "vendor|.git|gopath" | xargs /builder/bin/go.bash test
# Set TAG_NAME as version.
- name: 'ubuntu'
args: ['sed', '-i', 's/const version = "HEAD"/const version = "$TAG_NAME"/g', 'version.go']
args: ['sed', '-i', 's/HEAD/$TAG_NAME/g', 'version.go']
# Create binaries.
- name: 'gcr.io/cloud-builders/go:wheezy'
entrypoint: 'bash'
Expand Down
23 changes: 20 additions & 3 deletions localbuilder_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -78,7 +79,7 @@ func main() {
} else if len(args) > 1 {
exitUsage("There should be only one positional argument. Pass all the flags before the source.")
}
dir := args[0]
source := args[0]
if *configFile == "" {
exitUsage("Specify a config file")
}
Expand Down Expand Up @@ -140,8 +141,15 @@ func main() {
log.Printf("Error creating docker volume: %v", err)
return
}
if err := vol.Copy(dir); err != nil {
log.Printf("Error copying directory to docker volume: %v", err)
// If the source is a directory, only copy the inner content.
if isDir, err := isDirectory(source); err != nil {
log.Printf("Error getting directory: %v", err)
return
} else if isDir {
source = filepath.Clean(source) + "/."
}
if err := vol.Copy(source); err != nil {
log.Printf("Error copying source to docker volume: %v", err)
return
}
defer vol.Close()
Expand Down Expand Up @@ -243,3 +251,12 @@ func dockerVersions(r runner.Runner) (string, string, error) {

return strings.TrimSpace(serverb.String()), strings.TrimSpace(clientb.String()), nil
}

func isDirectory(path string) (bool, error) {
fileInfo, err := os.Stat(path)
if err != nil {
return false, err
}
mode := fileInfo.Mode()
return mode.IsDir(), nil
}
50 changes: 50 additions & 0 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

cb "google.golang.org/genproto/googleapis/devtools/cloudbuild/v1"
"github.com/GoogleCloudPlatform/container-builder-local/subst"
"github.com/docker/distribution/reference"
)

const (
Expand All @@ -48,6 +49,7 @@ const (
// Name of the permission required to use a key to decrypt data.
// Documented at https://cloud.google.com/kms/docs/reference/permissions-and-roles
cloudkmsDecryptPermission = "cloudkms.cryptoKeyVersions.useToDecrypt"
maxNumTags = 64 // max length of the list of tags.
)

var (
Expand All @@ -61,6 +63,13 @@ var (
"REVISION_ID": struct{}{},
"COMMIT_SHA": struct{}{},
}
validTagRE = regexp.MustCompile(`^(` + reference.TagRegexp.String() + `)$`)
// validImageTagRE ensures only proper characters are used in name and tag.
validImageTagRE = regexp.MustCompile(`^(` + reference.NameRegexp.String() + `(@sha256:` + reference.TagRegexp.String() + `|:` + reference.TagRegexp.String() + `)?)$`)
// validGCRImageRE ensures proper domain and folder level image for gcr.io. More lenient on the actual characters other than folder structure and domain.
validGCRImageRE = regexp.MustCompile(`^([^\.]+\.)?gcr\.io/[^/]+(/[^/]+)+$`)
validQuayImageRE = regexp.MustCompile(`^(.+\.)?quay\.io/.+$`)
validBuildTagRE = regexp.MustCompile(`^(` + reference.TagRegexp.String() + `)$`)
)

// CheckBuild returns no error if build is valid,
Expand Down Expand Up @@ -92,6 +101,10 @@ func CheckBuild(b *cb.Build) error {
}
}

if err := checkBuildTags(b.Tags); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -278,3 +291,40 @@ func CheckBuildSteps(steps []*cb.BuildStep) error {

return nil
}

// checkImageTags validates the image tag flag.
func checkImageTags(imageTags []string) error {
for _, imageTag := range imageTags {
if !validImageTagRE.MatchString(imageTag) {
return fmt.Errorf("invalid image tag %q: must match format %q", imageTag, validImageTagRE)
}
if !validGCRImageRE.MatchString(imageTag) && !validQuayImageRE.MatchString(imageTag) {
return fmt.Errorf("invalid image tag %q: must match format %q", imageTag, validGCRImageRE)
}
}
return nil
}

// checkBuildStepNames validates the build step names.
func checkBuildStepNames(steps []*cb.BuildStep) error {
for _, step := range steps {
name := step.Name
if !validImageTagRE.MatchString(name) {
return fmt.Errorf("invalid build step name %q: must match format %q", name, validImageTagRE)
}
}
return nil
}

// checkBuildTags validates the tags list.
func checkBuildTags(tags []string) error {
if len(tags) > maxNumTags {
return fmt.Errorf("number of tags %d exceeded (max: %d)", len(tags), maxNumTags)
}
for _, t := range tags {
if !validBuildTagRE.MatchString(t) {
return fmt.Errorf("invalid build tag %q: must match format %q", t, validBuildTagRE)
}
}
return nil
}
114 changes: 114 additions & 0 deletions validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,117 @@ func makeTestBuild(buildID string) *cb.Build {
Images: []string{"gcr.io/some/image/tag", "gcr.io/some/image/tag2"},
}
}

func TestCheckImageTags(t *testing.T) {
validTags := []string{
"subdomain.gcr.io/works/folder/folder",
"gcr.io/works/folder:tag",
"gcr.io/works/folder",
"quay.io/blah/blah:blah",
"quay.io/blah",
"sub.quay.io/blah",
"sub.sub.quay.io/blah",
"quay.io/blah:blah",
}
invalidTags := []string{
"",
"gcr.io/z",
"gcr.io/broken/noth:",
"gcr.io/broken:image",
"subdom.gcr.io/project/[email protected]",
"gcr.io/broken:tag",
"gcr.io/:broken",
"gcr.io/projoect/Broken",
"gcr.o/broken/folder:tag",
"baddomaingcr.io/doesntwork",
"sub.sub.gcr.io/baddomain/blah",
}
for _, tag := range validTags {
tags := []string{tag}
if err := checkImageTags(tags); err != nil {
t.Errorf("checkImageTags(%v) got unexpected error: %v", tags, err)

}
}
for _, tag := range invalidTags {
tags := []string{tag}
if err := checkImageTags(tags); err == nil {
t.Errorf("checkImageTags(%v) did not return error", tags)
}
}
}

func TestCheckBuildStepName(t *testing.T) {
validNames := []string{
"gcr.o/works/folder:tag",
"gcr.io/z",
"subdomain.gcr.io/works/folder/folder",
"gcr.io/works:tag",
"gcr.io/works/folder:tag",
"ubuntu",
"ubuntu:latest",
"gcr.io/cloud-builders/docker@sha256:blah",
}
invalidNames := []string{
"",
"gcr.io/cloud-builders/docker@sha256:",
"gcr.io/cloud-builders/docker@sha56:blah",
"ubnutu::latest",
"gcr.io/:broken",
"gcr.io/project/Broken",
}

for _, name := range validNames {
step := &cb.BuildStep{Name: name}
steps := []*cb.BuildStep{step}
if err := checkBuildStepNames(steps); err != nil {
t.Errorf("checkBuildStepNames(%v) got unexpected error: %v", steps, err)
}
}
for _, name := range invalidNames {
step := &cb.BuildStep{Name: name}
steps := []*cb.BuildStep{step}
if err := checkBuildStepNames(steps); err == nil {
t.Errorf("checkBuildStepNames(%v) did not return error", steps)
}
}
}

func TestCheckBuildTags(t *testing.T) {
var hugeTagList []string
for i := 0; i < maxNumTags+1; i++ {
hugeTagList = append(hugeTagList, randSeq(1))
}

for _, c := range []struct {
tags []string
wantErr bool
}{{
tags: []string{},
wantErr: false,
}, {
tags: []string{"ABCabc-._"},
wantErr: false,
}, {
tags: []string{"_"},
wantErr: false,
}, {
tags: []string{""},
wantErr: true,
}, {
tags: []string{"%"},
wantErr: true,
}, {
tags: []string{randSeq(128 + 1)}, // 128 is the max tag length
wantErr: true,
}, {
tags: hugeTagList,
wantErr: true,
}} {
if err := checkBuildTags(c.tags); err == nil && c.wantErr {
t.Errorf("checkBuildTags(%v) did not return error", c.tags)
} else if err != nil && !c.wantErr {
t.Errorf("checkBuildTags(%v) got unexpected error: %v", c.tags, err)
}
}
}
37 changes: 37 additions & 0 deletions vendor/github.com/docker/distribution/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/github.com/docker/distribution/.mailmap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 91f5648

Please sign in to comment.