Skip to content

Commit

Permalink
copy goal for copying files / directories from container to host.
Browse files Browse the repository at this point in the history
Signed-off-by: Marat Abrarov <[email protected]>
  • Loading branch information
mabrarov committed Mar 7, 2021
1 parent d0abca5 commit c5ff939
Show file tree
Hide file tree
Showing 42 changed files with 2,424 additions and 135 deletions.
84 changes: 84 additions & 0 deletions it/builder/app-image/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-builder-parent</artifactId>
<version>0.34-SNAPSHOT</version>
</parent>

<artifactId>dmp-it-builder-app-image</artifactId>
<packaging>pom</packaging>

<dependencies>
<dependency>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-builder-app</artifactId>
<type>tar.gz</type>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>build-context</id>
<phase>generate-resources</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>context</finalName>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptors>
<descriptor>src/assembly/context.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${app.image}</name>
<build>
<contextDir>${project.build.directory}/context</contextDir>
<filter>false</filter>
</build>
<run>
<wait>
<exit>0</exit>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>run</id>
<phase>integration-test</phase>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
26 changes: 26 additions & 0 deletions it/builder/app-image/src/assembly/context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>context</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>src/main/docker/Dockerfile</source>
<filtered>true</filtered>
<lineEnding>unix</lineEnding>
</file>
</files>
<dependencySets>
<dependencySet>
<outputDirectory/>
<includes>
<include>*:*:tar.gz</include>
</includes>
<useProjectArtifact>false</useProjectArtifact>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
</dependencySets>
</assembly>
5 changes: 5 additions & 0 deletions it/builder/app-image/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch

CMD ["/hello"]

ADD ["dmp-it-builder-app.tar.gz", "/"]
76 changes: 76 additions & 0 deletions it/builder/app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-builder-parent</artifactId>
<version>0.34-SNAPSHOT</version>
</parent>

<artifactId>dmp-it-builder-app</artifactId>
<packaging>pom</packaging>

<dependencies>
<dependency>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-builder-builder-image</artifactId>
<type>pom</type>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<executions>
<execution>
<id>copy-from-builder</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<images>
<image>
<name>${builder.image}</name>
<copy>
<entries>
<entry>
<containerPath>${builder.output.file}</containerPath>
<hostDirectory>${project.build.directory}</hostDirectory>
</entry>
</entries>
</copy>
</image>
</images>
<createContainers>true</createContainers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifact</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${builder.output.fileName}</file>
<type>tar.gz</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
2 changes: 2 additions & 0 deletions it/builder/builder-image/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build/
/.idea/
15 changes: 15 additions & 0 deletions it/builder/builder-image/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.0)

project(hello LANGUAGES C)

set(compile_definitions)
if(WIN32)
list(APPEND compile_definitions WIN32 _UNICODE UNICODE)
endif()

if(MINGW)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -municode")
endif()

add_executable(${PROJECT_NAME} "src/main/c/hello.c")
target_compile_definitions(${PROJECT_NAME} PRIVATE ${compile_definitions})
78 changes: 78 additions & 0 deletions it/builder/builder-image/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-builder-parent</artifactId>
<version>0.34-SNAPSHOT</version>
</parent>

<artifactId>dmp-it-builder-builder-image</artifactId>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>build-rootfs</id>
<phase>generate-resources</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>rootfs</finalName>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptors>
<descriptor>src/assembly/rootfs.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>build-context</id>
<phase>generate-resources</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>context</finalName>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptors>
<descriptor>src/assembly/context.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${builder.image}</name>
<build>
<contextDir>${project.build.directory}/context</contextDir>
<filter>false</filter>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
19 changes: 19 additions & 0 deletions it/builder/builder-image/src/assembly/context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>context</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>src/main/docker/Dockerfile</source>
<filtered>true</filtered>
<lineEnding>unix</lineEnding>
</file>
<file>
<source>${project.build.directory}/rootfs.tar</source>
</file>
</files>
</assembly>
21 changes: 21 additions & 0 deletions it/builder/builder-image/src/assembly/rootfs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>rootfs</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory/>
<directory>${project.basedir}</directory>
<includes>
<include>src/main/c/*.c</include>
<include>CMakeLists.txt</include>
<include>*.cmake</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
</fileSets>
</assembly>
19 changes: 19 additions & 0 deletions it/builder/builder-image/src/main/c/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if defined(WIN32)
#include <tchar.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

static const char *message = "Hello World!";

#if defined(WIN32)
int _tmain(int argc, _TCHAR **argv) {
#else
int main(int argc, char **argv) {
#endif
size_t len = strlen(message);
size_t written = fwrite(message, sizeof(char), len, stdout);
return written == len ? EXIT_SUCCESS : EXIT_FAILURE;
}
21 changes: 21 additions & 0 deletions it/builder/builder-image/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM alpine

RUN apk add --no-cache gcc libc-dev make cmake tar

ADD ["rootfs.tar", "/usr/src/hello"]

RUN output_file="@builder.output.file@" && \
source_dir="/usr/src/hello" && \
build_dir="$(mktemp -d)" && \
cmake \
-D CMAKE_SKIP_BUILD_RPATH=ON \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_USER_MAKE_RULES_OVERRIDE=static.cmake \
-S "${source_dir}" \
-B "${build_dir}" && \
cmake --build "${build_dir}" && \
mkdir -p "$(dirname "${output_file}")" && \
tar --sort=name --owner=root:0 --group=root:0 --mtime='UTC 1970-01-01' \
-C "${build_dir}" -czf "${output_file}" hello && \
rm -rf "${build_dir}" && \
echo "Built binaries location: ${output_file}"
12 changes: 12 additions & 0 deletions it/builder/builder-image/static.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Use CMAKE_USER_MAKE_RULES_OVERRIDE command line argument to point these rules

if(MSVC)
set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
elseif(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc")
endif()
Loading

0 comments on commit c5ff939

Please sign in to comment.