-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Docs for Copy Goal and Sample for File/Directory Copy #1
Add Docs for Copy Goal and Sample for File/Directory Copy #1
Conversation
samples/copy-from-container/pom.xml
Outdated
@@ -0,0 +1,89 @@ | |||
<project xmlns = "http://maven.apache.org/POM/4.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Project in "samples" directory use different formatting of this header:
<project xmlns = "http://maven.apache.org/POM/4.0.0" | |
<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</groupId> | |
<artifactId>dmp-sample-parent</artifactId> | |
<version>0.34-SNAPSHOT</version> | |
<relativePath>../pom.xml</relativePath> | |
</parent> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this file doesn't follow formatting of existing POMs from the "samples" directory, where 2 space indentation is used (while this file uses 3 spaces).
samples/copy-from-container/pom.xml
Outdated
<groupId>io.fabric8.dmp.samples</groupId> | ||
<artifactId>dmp-sample-parent</artifactId> | ||
<version>0.34-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"../pom.xm" is default value for relativePath
("http://maven.apache.org/POM/4.0.0" XML schema):
<xs:element name="relativePath" minOccurs="0" type="xs:string" default="../pom.xml">
<xs:annotation>
<xs:documentation source="version">4.0.0</xs:documentation>
<xs:documentation source="description">
The relative path of the parent <code>pom.xml</code> file within the check out.
The default value is <code>../pom.xml</code>.
...
</xs:documentation>
</xs:annotation>
</xs:element>
so I'd prefer to omit it. Unfortunately, it looks like all POMs in "samples" directory have this excessive item, so let's be consistence.
samples/copy-from-container/pom.xml
Outdated
<artifactId>dmp-sample-copy-from-container</artifactId> | ||
<profiles> | ||
<profile> | ||
<id>Copy-File</id> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the most of maven profiles of projects located in "sample" directory use lower-case names:
<id>Copy-File</id> | |
<id>copy-file</id> |
samples/copy-from-container/pom.xml
Outdated
<artifactId>docker-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy-from-container</id> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<id>copy-from-container</id> | |
<id>copy-file-from-container</id> |
samples/copy-from-container/pom.xml
Outdated
<configuration> | ||
<images> | ||
<image> | ||
<name>busybox:latest</name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can omit default tag:
<name>busybox:latest</name> | |
<name>busybox</name> |
samples/copy-from-container/pom.xml
Outdated
<entries> | ||
<entry> | ||
<containerPath>/etc/hosts</containerPath> | ||
<hostDirectory>/tmp/</hostDirectory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to cover in documentation that hostDirectory
can be relative path. In case hostDirectory
is not an absolute path (java.io.File#isAbsolute
) or is null
( is not defined), then it's considered relative path and the base directory for that relative path is the current project base directory (org.apache.maven.project.MavenProject#getBasedir
). null
or undefined hostDirectory
is treated like an empty string, i.e. leads to usage of base directory of maven project.
For these samples - to make them less OS specific and to avoid spoiling filesystem of host OS with results of build - I'd recommend to use project's build directory as value of hostDirectory
, like:
<hostDirectory>/tmp/</hostDirectory> | |
<hostDirectory>${project.build.directory}</hostDirectory> |
In another example we could use relative directory, like:
<hostDirectory>/tmp/</hostDirectory> | |
<hostDirectory>target</hostDirectory> |
samples/copy-from-container/pom.xml
Outdated
</build> | ||
</profile> | ||
<profile> | ||
<id>Copy-Directory</id> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<id>Copy-Directory</id> | |
<id>copy-directory</id> |
samples/copy-from-container/pom.xml
Outdated
<entries> | ||
<entry> | ||
<containerPath>/dev</containerPath> | ||
<hostDirectory>/tmp/</hostDirectory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<hostDirectory>/tmp/</hostDirectory> | |
<hostDirectory>target</hostDirectory> |
Thank you for your help. Here are my ideas / plans:
|
## How to Build? | ||
You can compile the project as usual maven command: | ||
``` | ||
mvn clean install |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need of using install
goal (spoiling local maven repository):
mvn clean install | |
mvn clean package |
samples/copy-from-container/pom.xml
Outdated
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>dmp-sample-copy-from-container</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use pom
packaging
<artifactId>dmp-sample-copy-from-container</artifactId> | |
<artifactId>dmp-sample-copy-from-container</artifactId> | |
<packaging>pom</packaging> |
to avoid warnings like:
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ dmp-sample-copy-from-container ---
[WARNING] JAR will be empty - no content was marked for inclusion!
## Copying File from Container to Local Host | ||
We have a `Copy-File` profile which copies `/etc/hosts` file from container to your `/tmp` directory. It has executions set up for `start`,`copy`,`stop` goals so they will be activated when you build using the specified profile. In order to run it, use this command: | ||
``` | ||
mvn clean install -PCopy-File |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mvn clean install -PCopy-File | |
$ mvn clean package -P copy-file |
``` | ||
Once command finishes successfully, try checking your `/tmp` directory to see file got created or not. If everything goes okay, you should be able to see output like this: | ||
``` | ||
copy-from-container : $ ls /tmp/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-from-container : $ ls /tmp/ | |
$ ls target | |
hosts | |
$ cat target/hosts |
``` | ||
mvn clean install -PCopy-File | ||
``` | ||
Once command finishes successfully, try checking your `/tmp` directory to see file got created or not. If everything goes okay, you should be able to see output like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once command finishes successfully, try checking your `/tmp` directory to see file got created or not. If everything goes okay, you should be able to see output like this: | |
Once command finishes successfully, try checking "target" directory to see if the file got created or not. If everything goes okay, you should be able to see output like this: |
samples/copy-from-container/pom.xml
Outdated
<id>copy-from-container</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>start</goal> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This profile could use <createContainers>true</createContainers>
, i.e. could demonstrate copying from temporary (created, but not started) container instead of copying from the started container (like it's done in Copy-File
profile).
ff02::2 ip6-allrouters | ||
172.17.0.3 80dd81263592 | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a note about usage of d-m-p external configuration, like:
Docker Maven Plugin external configuration can be used to define entries which need to be coped, e.g.:
$ mvn clean package -Pcopy-file \ -Ddocker.imagePropertyConfiguration=override \ -Ddocker.name=alpine \ -Ddocker.copy.entries.1.containerPath=/etc/os-release \ -Ddocker.copy.entries.1.hostDirectory=target \ -Ddocker.copy.entries.2.containerPath=/etc/hostname \ -Ddocker.copy.entries.2.hostDirectory=target ... $ ls target hostname os-release $ cat target/hostname f1387e0c6253 $ cat target/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.13.2 PRETTY_NAME="Alpine Linux v3.13" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://bugs.alpinelinux.org/"
@@ -0,0 +1,33 @@ | |||
[[docker:copy]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without changes in other files, like "src/main/asciidoc/index.adoc", this file doesn't look being picked and included into the generated documentation.
1bc02d8
to
107b715
Compare
``` | ||
|
||
## Copying Directory from Container to Local Host | ||
We have a `copy-directory` profile which copies `/dev` directory from container to your `/tmp` directory. It has `createContainers=true` with which plugin copies from a temporary(created, but not started) container instead of copying from the standard container. In order to run it, use this command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/tmp
directory is not used by this example anymore, does it?
107b715
to
7851a5c
Compare
Per requirements of d-m-p commits in PRs should be signed-off by the author. Could you please sign-off your commit(s) and update (force push) this PR? |
sure, let me do that. |
7851a5c
to
1192d5d
Compare
Once command finishes successfully, try checking your `target` directory to see file got created or not. If everything goes okay, you should be able to see output like this: | ||
``` | ||
copy-from-container : $ ls target | ||
dev hosts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hosts
file looks excessive, because clean
goal should remove it (if it is created by previous command - by mvn clean package -Pcopy-file
):
dev hosts | |
dev |
|
||
This is a plain maven application used to demonstrate how to copy files or directories from container using `docker:copy` goal | ||
|
||
## How to Build? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I don't see a need in this section, because package
does nothing for this sample. I'd omit it to reduce this README till essential part.
@@ -0,0 +1,64 @@ | |||
# Docker Maven Plugin Copy Sample | |||
|
|||
This is a plain maven application used to demonstrate how to copy files or directories from container using `docker:copy` goal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"maven application" -> "maven project"?
+ Added Docs for `docker:copy` + Added a `copy-from-container` sample which contains profiles for copying file and directory to localhost from container Signed-off-by: Rohan Kumar <[email protected]>
1192d5d
to
2dce16b
Compare
|
||
This is a plain maven project used to demonstrate how to copy files or directories from container using `docker:copy` goal | ||
|
||
## Copying File from Container to Local Host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if d-m-p has any standard for Markdown formatting, but I appreciate if we could use the following rules:
- Keep one empty line before bock of code (if it's not the first line of file).
- Keep one empty line before (if it's not the first line of file) and after each header.
- File ends with one empty line.
## Copying File from Container to Local Host | |
## Copying File from Container to Local Host | |
We have a `copy-file` profile which copies `/etc/hosts` file from container to your project build directory. | |
It has executions set up for `start`, `copy` and `stop` goals, so they will be activated when you build using the specified profile. | |
In order to run it, use this command: | |
``` | |
$ mvn clean package -Pcopy-file | |
``` | |
Once command finishes successfully, try checking your `target` directory to see if the file got created or not. | |
If everything goes okay, you should be able to see output like this: | |
``` | |
$ ls target | |
hosts | |
$ cat target/hosts | |
127.0.0.1 localhost | |
::1 localhost ip6-localhost ip6-loopback | |
fe00::0 ip6-localnet | |
ff00::0 ip6-mcastprefix | |
ff02::1 ip6-allnodes | |
ff02::2 ip6-allrouters | |
172.17.0.3 80dd81263592 | |
``` | |
Docker Maven Plugin external configuration can be used to define entries which need to be coped, e.g.: | |
``` | |
$ mvn clean package -Pcopy-file \ | |
-Ddocker.imagePropertyConfiguration=override \ | |
-Ddocker.name=alpine \ | |
-Ddocker.copy.entries.1.containerPath=/etc/os-release \ | |
-Ddocker.copy.entries.1.hostDirectory=target \ | |
-Ddocker.copy.entries.2.containerPath=/etc/hostname \ | |
-Ddocker.copy.entries.2.hostDirectory=target | |
... | |
$ ls target | |
hostname os-release | |
$ cat target/hostname | |
f1387e0c6253 | |
$ cat target/os-release | |
NAME="Alpine Linux" | |
ID=alpine | |
VERSION_ID=3.13.2 | |
PRETTY_NAME="Alpine Linux v3.13" | |
HOME_URL="https://alpinelinux.org/" | |
BUG_REPORT_URL="https://bugs.alpinelinux.org/" | |
``` | |
## Copying Directory from Container to Local Host | |
We have a `copy-directory` profile which copies `/dev` directory from container to your `target` directory. | |
It has `createContainers=true` with which plugin copies from a temporary (created, but not started) container instead of copying from the standard container (e.g. created and started by `start` goal). | |
In order to run it, use this command: | |
... |
This is a plain maven project used to demonstrate how to copy files or directories from container using `docker:copy` goal | ||
|
||
## Copying File from Container to Local Host | ||
We have a `copy-file` profile which copies `/etc/hosts` file from container to your project build directory. It has executions set up for `start`,`copy`,`stop` goals so they will be activated when you build using the specified profile. In order to run it, use this command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a `copy-file` profile which copies `/etc/hosts` file from container to your project build directory. It has executions set up for `start`,`copy`,`stop` goals so they will be activated when you build using the specified profile. In order to run it, use this command: | |
We have a `copy-file` profile which copies `/etc/hosts` file from container to your project build directory. | |
It has executions set up for `start`, `copy` and `stop` goals, so they will be activated when you build using the specified profile. | |
In order to run it, use this command: |
``` | ||
|
||
## Copying Directory from Container to Local Host | ||
We have a `copy-directory` profile which copies `/dev` directory from container to your `target` directory. It has `createContainers=true` with which plugin copies from a temporary(created, but not started) container instead of copying from the standard container. In order to run it, use this command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a `copy-directory` profile which copies `/dev` directory from container to your `target` directory. It has `createContainers=true` with which plugin copies from a temporary(created, but not started) container instead of copying from the standard container. In order to run it, use this command: | |
We have a `copy-directory` profile which copies `/dev` directory from container to your `target` directory. | |
It has `createContainers=true` with which plugin copies from a temporary (created, but not started) container instead of copying from the standard container (e.g. created and started by `start` goal). | |
In order to run it, use this command: |
@@ -0,0 +1,87 @@ | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that we need to add copy-from-container
module into "samples/pom.xml" POM (into the modules
section), don't we?
I'm going to merge this PR into |
oh, Sorry I was busy with work so couldn't update your recent comments. Shall I address your comments or do you plan to fix them yourself? I'm okay with whatever way you prefer. |
I plan to fix them myself. |
ohk, I guess you can merge it then |
docker:copy
copy-from-container
sample which contains profiles forcopying file and directory to localhost from container