Skip to content

Commit

Permalink
Build for barlib test image
Browse files Browse the repository at this point in the history
Phew! This took some figuring out. Details in README-images.md.
  • Loading branch information
squaremo committed Mar 31, 2020
1 parent dc65e38 commit fe3bbde
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 48 deletions.
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY=
github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
Expand All @@ -59,13 +60,16 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017 h1:2HQmlpI3yI9deH18Q6xiSOIjXD4sLI55Y/gfpa8/558=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7 h1:Cvj7S8I4Xpx78KAl6TwTmMHuHlZ/0SM60NUneGJQ7IE=
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.6.3 h1:zI2p9+1NQYdnG6sMU26EX4aVGlqbInSQxQXLvzJ4RPQ=
github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
Expand Down Expand Up @@ -96,6 +100,7 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand All @@ -104,6 +109,7 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand Down Expand Up @@ -227,6 +233,7 @@ github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1K
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down Expand Up @@ -310,6 +317,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -336,6 +344,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down Expand Up @@ -378,10 +387,12 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 h1:nfPFGzJkUDX6uBmpN/pSw7MbOAWegH5QDQuoXFHedLg=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
2 changes: 1 addition & 1 deletion tests/test-lib-wo-missing.js.error
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: could not import bar from '<exec>' etc.
error: could not import bar from '<exec>' etc.
10 changes: 10 additions & 0 deletions tests/testfiles/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Makefile for the images used in automated tests

.PHONY: all

all: foolib.tar barlib.tar

foolib.tar: src/foolib/jk/modules/foolib.js
tar -C src/foolib --exclude='*~' -c jk | docker import - foolib:v1
docker save -o foolib.tar foolib:v1

barlib.tar: src/barlib/Dockerfile.base-foo src/barlib/Dockerfile.alpine-foo src/barlib/Dockerfile.alpine-bar
for image in base-foo alpine-foo alpine-bar; do \
docker build -f "src/barlib/Dockerfile.$$image" -t "$$image" ./src/barlib; \
done
go run rebase.go --old "alpine-foo" --new "base-foo" --original "alpine-bar" --out "barlib.tar"
67 changes: 20 additions & 47 deletions tests/testfiles/README-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,55 +32,28 @@ The Makefile uses the above recipe to create `foolib.tar` from
## barlib:v1

barlib is prepared specially so that it contains whiteout files
(including an opaque whiteout).

The layers are like this (from bottom to top):

```
# Adds foo.js and bar.js
ff940e87e638b27658c85f5eea099f2845b22174f4930b0d23dc66f46166a07c
bar.js
foo.js
# Adds baz/foo/index.js and whites out everything else in baz/
b3f509bb9ebb848a43fa4753a1ce8a4edcf47a6a8f00f7ef169db2ceee378fa0
baz/
.wh..wh..opq
foo/
index.js
# Add baz/index.js, which should be visible
41aeafa2014c11a98517a72c5f62bb52565060682b444d773243d8b4b05b4045
baz/
index.js
# Adds bar.js and foo.js again (no reason)
01a81ce7b8b6713893656bf8acf4ed5ad454e5d0da599daa2d1e7acf0bedf68f
bar.js
foo.js
# Adds baz/index.js and whites out everything else in baz/
# (hiding baz/foo/index.js)
4adec11db178e60ff80fdb392ae4c2c7e15dfdb90cf113705c580caa05ff22c4
baz/
.wh..wh..opq
index.js
# Whites out bar.js with .wh.bar.js
67ab3fd25033b0983417d7094762e506c418bf1a834c5f4410e9e68daaa0ea84
.wh.bar.js
# Overlays foo.js with another file (default export 'baz')
1a18b3cf1e651323c4d059150b976eca9759bbfa8af1b39c7abf784abb005e19
foo.js
```

The resulting filesystem should look like this:
(including an opaque whiteout). This needs a bit of arranging:

1. [`Dockerfile.base-foo`](./src/Dockerfile.base-foo) copies `foo.js`
and `bar.js`, and creates the directory `baz/` implicitly by
copying to `baz/baz.js`.
2. [`Dockerfile.alpine-foo`](./src/Dockerfile.alpine-foo) copies
foo.js and baz.js (but _not_ baz/baz.js), and is based on
alpine:3.9 so we have `rm` available;
3. [`Dockerfile.alpine-bar`](./src/Dockerfile.alpine-bar) is based on
`alpine-foo`, so it has `foo.js` and `bar.js`. It removes `bar.js`,
creating a whiteout for that file, and replaces `foo.js`. It _also_
creates a directory `baz/`, which, since it's not present in
`alpine-foo`, makes an opaque whiteout;
4. `alpine-bar` is rebased on `base-foo`, removing the alpine layers
but leaving the opaque whiteout from step 3.

The resulting filesystem looks like this:

```
foo.js # exports 'baz'
# bar is whited-out
foo.js # exports 'baz', since replaced
# bar.js is whited-out, since removed
baz/
index.js
# foo is opaque-whited-out
# baz.js is opaque-whited-out
```
Binary file modified tests/testfiles/barlib.tar
Binary file not shown.
71 changes: 71 additions & 0 deletions tests/testfiles/rebase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"flag"
"fmt"
"log"
"os"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/tarball"
)

func mustParseRef(img string) name.Reference {
ref, err := name.ParseReference(img)
if err != nil {
log.Fatalf("could not parse reference from %q: %w", img, err)
}
return ref
}

func main() {
old := flag.String("old", "", "old base")
nu := flag.String("new", "", "new base")
orig := flag.String("original", "", "image to rebase")
out := flag.String("out", "", "result tarball")

flag.Parse()

origImg, err := daemon.Image(mustParseRef(*orig))
if err != nil {
log.Fatalf("pulling %s: %v", *orig, err)
}

oldBaseImg, err := daemon.Image(mustParseRef(*old))
if err != nil {
log.Fatalf("pulling %s: %v", *old, err)
}

newBaseImg, err := daemon.Image(mustParseRef(*nu))
if err != nil {
log.Fatalf("pulling %s: %v", *nu, err)
}

img, err := mutate.Rebase(origImg, oldBaseImg, newBaseImg)
if err != nil {
log.Fatalf("rebasing: %v", err)
}

image := (*out)[:len(*out)-4] + ":latest"
newTag, err := name.NewTag(image)
if err != nil {
log.Fatalf("could not create image ref %q: %w", image, err)
}
f, err := os.Create(*out)
if err != nil {
log.Fatalf("could not create file %q: %w", *out, err)
}
defer f.Close()

if err := tarball.Write(newTag, img, f); err != nil {
log.Fatalf("could not write image to %v: %w", *out, err)
}

digest, err := img.Digest()
if err != nil {
log.Fatalf("digesting rebased: %v", err)
}
fmt.Printf("Wrote image %s@%s to file %s\n", image, digest.String(), *out)
}
7 changes: 7 additions & 0 deletions tests/testfiles/src/barlib/Dockerfile.alpine-bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine-foo

WORKDIR /jk/modules

COPY baz.js ./baz/index.js
RUN rm bar.js
COPY baz.js foo.js
5 changes: 5 additions & 0 deletions tests/testfiles/src/barlib/Dockerfile.alpine-foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:3.9

WORKDIR /jk/modules

COPY foo.js bar.js ./
6 changes: 6 additions & 0 deletions tests/testfiles/src/barlib/Dockerfile.base-foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM scratch

WORKDIR /jk/modules

COPY foo.js bar.js ./
COPY baz.js ./baz/
1 change: 1 addition & 0 deletions tests/testfiles/src/barlib/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'bar';
1 change: 1 addition & 0 deletions tests/testfiles/src/barlib/baz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'baz';
1 change: 1 addition & 0 deletions tests/testfiles/src/barlib/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'foo';

0 comments on commit fe3bbde

Please sign in to comment.