diff --git a/cmd/drone-docker/main.go b/cmd/drone-docker/main.go index 967dbe3..7ec53af 100644 --- a/cmd/drone-docker/main.go +++ b/cmd/drone-docker/main.go @@ -182,40 +182,45 @@ func main() { Usage: "additional host:IP mapping", EnvVar: "PLUGIN_ADD_HOST", }, - cli.StringSliceFlag{ + cli.StringFlag{ Name: "s3-local-cache-dir", Usage: "local directory for S3 based cache", - EnvVar: "S3_LOCAL_CACHE_DIR", + EnvVar: "PLUGIN_S3_LOCAL_CACHE_DIR", }, - cli.StringSliceFlag{ + cli.StringFlag{ Name: "s3-bucket", Usage: "S3 bucket name", - EnvVar: "S3_BUCKET", + EnvVar: "PLUGIN_S3_BUCKET", }, - cli.StringSliceFlag{ + cli.StringFlag{ Name: "s3-endpoint", Usage: "S3 endpoint address", - EnvVar: "S3_END_POINT", + EnvVar: "PLUGIN_S3_ENDPOINT", }, - cli.StringSliceFlag{ + cli.StringFlag{ Name: "s3-region", Usage: "S3 region", - EnvVar: "S3_REGION", + EnvVar: "PLUGIN_S3_REGION", }, - cli.StringSliceFlag{ + cli.StringFlag{ Name: "s3-key", Usage: "S3 access key", - EnvVar: "S3_KEY", + EnvVar: "PLUGIN_S3_ACCESS_KEY", }, - cli.StringSliceFlag{ + cli.StringFlag{ Name: "s3-secret", Usage: "S3 access secret", - EnvVar: "S3_SECRET", + EnvVar: "PLUGIN_S3_SECRET", }, - cli.StringSliceFlag{ + cli.BoolFlag{ Name: "s3-use-ssl", Usage: "Enable SSL for S3 connections", - EnvVar: "S3_USE_SSL", + EnvVar: "PLUGIN_S3_USE_SSL", + }, + cli.BoolFlag{ + Name: "layers", + Usage: "User Layers", + EnvVar: "PLUGIN_LAYERS", }, } @@ -256,6 +261,14 @@ func run(c *cli.Context) error { NoCache: c.Bool("no-cache"), AddHost: c.StringSlice("add-host"), 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"), }, } diff --git a/docker.go b/docker.go index c31a97d..db9b08c 100644 --- a/docker.go +++ b/docker.go @@ -45,6 +45,14 @@ type ( NoCache bool // Docker build no-cache AddHost []string // Docker build add-host 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. @@ -190,6 +198,7 @@ func commandInfo() *exec.Cmd { func commandBuild(build Build) *exec.Cmd { args := []string{ "bud", + "--storage-driver", "vfs", "-f", build.Dockerfile, } @@ -223,6 +232,30 @@ func commandBuild(build Build) *exec.Cmd { if build.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 { labelSchema := []string{ @@ -303,14 +336,14 @@ func commandTag(build Build, tag string) *exec.Cmd { target = fmt.Sprintf("%s:%s", build.Repo, tag) ) return exec.Command( - buildahExe, "tag", source, target, + buildahExe, "tag", "--storage-driver", "vfs", source, target, ) } // helper function to create the docker push command. func commandPush(build Build, tag string) *exec.Cmd { 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" @@ -324,7 +357,7 @@ func isCommandRmi(args []string) bool { } 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 diff --git a/docker/docker/Dockerfile.linux.amd64 b/docker/docker/Dockerfile.linux.amd64 index 983757b..239f8c0 100644 --- a/docker/docker/Dockerfile.linux.amd64 +++ b/docker/docker/Dockerfile.linux.amd64 @@ -1,38 +1,11 @@ -FROM fedora - -RUN dnf -y install \ - make \ - golang \ - bats \ - btrfs-progs-devel \ - device-mapper-devel \ - glib2-devel \ - gpgme-devel \ - libassuan-devel \ - libseccomp-devel \ - git \ - bzip2 \ - go-md2man \ - runc \ - containers-common - -# Workaround - the first install somehow leaves the golang in a bad state -RUN dnf -y install golang - -ARG GIT_USER_NAME -RUN git config --global user.name "$GIT_USER_NAME" - -ARG GIT_USER_EMAIL -RUN git config --global user.email "$GIT_USER_EMAIL" - -RUN mkdir /root/buildah && \ - cd /root/buildah && \ - git clone https://github.com/harness/buildah.git ./src/github.com/containers/buildah - -RUN echo "alias bahrm='buildah rm --all && buildah rmi --all'" >> /root/.bashrc -RUN echo "alias bahbi='cd /root/buildah/src/github.com/containers/buildah && make && sudo make install && cd -'" >> /root/.bashrc +FROM quay.io/buildah/stable:v1.23.0 USER build -WORKDIR /root/buildah/src/github.com/containers/buildah -ADD /root/buildah/src/github.com/containers/buildah /bin/ -ENTRYPOINT ["/root/buildah/src/github.com/containers/buildah"] +WORKDIR /home/build +RUN export STORAGE_DRIVER=vfs +# Add plugin binary +ADD release/linux/amd64/drone-docker /bin/ +ADD prebuilt/buildah /bin/ +ADD prebuilt/imgtype /bin/ +ADD prebuilt/copy /bin/ +ENTRYPOINT ["/bin/drone-docker"] \ No newline at end of file diff --git a/prebuilt/buildah b/prebuilt/buildah new file mode 100755 index 0000000..22e1436 Binary files /dev/null and b/prebuilt/buildah differ diff --git a/prebuilt/copy b/prebuilt/copy new file mode 100755 index 0000000..24f733c Binary files /dev/null and b/prebuilt/copy differ diff --git a/prebuilt/imgtype b/prebuilt/imgtype new file mode 100755 index 0000000..831497f Binary files /dev/null and b/prebuilt/imgtype differ