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

Commit

Permalink
Merge branch 'release-1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
romank87 committed Feb 12, 2016
2 parents 1c71c9a + b45444e commit ec7c40b
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dev

*.sublime-workspace
rocker
*.swp
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## [1.1.2](https://github.com/grammarly/rocker/tree/1.1.2)

[Full Changelog](https://github.com/grammarly/rocker/compare/1.1.1...1.1.2)

**Merged pull requests:**

- New S3 naming schema works in parallel to the old one [\#76](https://github.com/grammarly/rocker/pull/76) ([romank87](https://github.com/romank87))
- Adopt S3 naming schema for Docker v1.10 [\#75](https://github.com/grammarly/rocker/pull/75) ([romank87](https://github.com/romank87))

## [1.1.1](https://github.com/grammarly/rocker/tree/1.1.1)

[Full Changelog](https://github.com/grammarly/rocker/compare/1.1.0...1.1.1)
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PKGS := $(foreach pkg, $(sort $(dir $(SRCS))), $(pkg))
TESTARGS ?=

default:
go build
GO15VENDOREXPERIMENT=1 go build -v

install:
cp rocker /usr/local/bin/rocker
Expand Down Expand Up @@ -62,9 +62,9 @@ gocyclo:
gocyclo -over 25 ./src

test: testdeps fmtcheck vet lint
go test ./src/... $(TESTARGS)
GO15VENDOREXPERIMENT=1 go test ./src/... $(TESTARGS)

integ:
go test ./src/... -tags="integration" -run TestInteg_
GO15VENDOREXPERIMENT=1 go test ./src/... -tags="integration" -run TestInteg_

.PHONY: clean test fmtcheck lint vet gocyclo default
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,28 +393,28 @@ It is possible to store images directly on S3, so there is no complex logic of l
```bash
FROM alpine:3.2
PUSH s3:bucket-name/image-name:1.2.3
PUSH s3.amazonaws.com/bucket-name/image-name:1.2.3
```

Rocker will push the image directly to S3, without event using Docker daemon for that.

You can pull images directly from S3 as well:

```bash
FROM s3:my-images/alpine:3.2
FROM s3.amazonaws.com/my-images/alpine:3.2
```

Since you can't just easily `docker pull` the image that is stored on S3, you can be creative and do something like this, because why the hell not:

```bash
echo "FROM s3:my-images/alpine:3.2" | rocker build -f -
echo "FROM s3.amazonaws.com/my-images/alpine:3.2" | rocker build -f -
```

Or just use `rocker pull` command :)

```bash
rocker pull s3:my-images/alpine:3.2
rocker pull s3.amazonaws.com/my-images/alpine:3.2
```

There should be AWS credentials in place, either exported as environment variables or present in `~/.aws/credentials`. For more information how to set up an environment, see [this doc](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html).
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.1.2
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func main() {
app.Authors = []cli.Author{
{"Yura Bogdanov", "[email protected]"},
{"Stas Levental", "[email protected]"},
{"Roman Khlystik", "[email protected]"},
}

app.Flags = append([]cli.Flag{
Expand Down
10 changes: 8 additions & 2 deletions src/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ func (b *Build) lookupImage(name string) (img *docker.Image, err error) {

// If hub is true, then there is no sense to inspect the local image
if !hub || isSha {
if isOld, warning := imagename.WarnIfOldS3ImageName(name); isOld {
log.Warn(warning)
}
// Try to inspect image as is, without version resolution
if img, err := b.client.InspectImage(imgName.String()); err != nil || img != nil {
return img, err
Expand All @@ -301,7 +304,7 @@ func (b *Build) lookupImage(name string) (img *docker.Image, err error) {
return nil, err
}
// Resolve local candidate
candidate = imgName.ResolveVersion(localImages)
candidate = imgName.ResolveVersion(localImages, true)
}

// In case we want to include external images as well, pulling list of available
Expand All @@ -317,9 +320,12 @@ func (b *Build) lookupImage(name string) (img *docker.Image, err error) {
}

// Since we found the remote image, we want to pull it
if remoteCandidate = imgName.ResolveVersion(remoteImages); remoteCandidate != nil {
if remoteCandidate = imgName.ResolveVersion(remoteImages, false); remoteCandidate != nil {
pull = true
candidate = remoteCandidate

// If we've found needed image on s3 it should be pulled in the same name style as lookuped image
candidate.IsOldS3Name = imgName.IsOldS3Name
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (c *DockerClient) PullImage(name string) error {

// e.g. s3:bucket-name/image-name
if image.Storage == imagename.StorageS3 {
if isOld, warning := imagename.WarnIfOldS3ImageName(name); isOld {
c.log.Warn(warning)
}

return c.s3storage.Pull(name)
}

Expand Down Expand Up @@ -432,6 +436,9 @@ func (c *DockerClient) UploadToContainer(containerID string, stream io.Reader, p
// TagImage adds tag to the image
func (c *DockerClient) TagImage(imageID, imageName string) error {
img := imagename.NewFromString(imageName)
if isOld, warning := imagename.WarnIfOldS3ImageName(imageName); isOld {
c.log.Warn(warning)
}

c.log.Infof("| Tag %.12s -> %s", imageID, img)

Expand Down Expand Up @@ -475,6 +482,9 @@ func (c *DockerClient) pushImageInner(imageName string) (digest string, err erro

// Use direct S3 image pusher instead
if img.Storage == imagename.StorageS3 {
if isOld, warning := imagename.WarnIfOldS3ImageName(imageName); isOld {
c.log.Warn(warning)
}
return c.s3storage.Push(imageName)
}

Expand Down
2 changes: 1 addition & 1 deletion src/build/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ func (c *CommandPush) Execute(b *Build) (State, error) {
filePath := filepath.Join(b.cfg.ArtifactsPath, artifact.GetFileName())

artifacts := imagename.Artifacts{
[]imagename.Artifact{artifact},
RockerArtifacts: []imagename.Artifact{artifact},
}
content, err := yaml.Marshal(artifacts)
if err != nil {
Expand Down
58 changes: 45 additions & 13 deletions src/imagename/imagename.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package imagename

import (
"encoding/json"
"fmt"
"regexp"
"sort"
"strings"
Expand All @@ -44,6 +45,11 @@ const (
StorageS3 = "s3"
)

const (
s3Prefix = "s3.amazonaws.com/"
s3OldPrefix = "s3:"
)

var (
ecrRe = regexp.MustCompile("^\\d+\\.dkr\\.ecr\\.[^\\.]+\\.amazonaws\\.com$")
)
Expand All @@ -55,6 +61,8 @@ type ImageName struct {
Tag string
Storage string
Version *semver.Range

IsOldS3Name bool
}

// NewFromString parses a given string and returns ImageName
Expand All @@ -63,6 +71,19 @@ func NewFromString(image string) *ImageName {
return New(name, tag)
}

// WarnIfOldS3ImageName Check whether old image format is used. Also return warning message if yes
func WarnIfOldS3ImageName(imageName string) (bool, string) {
if !strings.HasPrefix(imageName, s3OldPrefix) {
return false, ""
}

warning := fmt.Sprintf("Your image '%s' is using old name style (s3:<repo>/<image>) for s3 images."+
" This style isn't supported by docker 1.10 and would be removed from rocker in the future as well."+
" Please consider changing to the new schema (s3.amazonaws.com/<repo>/<image>).", imageName)

return true, warning
}

// New parses a given 'image' and 'tag' strings and returns ImageName
func New(image string, tag string) *ImageName {
dockerImage := &ImageName{}
Expand All @@ -74,19 +95,22 @@ func New(image string, tag string) *ImageName {
// default storage driver
dockerImage.Storage = StorageRegistry

// In case storage is specified, e.g. s3://bucket-name/image-name
storages := []string{StorageRegistry, StorageS3}
firstIsHost := false
prefix := ""

for _, storage := range storages {
prefix := storage + ":"
if strings.HasPrefix(image, s3Prefix) {
dockerImage.IsOldS3Name = false
prefix = s3Prefix

if strings.HasPrefix(image, prefix) {
image = strings.TrimPrefix(image, prefix)
dockerImage.Storage = storage
firstIsHost = true
break
}
} else if strings.HasPrefix(image, s3OldPrefix) {
dockerImage.IsOldS3Name = true
prefix = s3OldPrefix
}

if strings.HasPrefix(image, s3Prefix) || strings.HasPrefix(image, s3OldPrefix) {
image = strings.TrimPrefix(image, prefix)
dockerImage.Storage = StorageS3
firstIsHost = true
}

nameParts := strings.SplitN(image, "/", 2)
Expand Down Expand Up @@ -243,8 +267,12 @@ func (img ImageName) NameWithRegistry() string {
if img.Registry != "" {
registryPrefix = img.Registry + "/"
}
if img.Storage != StorageRegistry {
registryPrefix = img.Storage + ":" + registryPrefix
if img.Storage == StorageS3 {
if img.IsOldS3Name {
registryPrefix = s3OldPrefix + registryPrefix
} else {
registryPrefix = s3Prefix + registryPrefix
}
}
return registryPrefix + img.Name
}
Expand Down Expand Up @@ -277,13 +305,17 @@ func (img ImageName) Contains(b *ImageName) bool {
}

// ResolveVersion finds an applicable tag for current image among the list of available tags
func (img *ImageName) ResolveVersion(list []*ImageName) (result *ImageName) {
func (img *ImageName) ResolveVersion(list []*ImageName, strictS3Match bool) (result *ImageName) {
for _, candidate := range list {
// If these are different images (different names/repos)
if !img.IsSameKind(*candidate) {
continue
}

if strictS3Match && img.IsOldS3Name != candidate.IsOldS3Name {
continue
}

// If we have a strict equality
if img.HasTag() && candidate.HasTag() && img.Tag == candidate.Tag {
return candidate
Expand Down
Loading

0 comments on commit ec7c40b

Please sign in to comment.