• Stars
    star
    723
  • Rank 60,091 (Top 2 %)
  • Language
    Groovy
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a Gradle plugin for orchestrating docker builds and pushes.

Autorelease

Docker Gradle Plugin

Build Status Gradle Plugins Release

Disclaimer: This Repo is now Defunct

  • This repo is on life support only - although we will keep it working, no new features are accepted;
  • It is no longer used internally at Palantir.

Docker Plugin

This repository provides three Gradle plugins for working with Docker containers:

  • com.palantir.docker: add basic tasks for building and pushing docker images based on a simple configuration block that specifies the container name, the Dockerfile, task dependencies, and any additional file resources required for the Docker build.
  • com.palantir.docker-compose: adds a task for populating placeholders in a docker-compose template file with image versions resolved from dependencies.
  • com.palantir.docker-run: adds tasks for starting, stopping, statusing and cleaning up a named container based on a specified image

Apply the plugin using standard gradle convention:

plugins {
    id 'com.palantir.docker' version '<version>'
}

Set the container name, and then optionally specify a Dockerfile, any task dependencies and file resources required for the Docker build. This plugin will automatically include outputs of task dependencies in the Docker build context.

Docker Configuration Parameters

  • name the name to use for this container, may include a tag
  • tags (deprecated) (optional) an argument list of tags to create; any tag in name will be stripped before applying a specific tag; defaults to the empty set
  • tag (optional) a tag to create with a specified task name
  • dockerfile (optional) the dockerfile to use for building the image; defaults to project.file('Dockerfile') and must be a file object
  • files (optional) an argument list of files to be included in the Docker build context, evaluated per Project#files. For example, files tasks.distTar.outputs adds the TAR/TGZ file produced by the distTar tasks, and files tasks.distTar.outputs, 'my-file.txt' adds the archive in addition to file my-file.txt from the project root directory. The specified files are collected in a Gradle CopySpec which may be copied into the Docker build context directory. The underlying CopySpec may also be used to copy entire directories into the build context. The following example adds the aforementioned archive and text file to the CopySpec, uses the CopySpec to add all files from src/myDir into the CopySpec, then finally executes the copy into the directory myDir in docker build context.
docker {
    files tasks.distTar.outputs, 'my-file.txt'
    copySpec.from("src/myDir").into("myDir")
}

The final structure will be:

build/
  docker/
    myDir/
      my-file.txt
      // contents of task.distTar.outputs
      // files from src/myDir
  • buildArgs (optional) an argument map of string to string which will set --build-arg arguments to the docker build command; defaults to empty, which results in no --build-arg parameters
  • labels (optional) a map of string to string which will set --label arguments to the docker build command; defaults to empty, which results in no labels applied.
  • pull (optional) a boolean argument which defines whether Docker should attempt to pull a newer version of the base image before building; defaults to false
  • noCache (optional) a boolean argument which defines whether Docker build should add the option --no-cache, so that it rebuilds the whole image from scratch; defaults to false
  • buildx (optional) a boolean argument which defines whether Docker build should use buildx for cross platform builds; defaults to false
  • platform (optional) a list of strings argument which defines which platforms buildx should target; defaults to empty
  • builder (optional) a string argument which defines which builder buildx should use; defaults to null
  • load (optional) a boolean argument which defines whether Docker buildx builder should add --load flag, loading the image into the local repository; defaults to false
  • push (optional) a boolean argument which defines whether Docker buildx builder should add --push flag, pushing the image into the remote registry; defaults to false

To build a docker container, run the docker task. To push that container to a docker repository, run the dockerPush task.

Tag and Push tasks for each tag will be generated for each provided tag and tags entry.

Examples

Simplest configuration:

docker {
    name 'hub.docker.com/username/my-app:version'
}

Canonical configuration for building a Docker image from a distribution archive:

// Assumes that Gradle "distribution" plugin is applied
docker {
    name 'hub.docker.com/username/my-app:version'
    files tasks.distTar.outputs   // adds resulting *.tgz to the build context
}

Configuration specifying all parameters:

docker {
    name 'hub.docker.com/username/my-app:version'
    tags 'latest' // deprecated, use 'tag'
    tag 'myRegistry', 'my.registry.com/username/my-app:version'
    dockerfile file('Dockerfile')
    files tasks.distTar.outputs, 'file1.txt', 'file2.txt'
    buildArgs([BUILD_VERSION: 'version'])
    labels(['key': 'value'])
    pull true
    noCache true
}

Managing Docker image dependencies

The com.palantir.docker and com.palantir.docker-compose plugins provide functionality to declare and resolve version-aware dependencies between docker images. The primary use-case is to generate docker-compose.yml files whose image versions are mutually compatible and up-to-date in cases where multiple images depend on the existence of the same Dockerized service.

Specifying and publishing dependencies on Docker images

The docker plugin adds a docker Gradle component and a docker Gradle configuration that can be used to specify and publish dependencies on other Docker containers.

Example

plugins {
    id 'maven-publish'
    id 'com.palantir.docker'
}

...

dependencies {
    docker 'foogroup:barmodule:0.1.2'
    docker project(":someSubProject")
}

publishing {
    publications {
        dockerPublication(MavenPublication) {
            from components.docker
            artifactId project.name + "-docker"
        }
    }
}

The above configuration adds a Maven publication that specifies dependencies on barmodule and the someSubProject Gradle sub project. The resulting POM file has two dependency entries, one for each dependency. Each project can declare its dependencies on other docker images and publish an artifact advertising those dependencies.

Generating docker-compose.yml files from dependencies

The com.palantir.docker-compose plugin uses the transitive dependencies of the docker configuration to populate a docker-compose.yml.template file with the image versions specified by this project and all its transitive dependencies. The plugin uses standard Maven/Ivy machanism for declaring and resolving dependencies.

The generateDockerCompose task generates a docker-compose.yml file from a user-defined template by replacing each version variable by the concrete version declared by the transitive dependencies of the docker configuration. The task performs two operations: First, it generates a mapping group:name --> version from the dependencies of the docker configuration (see above). Second, it replaces all occurrences of version variables of the form {{group:name}} in the docker-compose.yml.template file by the resolved versions and writes the resulting file as docker-compose.yml.

The docker-compose plugin also provides a dockerComposeUp task that starts the docker images specified in the dockerComposeFile in detached mode. You can also use the dockerComposeDown task to stop the containers.

Example

Assume a docker-compose.yml.template as follows:

myservice:
  image: 'repository/myservice:latest'
otherservice:
  image: 'repository/otherservice:{{othergroup:otherservice}}'

build.gradle declares a dependency on a docker image published as 'othergroup:otherservice' in version 0.1.2:

plugins {
    id 'com.palantir.docker-compose'
}

dependencies {
    docker 'othergroup:otherservice:0.1.2'
}

The generateDockerCompose task creates a docker-compose.yml as follows:

myservice:
  image: 'repository/myservice:latest'
otherservice:
  image: 'repository/otherservice:0.1.2'

The generateDockerCompose task fails if the template file contains variables that cannot get resolved using the provided docker dependencies. Version conflicts between transitive dependencies of the same artifact are handled with the standard Gradle semantics: each artifact is resolved to the highest declared version.

Configuring file locations

The template and generated file locations are customizable through the dockerCompose extension:

dockerCompose {
    template 'my-template.yml'
    dockerComposeFile 'my-docker-compose.yml'
}

Docker Run Plugin

Apply the plugin using standard gradle convention:

plugins {
    id 'com.palantir.docker-run' version '<version>'
}

Use the dockerRun configuration block to configure the name, image and optional command to execute for the dockerRun tasks:

dockerRun {
    name 'my-container'
    image 'busybox'
    volumes 'hostvolume': '/containervolume'
    ports '7080:5000'
    daemonize true
    env 'MYVAR1': 'MYVALUE1', 'MYVAR2': 'MYVALUE2'
    command 'sleep', '100'
    arguments '--hostname=custom', '-P'
}

Docker Run Configuration Parameters

  • name the name to use for this container, may include a tag.
  • image the name of the image to use.
  • volumes optional map of volumes to mount in the container. The key is the path to the host volume, resolved using project.file(). The value is the exposed container volume path.
  • ports optional mapping local:container of local port to container port.
  • env optional map of environment variables to supply to the running container. These must be exposed in the Dockerfile with ENV instructions.
  • daemonize defaults to true to daemonize the container after starting. However if your container runs a command and exits, you can set this to false.
  • ignoreExitValue (optional) to ignore the exit code returned from the execution of the docker command; defaults to false
  • clean (optional) a boolean argument which adds --rm to the docker run command to ensure that containers are cleaned up after running; defaults to false
  • command the command to run.
  • arguments additional arguments to be passed into the docker run command. Please see https://docs.docker.com/engine/reference/run/ for possible values.

Tasks

  • Docker
    • docker: build a docker image with the specified name and Dockerfile
    • dockerTag: tag the docker image with all specified tags
    • dockerTag<tag>: tag the docker image with <tag>
    • dockerPush: push the specified image to a docker repository
    • dockerPush<tag>: push the <tag> docker image to a docker repository
    • dockerTagsPush: push all tagged docker images to a docker repository
    • dockerPrepare: prepare to build a docker image by copying dependent task outputs, referenced files, and dockerfile into a temporary directory
    • dockerClean: remove temporary directory associated with the docker build
    • dockerfileZip: builds a ZIP file containing the configured Dockerfile
  • Docker Compose
    • generateDockerCompose: Populates a docker-compose file template with image versions declared by dependencies
    • dockerComposeUp: Brings up services defined in dockerComposeFile in detacted state
    • dockerComposeDown: Stops services defined in dockerComposeFile
  • Docker Run
    • dockerRun: run the specified image with the specified name
    • dockerStop: stop the running container
    • dockerRunStatus: indicate the run status of the container
    • dockerRemoveContainer: remove the container

License

This plugin is made available under the Apache 2.0 License.

Contributing

Contributions to this project must follow the contribution guide.

More Repositories

1

blueprint

A React-based UI toolkit for the web
TypeScript
19,885
star
2

tslint

๐Ÿšฆ An extensible linter for the TypeScript language
TypeScript
5,916
star
3

plottable

๐Ÿ“Š A library of modular chart components built on D3
TypeScript
2,926
star
4

python-language-server

An implementation of the Language Server Protocol for Python
Python
2,579
star
5

windows-event-forwarding

A repository for using windows event forwarding for incident detection and response
Roff
1,186
star
6

pyspark-style-guide

This is a guide to PySpark code style presenting common situations and the associated best practices based on the most frequent recurring topics across the PySpark repos we've encountered.
Python
945
star
7

osquery-configuration

A repository for using osquery for incident detection and response
800
star
8

tslint-react

๐Ÿ“™ Lint rules related to React & JSX for TSLint.
TypeScript
752
star
9

bulldozer

GitHub Pull Request Auto-Merge Bot
Go
725
star
10

policy-bot

A GitHub App that enforces approval policies on pull requests
Go
700
star
11

alerting-detection-strategy-framework

A framework for developing alerting and detection strategies for incident response.
610
star
12

stacktrace

Stack traces for Go errors
Go
498
star
13

docker-compose-rule

A JUnit rule to manage docker containers using docker-compose
Java
422
star
14

conjure

Strongly typed HTTP/JSON APIs for browsers and microservices
Java
393
star
15

palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Java
373
star
16

eclipse-typescript

An Eclipse plug-in for developing in the TypeScript language.
JavaScript
341
star
17

gradle-git-version

a Gradle plugin that uses `git describe` to produce a version string.
Java
339
star
18

go-githubapp

A simple Go framework for building GitHub Apps
Go
317
star
19

godel

Go tool for formatting, checking, building, distributing and publishing projects
Go
304
star
20

gradle-baseline

A set of Gradle plugins that configure default code quality tools for developers.
Java
283
star
21

jamf-pro-scripts

A collection of scripts and extension attributes created for managing Mac workstations via Jamf Pro.
Shell
277
star
22

gradle-graal

A plugin for Gradle that adds tasks to download, extract and interact with GraalVM tooling.
Java
225
star
23

log4j-sniffer

A tool that scans archives to check for vulnerable log4j versions
Go
193
star
24

tfjson

Terraform plan file to JSON
Go
182
star
25

k8s-spark-scheduler

A Kubernetes Scheduler Extender to provide gang scheduling support for Spark on Kubernetes
Go
175
star
26

Sysmon

A lightweight platform monitoring tool for Java VMs
Java
155
star
27

typesettable

๐Ÿ“ A typesetting library for SVG and Canvas
TypeScript
146
star
28

documentalist

๐Ÿ“ A sort-of-static site generator optimized for living documentation of software projects
TypeScript
145
star
29

exploitguard

Documentation and supporting script sample for Windows Exploit Guard
PowerShell
144
star
30

bouncer

An application to cycle (bounce) all nodes in a coordinated fashion in an AWS ASG or set of related ASGs
Go
130
star
31

gradle-consistent-versions

Compact, constraint-friendly lockfiles for your dependencies
Java
111
star
32

Cinch

A Java library that manages component action/event bindings for MVC patterns
Java
110
star
33

redoodle

An addon library for Redux that enhances its integration with TypeScript.
TypeScript
99
star
34

gradle-jacoco-coverage

Groovy
99
star
35

sqlite3worker

A threadsafe sqlite worker for Python
Python
94
star
36

phishcatch

A browser extension and API server for detecting corporate password use on external websites
CSS
83
star
37

python-jsonrpc-server

A Python 2 and 3 asynchronous JSON RPC server
Python
80
star
38

conjure-java-runtime

Opinionated libraries for HTTP&JSON-based RPC using Retrofit, Feign, OkHttp as clients and Jetty/Jersey as servers
Java
78
star
39

stashbot

A plugin for Atlassian Stash to allow easy, self-service continuous integration with Jenkins
Java
67
star
40

go-baseapp

A lightweight starting point for Go web servers
Go
67
star
41

stash-codesearch-plugin

Provides global repository, commit, and file content search for Atlassian Stash instances
Java
62
star
42

gradle-processors

Gradle plugin for integrating Java annotation processors
Groovy
62
star
43

go-java-launcher

A simple Go program for launching Java programs from a fixed configuration. This program replaces Gradle-generated Bash launch scripts which are susceptible to attacks via injection of environment variables of the form JAVA_OPTS='$(rm -rf /)'.
Go
59
star
44

pkg

A collection of stand-alone Go packages
Go
53
star
45

rust-zipkin

A library for logging and propagating Zipkin trace information in Rust
Rust
53
star
46

grunt-tslint

A Grunt plugin for tslint.
JavaScript
51
star
47

witchcraft-go-server

A highly opinionated Go embedded application server for RESTy APIs
Go
50
star
48

spark-influx-sink

A Spark metrics sink that pushes to InfluxDb
Scala
50
star
49

giraffe

Gracefully Integrated Remote Access For Files and Execution
Java
49
star
50

language-servers

[Deprecated and No longer supported] A collection of implementations for the Microsoft Language Server Protocol
Java
46
star
51

go-license

Go tool that applies and verifies that proper license headers are applied to Go files
Go
44
star
52

hadoop-crypto

Library for per-file client-side encyption in Hadoop FileSystems such as HDFS or S3.
Java
41
star
53

tritium

Tritium is a library for instrumenting applications to provide better observability at runtime
Java
39
star
54

sls-packaging

A set of Gradle plugins for creating SLS-compatible packages
Shell
38
star
55

roboslack

A pluggable, fluent, straightforward Java library for interacting with Slack.
Java
37
star
56

dropwizard-web-security

A Dropwizard bundle for applying default web security functionality
Java
37
star
57

goastwriter

Go library for writing Go source code programatically
Go
31
star
58

gradle-gitsemver

Java
31
star
59

palantir-python-sdk

Palantir Python SDK
Python
30
star
60

gradle-revapi

Gradle plugin that uses Revapi to check whether you have introduced API/ABI breaks in your Java public API
Java
29
star
61

checks

Go libraries and programs for performing static checks on Go projects
Go
29
star
62

gradle-circle-style

๐Ÿš€๐Ÿš€๐Ÿš€MOVED TO Baseline
Java
28
star
63

trove

Patched version of the Trove 3 library - changes the Collections semantics to match proper java.util.Map semantics
Java
27
star
64

dialogue

A client-side RPC library for conjure-java
Java
27
star
65

atlasdb

Transactional Distributed Database Layer
Java
27
star
66

stylelint-config-palantir

Palantir's stylelint config
JavaScript
25
star
67

typedjsonrpc

A typed decorator-based JSON-RPC library for Python
Python
24
star
68

encrypted-config-value

Tooling for encrypting certain configuration parameter values in dropwizard apps
Java
22
star
69

typescript-service-generator

Java
21
star
70

streams

Utilities for working with Java 8 streams
Java
21
star
71

distgo

Go tool for building, distributing and publishing Go projects
Go
21
star
72

gradle-npm-run-plugin

Groovy
20
star
73

conjure-python

Conjure generator for Python clients
Java
19
star
74

conjure-java

Conjure generator for Java clients and servers
Java
19
star
75

amalgomate

Go tool for combining multiple different main packages into a single program or library
Go
19
star
76

serde-encrypted-value

A crate which wraps Serde deserializers and decrypts values
Rust
19
star
77

gradle-docker-test-runner

Gradle plugin for running tests in Docker environments
Groovy
19
star
78

gerrit-ci

Plugin for Gerrit enabling self-service continuous integration workflows with Jenkins.
Java
18
star
79

conjure-rust

Conjure support for Rust
Rust
18
star
80

conjure-typescript

Conjure generator for TypeScript clients
TypeScript
17
star
81

gpg-tap-notifier-macos

Show a macOS notification when GPG is waiting for you to tap/touch a security device (e.g. YubiKey).
Swift
17
star
82

tracing-java

Java library providing zipkin-like tracing functionality
Java
16
star
83

plottable-moment

Plottable date/time formatting library built on Moment.js
JavaScript
16
star
84

spark-tpcds-benchmark

Utility for benchmarking changes in Spark using TPC-DS workloads
Java
16
star
85

assertj-automation

Automatic code rewriting for AssertJ using error-prone and refaster
Java
15
star
86

metric-schema

Schema for standard metric definitions
Java
14
star
87

safe-logging

Interfaces and utilities for safe log messages
Java
14
star
88

resource-identifier

Common resource identifier specification for inter-application object sharing
Java
14
star
89

dropwizard-web-logger

WebLoggerBundle is a Dropwizard bundle used to help log web activity to log files on a serverโ€™s backend
Java
14
star
90

gradle-shadow-jar

Gradle plugin to precisely shadow either a dependency or its transitives
Groovy
14
star
91

gradle-miniconda-plugin

Plugin that sets up a Python environment for building and running tests using Miniconda.
Java
13
star
92

conjure-go-runtime

Go implementation of the Conjure runtime
Go
12
star
93

gulp-count

Counts files in vinyl streams.
CoffeeScript
12
star
94

gradle-configuration-resolver-plugin

Groovy
12
star
95

asana_mailer

A script that uses Asana's RESTful API to generate plaintext and HTML emails.
Python
12
star
96

human-readable-types

A collection of human-readable types
Java
11
star
97

dropwizard-index-page

A Dropwizard bundle that serves the index page for a single page application
Java
11
star
98

eclipse-less

An Eclipse plug-in for compiling LESS files.
Java
11
star
99

go-compiles

Go check that checks that Go source and tests compiles
Go
11
star
100

go-generate

Go tool that runs and verifies the output of go generate
Go
11
star