-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'list_shutdown_errors' of github.com:doyleyoung/docker-m…
…aven-plugin into list_shutdown_errors
- Loading branch information
Showing
34 changed files
with
1,033 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
23 changes: 23 additions & 0 deletions
23
samples/build-cache/app/src/main/java/io/fabric8/dmp/samples/buildcache/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} | ||
} | ||
} |
Oops, something went wrong.