Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
Feature/#55 add build and push (#56)
Browse files Browse the repository at this point in the history
* #55 Added build and push as goal
#54 Added env vars

* Added documentation for #54 and #55

* #55 No default value

* #54 and #55 Tests added

* #55 fixed test

* Added version to check which version the travis is using

* Travis docker-compose needs service when using build args

* Cleanup for PR
  • Loading branch information
tuxBurner authored and David Kane committed Aug 25, 2019
1 parent 7b78ffc commit 4f9915f
Show file tree
Hide file tree
Showing 49 changed files with 598 additions and 35 deletions.
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This plugin is designed to be light, fast and with minimum dependencies (only th
### Goals
* up - runs `docker-compose up`
* down - runs `docker-compose down`
* build - runs `docker-compose build`
* push - runs `docker-compose push`
* pull - runs `docker-compose pull`

### Properties
Expand Down Expand Up @@ -265,6 +267,98 @@ This can be changed in the configuration section of the plugin:
</configuration>
```

#### Environment variables

You can add env vars to your `docker-compose` call via

```xml
<configuration>
...
<envVars>
<jdkImageType>openjdk</jdkImageType>
<dockerImageTag>0.1.1</dockerImageTag>
</envVars>
...
</configuration>
```

This will add `jdkImageType=openjdk` and `dockerImageTag=0.1.1` to the environment.

#### Build arguments

The build arguments for the `build` goal have there own section in the configuration.

```xml
<configuration>
<buildArgs>
...
</buildArgs>
</configuration>
```

##### forceRm

Adds `--force-rm` to the docker-compose build call.

```xml
<configuration>
<buildArgs>
...
<forceRm>true</forceRm>
...
</buildArgs>
</configuration>
```

##### noCache

Adds `--no-cache` to the docker-compose build call.

```xml
<configuration>
<buildArgs>
...
<noCache>true</noCache>
...
</buildArgs>
</configuration>
```

##### alwaysPull

Adds `--pull` to the docker-compose build call.

```xml
<configuration>
<buildArgs>
...
<alwaysPull>true</alwaysPull>
...
</buildArgs>
</configuration>
```

##### args

Adds `--build-arg` to the docker-compose build call.


```xml
<configuration>
<buildArgs>
...
<args>
<foo>bar</foo>
<far>boor</far>
</args>
...
</buildArgs>
</configuration>
```

This will add `--build-arg foo=bar` and `--build-arg far=boor` to the docker-compose build call.


## Configuration
### Default
Below will allow use of the plugin from the `mvn` command line:
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
<debug>false</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>envvars/pom.xml</pomInclude>
<pomInclude>build/pom.xml</pomInclude>
<pomInclude>build-args/pom.xml</pomInclude>
<pomInclude>build-force-rm/pom.xml</pomInclude>
<pomInclude>build-no-cache/pom.xml</pomInclude>
<pomInclude>build-pull/pom.xml</pomInclude>
<pomInclude>down/pom.xml</pomInclude>
<pomInclude>down-remove-images/pom.xml</pomInclude>
<pomInclude>down-remove-images-local/pom.xml</pomInclude>
Expand Down
3 changes: 3 additions & 0 deletions src/it/build-args/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox

CMD echo -e Docker Compose has build successfully
6 changes: 6 additions & 0 deletions src/it/build-args/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.2'
services:
test:
image: mpdc-it-build-args
container_name: mpdc-it-build-args
build: ./
45 changes: 45 additions & 0 deletions src/it/build-args/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.dkanejs.maven.plugins.it</groupId>
<artifactId>build-args</artifactId>
<version>1.0</version>

<description>Verify "docker-compose build with arguments" runs.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>build</id>
<phase>verify</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<detachedMode>false</detachedMode>
<services>test</services>
<buildArgs>
<args>
<foo>bar</foo>
<far>boor</far>
</args>
</buildArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
6 changes: 6 additions & 0 deletions src/it/build-args/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import java.nio.file.Paths

String buildLog = new File("${basedir}/build.log").getText("UTF-8")
String composeFile = Paths.get("${basedir}/docker-compose.yml").toString()

assert buildLog.contains("Running: docker-compose -f $composeFile build --build-arg far=boor --build-arg foo=bar" as CharSequence)
3 changes: 3 additions & 0 deletions src/it/build-force-rm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox

CMD echo -e Docker Compose has build successfully
6 changes: 6 additions & 0 deletions src/it/build-force-rm/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.2'
services:
test:
image: mpdc-it-build-forcerm
container_name: mpdc-it-build-forcerm
build: ./
41 changes: 41 additions & 0 deletions src/it/build-force-rm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.dkanejs.maven.plugins.it</groupId>
<artifactId>build-force-rm</artifactId>
<version>1.0</version>

<description>Verify "docker-compose build with force rm" runs.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>build</id>
<phase>verify</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<detachedMode>false</detachedMode>
<buildArgs>
<forceRm>true</forceRm>
</buildArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions src/it/build-force-rm/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import java.nio.file.Paths

String buildLog = new File("${basedir}/build.log").getText("UTF-8")
String composeFile = Paths.get("${basedir}/docker-compose.yml").toString()

assert buildLog.contains("Running: docker-compose -f $composeFile build --force-rm" as CharSequence)
assert buildLog.contains("Successfully tagged mpdc-it-build-forcerm")
3 changes: 3 additions & 0 deletions src/it/build-no-cache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox

CMD echo -e Docker Compose has build successfully
6 changes: 6 additions & 0 deletions src/it/build-no-cache/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.2'
services:
test:
image: mpdc-it-build-nocache
container_name: mpdc-it-build-nocache
build: ./
41 changes: 41 additions & 0 deletions src/it/build-no-cache/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.dkanejs.maven.plugins.it</groupId>
<artifactId>build-no-cache</artifactId>
<version>1.0</version>

<description>Verify "docker-compose build with no cache" runs.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>build</id>
<phase>verify</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<detachedMode>false</detachedMode>
<buildArgs>
<noCache>true</noCache>
</buildArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions src/it/build-no-cache/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import java.nio.file.Paths

String buildLog = new File("${basedir}/build.log").getText("UTF-8")
String composeFile = Paths.get("${basedir}/docker-compose.yml").toString()

assert buildLog.contains("Running: docker-compose -f $composeFile build --no-cache" as CharSequence)
assert buildLog.contains("Successfully tagged mpdc-it-build-nocache:latest")
3 changes: 3 additions & 0 deletions src/it/build-pull/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox

CMD echo -e Docker Compose has build successfully
6 changes: 6 additions & 0 deletions src/it/build-pull/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.2'
services:
test:
image: mpdc-it-build-pull
container_name: mpdc-it-build-pull
build: ./
41 changes: 41 additions & 0 deletions src/it/build-pull/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.dkanejs.maven.plugins.it</groupId>
<artifactId>build-pull</artifactId>
<version>1.0</version>

<description>Verify "docker-compose build with pull" runs.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>build</id>
<phase>verify</phase>
<goals>
<goal>build</goal>
</goals>
<configuration>
<composeFile>${project.basedir}/docker-compose.yml</composeFile>
<detachedMode>false</detachedMode>
<buildArgs>
<alwaysPull>true</alwaysPull>
</buildArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions src/it/build-pull/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import java.nio.file.Paths

String buildLog = new File("${basedir}/build.log").getText("UTF-8")
String composeFile = Paths.get("${basedir}/docker-compose.yml").toString()

assert buildLog.contains("Running: docker-compose -f $composeFile build --pull" as CharSequence)
assert buildLog.contains("Successfully tagged mpdc-it-build-pull:latest")
3 changes: 3 additions & 0 deletions src/it/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox

CMD echo -e Docker Compose has build successfully
6 changes: 6 additions & 0 deletions src/it/build/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.2'
services:
test:
image: mpdc-it-build
container_name: mpdc-it-build
build: ./
Loading

0 comments on commit 4f9915f

Please sign in to comment.