Skip to content

Commit

Permalink
Merge branch 'list_shutdown_errors' of github.com:doyleyoung/docker-m…
Browse files Browse the repository at this point in the history
…aven-plugin into list_shutdown_errors
  • Loading branch information
doyleyoung committed Mar 8, 2021
2 parents 43e6f76 + ef9801f commit 794271a
Show file tree
Hide file tree
Showing 34 changed files with 1,033 additions and 62 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Windows Build

on:
push:
branches:
- master
pull_request:

jobs:
build:
name: Windows Java ${{ matrix.java }} Maven
runs-on: windows-latest
strategy:
matrix:
java: [8, 11]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Build Project
run: mvn clean install
2 changes: 2 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* 0.34-SNAPSHOT
- Building 'spring-boot-with-jib' sample fails with NoSuchMethodError ([1384](https://github.com/fabric8io/docker-maven-plugin/issues/1384))
- Loading Image tarball into docker daemon fails in JIB mode ([1385](https://github.com/fabric8io/docker-maven-plugin/issues/1385))
- `assembly.inline` is removed when external properties are enabled ([1082](https://github.com/fabric8io/docker-maven-plugin/issues/1082))
- Fix Support for Podman REST API(when configured) Related to ([1330](https://github.com/fabric8io/docker-maven-plugin/issues/1330))

* **0.34.1** (2020-09-27)
- Fix NPE with "skipPush" and no build configuration given ([#1381](https://github.com/fabric8io/docker-maven-plugin/issues/1381))
Expand Down
11 changes: 6 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<surefire.version>3.0.0-M2</surefire.version>
<jib-core.version>0.15.0</jib-core.version>
<httpclient.version>4.5.10</httpclient.version>
<project.build.outputTimestamp>2020-11-14T11:57:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down Expand Up @@ -253,7 +254,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5</version>
<version>3.6.0</version>
<configuration>
<goalPrefix>docker</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
Expand Down Expand Up @@ -317,7 +318,7 @@
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.7.1</version>
<version>2.1.0</version>
<configuration>
<staticMetadataDirectory>${basedir}/target/filtered-resources/META-INF/plexus</staticMetadataDirectory>
</configuration>
Expand All @@ -336,12 +337,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<version>3.0.0-M1</version>
</plugin>

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<version>3.2.0</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
Expand All @@ -357,7 +358,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.0</version>
</plugin>

<plugin>
Expand Down
53 changes: 53 additions & 0 deletions samples/build-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## d-m-p sample utilizing docker build cache

This example shows:

1. How to use docker-maven-plugin together with [Spring Boot Layered JAR](https://spring.io/blog/2020/08/14/creating-efficient-docker-images-with-spring-boot-2-3) feature to utilize Docker build cache.
1. How to add files into the image with predefined permissions without [multi-stage build](https://docs.docker.com/develop/develop-images/multistage-build/).

It is a simple "Hello world" Spring Boot REST controller in the root context.

The [Dockerfile](image/src/main/docker/Dockerfile) is located in `image/src/main/docker`.

This example follows [reproducible builds](https://maven.apache.org/guides/mini/guide-reproducible-builds.html) approach
to generate archives which are friendly to the Docker build cache.

All content which needs to be added from the host into the image is packaged into archives of TAR format.
Content is separated based on the frequency of updates, so that changes in application code -
in [app/src/main/java/io/fabric8/dmp/samples/buildcache/Application.java](app/src/main/java/io/fabric8/dmp/samples/buildcache/Application.java) -
don't lead to modification of all archives, but impact just image/target/application.tar.

Generated archives are extracted inside image with `ADD` Dockefile directive adding the host content into the image with
desired UNIX file permissions, owner, group, creation and modification timestamps.

Dockerfile directives are ordered based on the frequency of updates, e.g. archive with application dependencies
(image/target/dependencies.tar) is added before archive with application code (image/target/application.tar) to avoid
creation of new image layer containing application dependencies (i.e. to take that layer from the Docker build cache)
when only application code changes.

When building the project multiple times, note that subsequent builds log "Using cache" messages, like:

```
$ mvn clean package
...
[INFO] DOCKER> Step 1 : FROM gcr.io/distroless/java-debian10
[INFO] DOCKER> ---> f6a5dc137f9b
[INFO] DOCKER> Step 2 : USER nonroot
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> 26d64b9907e3
[INFO] DOCKER> Step 3 : ENTRYPOINT
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> 6eb12980cd38
[INFO] DOCKER> Step 4 : WORKDIR "/app"
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> d6a408147d7c
[INFO] DOCKER> Step 5 : CMD tini -e 130 -e 143 -- java org.springframework.boot.loader.JarLauncher
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> 461505b7ade9
[INFO] DOCKER> Step 6 : ADD dependencies.tar /
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> df87a8d003f3
[INFO] DOCKER> Step 7 : ADD spring-boot-loader.tar /
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> 2de1bf3ac9ad
```
44 changes: 44 additions & 0 deletions samples/build-cache/app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>io.fabric8.dmp.samples.build-cache</groupId>
<artifactId>parent</artifactId>
<version>0.34-SNAPSHOT</version>
</parent>

<artifactId>app</artifactId>

<properties>
<!-- Avoid docker build cache invalidation due to new commits -->
<project.build.outputTimestamp>1970-01-01T00:00:00Z</project.build.outputTimestamp>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>io.fabric8.dmp.samples.buildcache.Application</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.fabric8.dmp.samples.buildcache;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class Application {

public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}

@RestController
public static class HelloController {

@RequestMapping("/")
public String greeting() {
return "Hello World!";
}
}
}

0 comments on commit 794271a

Please sign in to comment.