Skip to content

Commit 3eddec8

Browse files
committed
Add a script to run a container from an image created by a container
commit. The image has to be named silverpeas-template.
1 parent fb07c4e commit 3eddec8

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

run-template.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
3+
function die() {
4+
echo "Error: $1"
5+
exit 1
6+
}
7+
8+
image_version=latest
9+
name="silverdev-${image_version}"
10+
while [[ $# -gt 0 ]]; do
11+
key="$1"
12+
case $key in
13+
-h)
14+
echo "Usage: run.sh [-i IMAGE_VERSION] [-w WORKING_DIR] [-n NAME] [-s]"
15+
echo "Spawns and runs a container from the Docker image silverpeas/silverdev at a given version."
16+
echo "In order to build the projects in that container, the working directory of your projects"
17+
echo "will be mounted in the container. It checks if a Maven settings settings-docker.xml exist"
18+
echo "in order to use it in the container. Otherwise, it is your settings.xml that will be used."
19+
echo "The following files or directories will be also used in the container: "
20+
echo " - The Maven security configuration settings-security.xml"
21+
echo " - The Git configuration .gitconfig"
22+
echo " - The ssh configuration directory .ssh"
23+
echo " - The GPG configuration directory .gnupg"
24+
echo ""
25+
echo "with:"
26+
echo " -i IMAGE_VERSION the version of the Docker image to instantiate. By default latest."
27+
echo " -w WORKING_DIR the path of your working directory to mount The working directory"
28+
echo " will be mounted to /home/silveruser/projects. By default nothing to"
29+
echo " mount."
30+
echo " -n NAME a name to give to the container. By default silverdev-IMAGE_VERSION."
31+
echo " -s to share the local Maven repository of the host with the container."
32+
exit 0
33+
;;
34+
-i)
35+
image_version="$2"
36+
shift # past argument
37+
shift # past value
38+
;;
39+
-w)
40+
working_dir="-v "$2":/home/silveruser/projects"
41+
shift # past argument
42+
shift # past value
43+
;;
44+
-n)
45+
name="$2"
46+
shift # past argument
47+
shift # past value
48+
;;
49+
-s)
50+
maven_repo="-v ${HOME}/.m2/repository:/home/silveruser/.m2/repository"
51+
shift # past argument
52+
;;
53+
*)
54+
die "Unknown option: $1"
55+
;;
56+
esac
57+
done
58+
59+
# run the silverpeas build image by linking the required volumes for signing and deploying built artifacts.
60+
if [[ -f "$HOME"/.m2/settings-docker.xml ]]; then
61+
settings="$HOME"/.m2/settings-docker.xml
62+
else
63+
settings="$HOME"/.m2/settings.xml
64+
fi
65+
66+
#xhost +si:localuser:$USER
67+
docker run -it -e DISPLAY=${DISPLAY} ${working_dir} ${maven_repo} \
68+
-v /tmp/.X11-unix:/tmp/.X11-unix \
69+
-v "${settings}":/home/silveruser/.m2/settings.xml \
70+
-v "$HOME"/.m2/settings-security.xml:/home/silveruser/.m2/settings-security.xml \
71+
-v "$HOME"/.gitconfig:/home/silveruser/.gitconfig \
72+
-v "$HOME"/.ssh:/home/silveruser/.ssh \
73+
-v "$HOME"/.gnupg:/home/silveruser/.gnupg \
74+
--name ${name} \
75+
silverdev-template:${image_version} /bin/bash

0 commit comments

Comments
 (0)