Re: [Xen-devel] [PATCH] scripts: add helper script to use Docker containers

2018-07-17 Thread Wei Liu
On Thu, Jul 12, 2018 at 08:53:06AM -0500, Doug Goldstein wrote:
> This adds a script that can be used to do builds easily within the
> defined containers under the automation directory. These containers live
> in the public GitLab registry under the xen-project namespace. The
> script can be executed a number of ways but the default is to drop you
> at a bash shell within a Debian Stretch container at the top level of
> the source tree.
> 
> Signed-off-by: Doug Goldstein 

I think there is no harm in committing this into xen.git and improve it
as needed, so:

Acked-by: Wei Liu 

I will wait until Friday for any objection to be raised.

Wei.

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH] scripts: add helper script to use Docker containers

2018-07-12 Thread Wei Liu
On Thu, Jul 12, 2018 at 08:53:06AM -0500, Doug Goldstein wrote:
> This adds a script that can be used to do builds easily within the
> defined containers under the automation directory. These containers live
> in the public GitLab registry under the xen-project namespace. The
> script can be executed a number of ways but the default is to drop you
> at a bash shell within a Debian Stretch container at the top level of
> the source tree.
> 
> Signed-off-by: Doug Goldstein 
> ---
> A few folks have asked about this so I'm CCing folks directly. I'm
> completely game for changing anything that makes this easier for folks
> to use. This is primarily geared as a developer/maintainer tool but
> its also good for folks just starting out with Xen and not having
> all the dependencies installed.

+1 to this.

I have found this script to be quite handy.

Wei.

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

[Xen-devel] [PATCH] scripts: add helper script to use Docker containers

2018-07-12 Thread Doug Goldstein
This adds a script that can be used to do builds easily within the
defined containers under the automation directory. These containers live
in the public GitLab registry under the xen-project namespace. The
script can be executed a number of ways but the default is to drop you
at a bash shell within a Debian Stretch container at the top level of
the source tree.

Signed-off-by: Doug Goldstein 
---
A few folks have asked about this so I'm CCing folks directly. I'm
completely game for changing anything that makes this easier for folks
to use. This is primarily geared as a developer/maintainer tool but
its also good for folks just starting out with Xen and not having
all the dependencies installed.

CC: Andrew Cooper 
CC: George Dunlap 
CC: Ian Jackson 
CC: Stefano Stabellini 
CC: Wei Liu 
---
 automation/build/README.md  | 53 ---
 automation/scripts/containerize | 93 ++-
 2 files changed, 138 insertions(+), 8 deletions(-)
 create mode 100755 automation/scripts/containerize

diff --git a/automation/build/README.md b/automation/build/README.md
index 0206d57..be4526c 100644
--- a/automation/build/README.md
+++ b/automation/build/README.md
@@ -5,9 +5,12 @@ These Docker containers should make it possible to build Xen in
 any of the available environments on any system that supports
 running Docker. They are organized by distro and tagged with
 the version of that distro. They are available from the GitLab
-Container Registry under the Xen project at:
+Container Registry under the Xen project at the [registry] and
+can be pulled with Docker from the following path:
 
-registry.gitlab.com/xen-project/xen/DISTRO:VERSION
+```
+docker pull registry.gitlab.com/xen-project/xen/DISTRO:VERSION
+```
 
 To see the list of available containers run `make` in this
 directory. You will have to replace the `/` with a `:` to use
@@ -19,16 +22,50 @@ Building Xen
 From the top level of the source tree it should be possible to
 run the following:
 
-docker run --rm -it -v $(PWD):/build -u $(id -u) -e CC=gcc $(CONTAINER) make
+```
+./automation/scripts/containerize make
+```
 
-There are other modifications that can be made but this will run
-the `make` command inside the specified container. It will use your
-currently checked out source tree to build with, ensure that file
-permissions remain consistent and clean up after itself.
+Which will cause the top level `make` to execute within the default
+container, which is currently defined as Debian Stretch. Any arguments
+specified to the script will be executed within the container from
+the default shell.
+
+There are several environment variables which the containerize script
+understands.
+
+- CONTAINER: This overrides the container to use. For CentOS 7.2, use:
+
+  ```
+  CONTAINER=centos72 ./automation/scripts/containerize make
+  ```
+
+- WORKDIR: This overrides the path that will be available under the
+  `/build` directory in the container, which is the default path.
+
+  ```
+  WORKDIR=/some/other/path ./automation/scripts/containerize ls
+  ```
+
+- XEN_CONFIG_EXPERT: If this is defined in your shell it will be
+  automatically passed through to the container.
+
+- CONTAINER_NAME: By default the container name is set based on the
+  container itself so that its easy to attach other terminals to your
+  container. This however prevents you from running multiple containers
+  of the same version. Override the name value to cause it to name
+  the container differently on start.
+
+- EXTRA_CONTAINER_ARGS: Allows you to pass extra arguments to Docker
+  when starting the container.
 
 Building a container
 
 
 There is a makefile to make this process easier. You should be
 able to run `make DISTRO/VERSION` to have Docker build the container
-for you.
+for you. If you define the `PUSH` environment variable when running the
+former `make` command, it will push the container to the [registry] if
+you have access to do so.
+
+[registry]: https://gitlab.com/xen-project/xen/container_registry
diff --git a/automation/scripts/containerize b/automation/scripts/containerize
new file mode 100755
index 000..7253617
--- /dev/null
+++ b/automation/scripts/containerize
@@ -0,0 +1,93 @@
+#!/bin/bash
+
+einfo() {
+   echo "$*" >&2
+}
+
+die() {
+echo "$*" >&2
+exit 1
+}
+
+#
+# The caller is expected to override the CONTAINER environment
+# variable with the container they wish to launch.
+#
+BASE="registry.gitlab.com/xen-project/xen"
+case "_${CONTAINER}" in
+_centos72) CONTAINER="${BASE}/centos:7.2" ;;
+_trusty) CONTAINER="${BASE}/ubuntu:trusty" ;;
+_xenial) CONTAINER="${BASE}/ubuntu:xenial" ;;
+_jessie) CONTAINER="${BASE}/debian:jessie" ;;
+_stretch|_) CONTAINER="${BASE}/debian:stretch" ;;
+esac
+
+# get our container name and version
+containid=${CONTAINER%:*}
+containver=${CONTAINER#*:}
+
+# Save the commands for future use
+cmd=$@
+
+# If no command was specified, just drop us into