Merge pull request #5 from drone-plugins/layer-caching
Support Buildah Layer caching
This commit is contained in:
commit
aacad6eca9
@ -182,6 +182,46 @@ func main() {
|
|||||||
Usage: "additional host:IP mapping",
|
Usage: "additional host:IP mapping",
|
||||||
EnvVar: "PLUGIN_ADD_HOST",
|
EnvVar: "PLUGIN_ADD_HOST",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "s3-local-cache-dir",
|
||||||
|
Usage: "local directory for S3 based cache",
|
||||||
|
EnvVar: "PLUGIN_S3_LOCAL_CACHE_DIR",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "s3-bucket",
|
||||||
|
Usage: "S3 bucket name",
|
||||||
|
EnvVar: "PLUGIN_S3_BUCKET",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "s3-endpoint",
|
||||||
|
Usage: "S3 endpoint address",
|
||||||
|
EnvVar: "PLUGIN_S3_ENDPOINT",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "s3-region",
|
||||||
|
Usage: "S3 region",
|
||||||
|
EnvVar: "PLUGIN_S3_REGION",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "s3-key",
|
||||||
|
Usage: "S3 access key",
|
||||||
|
EnvVar: "PLUGIN_S3_ACCESS_KEY",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "s3-secret",
|
||||||
|
Usage: "S3 access secret",
|
||||||
|
EnvVar: "PLUGIN_S3_SECRET",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "s3-use-ssl",
|
||||||
|
Usage: "Enable SSL for S3 connections",
|
||||||
|
EnvVar: "PLUGIN_S3_USE_SSL",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "layers",
|
||||||
|
Usage: "User Layers",
|
||||||
|
EnvVar: "PLUGIN_LAYERS",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@ -221,6 +261,14 @@ func run(c *cli.Context) error {
|
|||||||
NoCache: c.Bool("no-cache"),
|
NoCache: c.Bool("no-cache"),
|
||||||
AddHost: c.StringSlice("add-host"),
|
AddHost: c.StringSlice("add-host"),
|
||||||
Quiet: c.Bool("quiet"),
|
Quiet: c.Bool("quiet"),
|
||||||
|
S3CacheDir: c.String("s3-local-cache-dir"),
|
||||||
|
S3Bucket: c.String("s3-bucket"),
|
||||||
|
S3Endpoint: c.String("s3-endpoint"),
|
||||||
|
S3Region: c.String("s3-region"),
|
||||||
|
S3Key: c.String("s3-key"),
|
||||||
|
S3Secret: c.String("s3-secret"),
|
||||||
|
S3UseSSL: c.Bool("s3-use-ssl"),
|
||||||
|
Layers: c.Bool("layers"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
39
docker.go
39
docker.go
@ -45,6 +45,14 @@ type (
|
|||||||
NoCache bool // Docker build no-cache
|
NoCache bool // Docker build no-cache
|
||||||
AddHost []string // Docker build add-host
|
AddHost []string // Docker build add-host
|
||||||
Quiet bool // Docker build quiet
|
Quiet bool // Docker build quiet
|
||||||
|
S3CacheDir string
|
||||||
|
S3Bucket string
|
||||||
|
S3Endpoint string
|
||||||
|
S3Region string
|
||||||
|
S3Key string
|
||||||
|
S3Secret string
|
||||||
|
S3UseSSL bool
|
||||||
|
Layers bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin defines the Docker plugin parameters.
|
// Plugin defines the Docker plugin parameters.
|
||||||
@ -190,6 +198,7 @@ func commandInfo() *exec.Cmd {
|
|||||||
func commandBuild(build Build) *exec.Cmd {
|
func commandBuild(build Build) *exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"bud",
|
"bud",
|
||||||
|
"--storage-driver", "vfs",
|
||||||
"-f", build.Dockerfile,
|
"-f", build.Dockerfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +232,30 @@ func commandBuild(build Build) *exec.Cmd {
|
|||||||
if build.Quiet {
|
if build.Quiet {
|
||||||
args = append(args, "--quiet")
|
args = append(args, "--quiet")
|
||||||
}
|
}
|
||||||
|
if build.Layers {
|
||||||
|
args = append(args, "--layers=true")
|
||||||
|
if build.S3CacheDir != "" {
|
||||||
|
args = append(args, "--s3-local-cache-dir", build.S3CacheDir)
|
||||||
|
if build.S3Bucket != "" {
|
||||||
|
args = append(args, "--s3-bucket", build.S3Bucket)
|
||||||
|
}
|
||||||
|
if build.S3Endpoint != "" {
|
||||||
|
args = append(args, "--s3-endpoint", build.S3Endpoint)
|
||||||
|
}
|
||||||
|
if build.S3Region != "" {
|
||||||
|
args = append(args, "--s3-region", build.S3Region)
|
||||||
|
}
|
||||||
|
if build.S3Key != "" {
|
||||||
|
args = append(args, "--s3-key", build.S3Key)
|
||||||
|
}
|
||||||
|
if build.S3Secret != "" {
|
||||||
|
args = append(args, "--s3-secret", build.S3Secret)
|
||||||
|
}
|
||||||
|
if build.S3UseSSL {
|
||||||
|
args = append(args, "--s3-use-ssl=true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if build.AutoLabel {
|
if build.AutoLabel {
|
||||||
labelSchema := []string{
|
labelSchema := []string{
|
||||||
@ -303,14 +336,14 @@ func commandTag(build Build, tag string) *exec.Cmd {
|
|||||||
target = fmt.Sprintf("%s:%s", build.Repo, tag)
|
target = fmt.Sprintf("%s:%s", build.Repo, tag)
|
||||||
)
|
)
|
||||||
return exec.Command(
|
return exec.Command(
|
||||||
buildahExe, "tag", source, target,
|
buildahExe, "tag", "--storage-driver", "vfs", source, target,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker push command.
|
// helper function to create the docker push command.
|
||||||
func commandPush(build Build, tag string) *exec.Cmd {
|
func commandPush(build Build, tag string) *exec.Cmd {
|
||||||
target := fmt.Sprintf("%s:%s", build.Repo, tag)
|
target := fmt.Sprintf("%s:%s", build.Repo, tag)
|
||||||
return exec.Command(buildahExe, "push", target)
|
return exec.Command(buildahExe, "push", "--storage-driver", "vfs", target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper to check if args match "docker prune"
|
// helper to check if args match "docker prune"
|
||||||
@ -324,7 +357,7 @@ func isCommandRmi(args []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func commandRmi(tag string) *exec.Cmd {
|
func commandRmi(tag string) *exec.Cmd {
|
||||||
return exec.Command(buildahExe, "rmi", tag)
|
return exec.Command(buildahExe, "--storage-driver", "vfs", "rmi", tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// trace writes each command to stdout with the command wrapped in an xml
|
// trace writes each command to stdout with the command wrapped in an xml
|
||||||
|
|||||||
@ -1,22 +1,40 @@
|
|||||||
# Source for dockerfile:
|
FROM fedora
|
||||||
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
|
|
||||||
FROM quay.io/buildah/stable:v1.14.8
|
|
||||||
|
|
||||||
RUN touch /etc/subgid /etc/subuid \
|
RUN dnf -y install \
|
||||||
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
|
make \
|
||||||
&& echo build:10000:65536 > /etc/subuid \
|
golang \
|
||||||
&& echo build:10000:65536 > /etc/subgid
|
bats \
|
||||||
|
btrfs-progs-devel \
|
||||||
|
device-mapper-devel \
|
||||||
|
glib2-devel \
|
||||||
|
gpgme-devel \
|
||||||
|
libassuan-devel \
|
||||||
|
libseccomp-devel \
|
||||||
|
git \
|
||||||
|
bzip2 \
|
||||||
|
go-md2man \
|
||||||
|
runc \
|
||||||
|
containers-common \
|
||||||
|
skopeo-containers
|
||||||
|
|
||||||
# Use chroot since the default runc does not work when running rootless
|
# Workaround - the first install somehow leaves the golang in a bad state
|
||||||
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
|
RUN dnf -y install golang
|
||||||
|
|
||||||
# Use VFS since fuse does not work
|
RUN mkdir /root/buildah && \
|
||||||
RUN mkdir -p /home/build/.config/containers \
|
cd /root/buildah && \
|
||||||
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
|
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
|
||||||
|
|
||||||
|
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM quay.io/buildah/stable:v1.23.0
|
||||||
|
|
||||||
USER build
|
USER build
|
||||||
WORKDIR /home/build
|
WORKDIR /home/build
|
||||||
|
RUN export STORAGE_DRIVER=vfs
|
||||||
# Add plugin binary
|
# Add plugin binary
|
||||||
ADD release/linux/amd64/drone-docker /bin/
|
ADD release/linux/amd64/drone-docker /bin/
|
||||||
ENTRYPOINT ["/bin/drone-docker"]
|
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
|
||||||
|
|
||||||
|
ENTRYPOINT ["/bin/drone-docker"]
|
||||||
@ -1,21 +1,39 @@
|
|||||||
# Source for dockerfile:
|
FROM fedora
|
||||||
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
|
|
||||||
FROM quay.io/buildah/stable:v1.14.8
|
|
||||||
|
|
||||||
RUN touch /etc/subgid /etc/subuid \
|
RUN dnf -y install \
|
||||||
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
|
make \
|
||||||
&& echo build:10000:65536 > /etc/subuid \
|
golang \
|
||||||
&& echo build:10000:65536 > /etc/subgid
|
bats \
|
||||||
|
btrfs-progs-devel \
|
||||||
|
device-mapper-devel \
|
||||||
|
glib2-devel \
|
||||||
|
gpgme-devel \
|
||||||
|
libassuan-devel \
|
||||||
|
libseccomp-devel \
|
||||||
|
git \
|
||||||
|
bzip2 \
|
||||||
|
go-md2man \
|
||||||
|
runc \
|
||||||
|
containers-common \
|
||||||
|
skopeo-containers
|
||||||
|
|
||||||
# Use chroot since the default runc does not work when running rootless
|
# Workaround - the first install somehow leaves the golang in a bad state
|
||||||
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
|
RUN dnf -y install golang
|
||||||
|
|
||||||
# Use VFS since fuse does not work
|
RUN mkdir /root/buildah && \
|
||||||
RUN mkdir -p /home/build/.config/containers \
|
cd /root/buildah && \
|
||||||
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
|
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
|
||||||
|
|
||||||
|
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM quay.io/buildah/stable:v1.23.0
|
||||||
|
|
||||||
USER build
|
USER build
|
||||||
WORKDIR /home/build
|
WORKDIR /home/build
|
||||||
|
RUN export STORAGE_DRIVER=vfs
|
||||||
|
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
|
||||||
|
|
||||||
# Add plugin binary
|
# Add plugin binary
|
||||||
ADD release/linux/amd64/drone-docker /bin/
|
ADD release/linux/amd64/drone-docker /bin/
|
||||||
|
|||||||
@ -1,21 +1,39 @@
|
|||||||
# Source for dockerfile:
|
FROM fedora
|
||||||
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
|
|
||||||
FROM quay.io/buildah/stable:v1.14.8
|
|
||||||
|
|
||||||
RUN touch /etc/subgid /etc/subuid \
|
RUN dnf -y install \
|
||||||
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
|
make \
|
||||||
&& echo build:10000:65536 > /etc/subuid \
|
golang \
|
||||||
&& echo build:10000:65536 > /etc/subgid
|
bats \
|
||||||
|
btrfs-progs-devel \
|
||||||
|
device-mapper-devel \
|
||||||
|
glib2-devel \
|
||||||
|
gpgme-devel \
|
||||||
|
libassuan-devel \
|
||||||
|
libseccomp-devel \
|
||||||
|
git \
|
||||||
|
bzip2 \
|
||||||
|
go-md2man \
|
||||||
|
runc \
|
||||||
|
containers-common \
|
||||||
|
skopeo-containers
|
||||||
|
|
||||||
# Use chroot since the default runc does not work when running rootless
|
# Workaround - the first install somehow leaves the golang in a bad state
|
||||||
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
|
RUN dnf -y install golang
|
||||||
|
|
||||||
# Use VFS since fuse does not work
|
RUN mkdir /root/buildah && \
|
||||||
RUN mkdir -p /home/build/.config/containers \
|
cd /root/buildah && \
|
||||||
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
|
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
|
||||||
|
|
||||||
|
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM quay.io/buildah/stable:v1.23.0
|
||||||
|
|
||||||
USER build
|
USER build
|
||||||
WORKDIR /home/build
|
WORKDIR /home/build
|
||||||
|
RUN export STORAGE_DRIVER=vfs
|
||||||
|
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
|
||||||
|
|
||||||
# Add plugin binary
|
# Add plugin binary
|
||||||
ADD release/linux/amd64/drone-docker /bin/
|
ADD release/linux/amd64/drone-docker /bin/
|
||||||
|
|||||||
@ -1,21 +1,39 @@
|
|||||||
# Source for dockerfile:
|
FROM fedora
|
||||||
# https://github.com/containers/buildah/blob/master/docs/tutorials/05-openshift-rootless-bud.md
|
|
||||||
FROM quay.io/buildah/stable:v1.14.8
|
|
||||||
|
|
||||||
RUN touch /etc/subgid /etc/subuid \
|
RUN dnf -y install \
|
||||||
&& chmod g=u /etc/subgid /etc/subuid /etc/passwd \
|
make \
|
||||||
&& echo build:10000:65536 > /etc/subuid \
|
golang \
|
||||||
&& echo build:10000:65536 > /etc/subgid
|
bats \
|
||||||
|
btrfs-progs-devel \
|
||||||
|
device-mapper-devel \
|
||||||
|
glib2-devel \
|
||||||
|
gpgme-devel \
|
||||||
|
libassuan-devel \
|
||||||
|
libseccomp-devel \
|
||||||
|
git \
|
||||||
|
bzip2 \
|
||||||
|
go-md2man \
|
||||||
|
runc \
|
||||||
|
containers-common \
|
||||||
|
skopeo-containers
|
||||||
|
|
||||||
# Use chroot since the default runc does not work when running rootless
|
# Workaround - the first install somehow leaves the golang in a bad state
|
||||||
RUN echo "export BUILDAH_ISOLATION=chroot" >> /home/build/.bashrc
|
RUN dnf -y install golang
|
||||||
|
|
||||||
# Use VFS since fuse does not work
|
RUN mkdir /root/buildah && \
|
||||||
RUN mkdir -p /home/build/.config/containers \
|
cd /root/buildah && \
|
||||||
&& echo "driver=\"vfs\"" > /home/build/.config/containers/storage.conf
|
git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah
|
||||||
|
|
||||||
|
RUN cd /root/buildah/src/github.com/containers/buildah && make && sudo make install
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM quay.io/buildah/stable:v1.23.0
|
||||||
|
|
||||||
USER build
|
USER build
|
||||||
WORKDIR /home/build
|
WORKDIR /home/build
|
||||||
|
RUN export STORAGE_DRIVER=vfs
|
||||||
|
COPY --from=0 /root/buildah/src/github.com/containers/buildah/bin/. /bin/
|
||||||
|
|
||||||
# Add plugin binary
|
# Add plugin binary
|
||||||
ADD release/linux/amd64/drone-docker /bin/
|
ADD release/linux/amd64/drone-docker /bin/
|
||||||
|
|||||||
@ -14,5 +14,4 @@ GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-gcr ./cmd/drone
|
|||||||
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-ecr ./cmd/drone-ecr
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-ecr ./cmd/drone-ecr
|
||||||
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-docker ./cmd/drone-docker
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-docker ./cmd/drone-docker
|
||||||
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-acr ./cmd/drone-acr
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-acr ./cmd/drone-acr
|
||||||
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-heroku ./cmd/drone-heroku
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/drone-heroku ./cmd/drone-heroku
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user