Skip to content

Commit aacad6e

Browse files
authored
Merge pull request #5 from drone-plugins/layer-caching
Support Buildah Layer caching
2 parents cd4f459 + 3705ed0 commit aacad6e

File tree

7 files changed

+207
-55
lines changed

7 files changed

+207
-55
lines changed

cmd/drone-docker/main.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,46 @@ func main() {
182182
Usage: "additional host:IP mapping",
183183
EnvVar: "PLUGIN_ADD_HOST",
184184
},
185+
cli.StringFlag{
186+
Name: "s3-local-cache-dir",
187+
Usage: "local directory for S3 based cache",
188+
EnvVar: "PLUGIN_S3_LOCAL_CACHE_DIR",
189+
},
190+
cli.StringFlag{
191+
Name: "s3-bucket",
192+
Usage: "S3 bucket name",
193+
EnvVar: "PLUGIN_S3_BUCKET",
194+
},
195+
cli.StringFlag{
196+
Name: "s3-endpoint",
197+
Usage: "S3 endpoint address",
198+
EnvVar: "PLUGIN_S3_ENDPOINT",
199+
},
200+
cli.StringFlag{
201+
Name: "s3-region",
202+
Usage: "S3 region",
203+
EnvVar: "PLUGIN_S3_REGION",
204+
},
205+
cli.StringFlag{
206+
Name: "s3-key",
207+
Usage: "S3 access key",
208+
EnvVar: "PLUGIN_S3_ACCESS_KEY",
209+
},
210+
cli.StringFlag{
211+
Name: "s3-secret",
212+
Usage: "S3 access secret",
213+
EnvVar: "PLUGIN_S3_SECRET",
214+
},
215+
cli.BoolFlag{
216+
Name: "s3-use-ssl",
217+
Usage: "Enable SSL for S3 connections",
218+
EnvVar: "PLUGIN_S3_USE_SSL",
219+
},
220+
cli.BoolFlag{
221+
Name: "layers",
222+
Usage: "User Layers",
223+
EnvVar: "PLUGIN_LAYERS",
224+
},
185225
}
186226

187227
if err := app.Run(os.Args); err != nil {
@@ -221,6 +261,14 @@ func run(c *cli.Context) error {
221261
NoCache: c.Bool("no-cache"),
222262
AddHost: c.StringSlice("add-host"),
223263
Quiet: c.Bool("quiet"),
264+
S3CacheDir: c.String("s3-local-cache-dir"),
265+
S3Bucket: c.String("s3-bucket"),
266+
S3Endpoint: c.String("s3-endpoint"),
267+
S3Region: c.String("s3-region"),
268+
S3Key: c.String("s3-key"),
269+
S3Secret: c.String("s3-secret"),
270+
S3UseSSL: c.Bool("s3-use-ssl"),
271+
Layers: c.Bool("layers"),
224272
},
225273
}
226274

docker.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ type (
4545
NoCache bool // Docker build no-cache
4646
AddHost []string // Docker build add-host
4747
Quiet bool // Docker build quiet
48+
S3CacheDir string
49+
S3Bucket string
50+
S3Endpoint string
51+
S3Region string
52+
S3Key string
53+
S3Secret string
54+
S3UseSSL bool
55+
Layers bool
4856
}
4957

5058
// Plugin defines the Docker plugin parameters.
@@ -190,6 +198,7 @@ func commandInfo() *exec.Cmd {
190198
func commandBuild(build Build) *exec.Cmd {
191199
args := []string{
192200
"bud",
201+
"--storage-driver", "vfs",
193202
"-f", build.Dockerfile,
194203
}
195204

@@ -223,6 +232,30 @@ func commandBuild(build Build) *exec.Cmd {
223232
if build.Quiet {
224233
args = append(args, "--quiet")
225234
}
235+
if build.Layers {
236+
args = append(args, "--layers=true")
237+
if build.S3CacheDir != "" {
238+
args = append(args, "--s3-local-cache-dir", build.S3CacheDir)
239+
if build.S3Bucket != "" {
240+
args = append(args, "--s3-bucket", build.S3Bucket)
241+
}
242+
if build.S3Endpoint != "" {
243+
args = append(args, "--s3-endpoint", build.S3Endpoint)
244+
}
245+
if build.S3Region != "" {
246+
args = append(args, "--s3-region", build.S3Region)
247+
}
248+
if build.S3Key != "" {
249+
args = append(args, "--s3-key", build.S3Key)
250+
}
251+
if build.S3Secret != "" {
252+
args = append(args, "--s3-secret", build.S3Secret)
253+
}
254+
if build.S3UseSSL {
255+
args = append(args, "--s3-use-ssl=true")
256+
}
257+
}
258+
}
226259

227260
if build.AutoLabel {
228261
labelSchema := []string{
@@ -303,14 +336,14 @@ func commandTag(build Build, tag string) *exec.Cmd {
303336
target = fmt.Sprintf("%s:%s", build.Repo, tag)
304337
)
305338
return exec.Command(
306-
buildahExe, "tag", source, target,
339+
buildahExe, "tag", "--storage-driver", "vfs", source, target,
307340
)
308341
}
309342

310343
// helper function to create the docker push command.
311344
func commandPush(build Build, tag string) *exec.Cmd {
312345
target := fmt.Sprintf("%s:%s", build.Repo, tag)
313-
return exec.Command(buildahExe, "push", target)
346+
return exec.Command(buildahExe, "push", "--storage-driver", "vfs", target)
314347
}
315348

316349
// helper to check if args match "docker prune"
@@ -324,7 +357,7 @@ func isCommandRmi(args []string) bool {
324357
}
325358

326359
func commandRmi(tag string) *exec.Cmd {
327-
return exec.Command(buildahExe, "rmi", tag)
360+
return exec.Command(buildahExe, "--storage-driver", "vfs", "rmi", tag)
328361
}
329362

330363
// trace writes each command to stdout with the command wrapped in an xml
Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
# Source for dockerfile:
2-
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
3-
FROM quay.io/buildah/stable:v1.14.8
1+
FROM fedora
42

5-
RUN touch /etc/subgid /etc/subuid \
6-
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
7-
&& echo build:10000:65536 > /etc/subuid \
8-
&& echo build:10000:65536 > /etc/subgid
3+
RUN dnf -y install \
4+
make \
5+
golang \
6+
bats \
7+
btrfs-progs-devel \
8+
device-mapper-devel \
9+
glib2-devel \
10+
gpgme-devel \
11+
libassuan-devel \
12+
libseccomp-devel \
13+
git \
14+
bzip2 \
15+
go-md2man \
16+
runc \
17+
containers-common \
18+
skopeo-containers
919

10-
# Use chroot since the default runc does not work when running rootless
11-
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
20+
# Workaround - the first install somehow leaves the golang in a bad state
21+
RUN dnf -y install golang
1222

13-
# Use VFS since fuse does not work
14-
RUN mkdir -p /home/build/.config/containers \
15-
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
23+
RUN mkdir /root/buildah && \
24+
cd /root/buildah && \
25+
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
26+
27+
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
28+
29+
30+
31+
FROM quay.io/buildah/stable:v1.23.0
1632

1733
USER build
1834
WORKDIR /home/build
19-
35+
RUN export STORAGE_DRIVER=vfs
2036
# Add plugin binary
2137
ADD release/linux/amd64/drone-docker /bin/
22-
ENTRYPOINT ["/bin/drone-docker"]
38+
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
39+
40+
ENTRYPOINT ["/bin/drone-docker"]

docker/ecr/Dockerfile.linux.amd64

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1-
# Source for dockerfile:
2-
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
3-
FROM quay.io/buildah/stable:v1.14.8
1+
FROM fedora
42

5-
RUN touch /etc/subgid /etc/subuid \
6-
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
7-
&& echo build:10000:65536 > /etc/subuid \
8-
&& echo build:10000:65536 > /etc/subgid
3+
RUN dnf -y install \
4+
make \
5+
golang \
6+
bats \
7+
btrfs-progs-devel \
8+
device-mapper-devel \
9+
glib2-devel \
10+
gpgme-devel \
11+
libassuan-devel \
12+
libseccomp-devel \
13+
git \
14+
bzip2 \
15+
go-md2man \
16+
runc \
17+
containers-common \
18+
skopeo-containers
919

10-
# Use chroot since the default runc does not work when running rootless
11-
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
20+
# Workaround - the first install somehow leaves the golang in a bad state
21+
RUN dnf -y install golang
1222

13-
# Use VFS since fuse does not work
14-
RUN mkdir -p /home/build/.config/containers \
15-
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
23+
RUN mkdir /root/buildah && \
24+
cd /root/buildah && \
25+
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
26+
27+
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
28+
29+
30+
31+
FROM quay.io/buildah/stable:v1.23.0
1632

1733
USER build
1834
WORKDIR /home/build
35+
RUN export STORAGE_DRIVER=vfs
36+
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
1937

2038
# Add plugin binary
2139
ADD release/linux/amd64/drone-docker /bin/

docker/gcr/Dockerfile.linux.amd64

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1-
# Source for dockerfile:
2-
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
3-
FROM quay.io/buildah/stable:v1.14.8
1+
FROM fedora
42

5-
RUN touch /etc/subgid /etc/subuid \
6-
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
7-
&& echo build:10000:65536 > /etc/subuid \
8-
&& echo build:10000:65536 > /etc/subgid
3+
RUN dnf -y install \
4+
make \
5+
golang \
6+
bats \
7+
btrfs-progs-devel \
8+
device-mapper-devel \
9+
glib2-devel \
10+
gpgme-devel \
11+
libassuan-devel \
12+
libseccomp-devel \
13+
git \
14+
bzip2 \
15+
go-md2man \
16+
runc \
17+
containers-common \
18+
skopeo-containers
919

10-
# Use chroot since the default runc does not work when running rootless
11-
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
20+
# Workaround - the first install somehow leaves the golang in a bad state
21+
RUN dnf -y install golang
1222

13-
# Use VFS since fuse does not work
14-
RUN mkdir -p /home/build/.config/containers \
15-
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
23+
RUN mkdir /root/buildah && \
24+
cd /root/buildah && \
25+
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
26+
27+
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
28+
29+
30+
31+
FROM quay.io/buildah/stable:v1.23.0
1632

1733
USER build
1834
WORKDIR /home/build
35+
RUN export STORAGE_DRIVER=vfs
36+
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
1937

2038
# Add plugin binary
2139
ADD release/linux/amd64/drone-docker /bin/

docker/heroku/Dockerfile.linux.amd64

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1-
# Source for dockerfile:
2-
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
3-
FROM quay.io/buildah/stable:v1.14.8
1+
FROM fedora
42

5-
RUN touch /etc/subgid /etc/subuid \
6-
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
7-
&& echo build:10000:65536 > /etc/subuid \
8-
&& echo build:10000:65536 > /etc/subgid
3+
RUN dnf -y install \
4+
make \
5+
golang \
6+
bats \
7+
btrfs-progs-devel \
8+
device-mapper-devel \
9+
glib2-devel \
10+
gpgme-devel \
11+
libassuan-devel \
12+
libseccomp-devel \
13+
git \
14+
bzip2 \
15+
go-md2man \
16+
runc \
17+
containers-common \
18+
skopeo-containers
919

10-
# Use chroot since the default runc does not work when running rootless
11-
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
20+
# Workaround - the first install somehow leaves the golang in a bad state
21+
RUN dnf -y install golang
1222

13-
# Use VFS since fuse does not work
14-
RUN mkdir -p /home/build/.config/containers \
15-
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
23+
RUN mkdir /root/buildah && \
24+
cd /root/buildah && \
25+
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
26+
27+
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
28+
29+
30+
31+
FROM quay.io/buildah/stable:v1.23.0
1632

1733
USER build
1834
WORKDIR /home/build
35+
RUN export STORAGE_DRIVER=vfs
36+
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
1937

2038
# Add plugin binary
2139
ADD release/linux/amd64/drone-docker /bin/

scripts/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-gcr ./cmd/drone
1414
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-ecr ./cmd/drone-ecr
1515
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-docker ./cmd/drone-docker
1616
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-acr ./cmd/drone-acr
17-
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-heroku ./cmd/drone-heroku
18-
17+
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-heroku ./cmd/drone-heroku

0 commit comments

Comments
 (0)