Skip to content

Commit 1f5b83f

Browse files
committed
Refine the scripts to build a Docker image and to run such an image
1 parent fd138c2 commit 1f5b83f

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-9
lines changed

build.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,34 @@ version=0
1313
while [[ $# -gt 0 ]]; do
1414
key="$1"
1515
case $key in
16+
-h)
17+
echo "Usage: build.sh [-u USER_ID] [-g GROUP_ID] -v [SILVERPEAS_VERSION WILDFLY_VERSION]"
18+
echo "Build a Docker image from which a Docker container could be spawned to code and build"
19+
echo "within a compartmentalized environment some Silverpeas projects that can be shared "
20+
echo "between the container and the host."
21+
echo "with:"
22+
echo " -u USER_ID set the user identifier as USER_ID (it is recommended the USER_ID is"
23+
echo " your own user identifier in the host if the code source is shared"
24+
echo " between a Docker container and the host. By default 1000."
25+
echo " -g GROUP_ID set the group identifier as GROUP_ID (it is recommended the GROUP_ID is"
26+
echo " your own group identifier in the host if the code source is shared"
27+
echo " between a Docker container and the host. By default 1000."
28+
echo " -v SILVERPEAS_VERSION WILDFLY_VERSION"
29+
echo " set both the version of Silverpeas and of the Widfly distribution for"
30+
echo " which a docker container will be spawn to work on theses versions."
31+
echo " By default, the latest version in development of Silverpeas"
32+
exit 0
33+
;;
1634
-u)
1735
user="--build-arg USER_ID=$2"
1836
shift # past argument
1937
shift # past value
2038
;;
39+
-g)
40+
group="--build-arg GROUP_ID=$2"
41+
shift # past argument
42+
shift # past value
43+
;;
2144
-v)
2245
silverpeas_version="$2"
2346
wildfly_version="$3"
@@ -37,12 +60,12 @@ done
3760

3861
# build the Docker image for building some of the Silverpeas projects
3962
if [[ ${version} -eq 1 ]]; then
40-
docker build ${user} \
63+
docker build ${user} ${group} \
4164
--build-arg WILDFLY_VERSION=${wildfly_version} \
4265
-t silverpeas/silverdev:${silverpeas_version} \
4366
.
4467
else
45-
docker build ${user} \
68+
docker build ${user} ${group} \
4669
-t silverpeas/silverdev:latest \
4770
.
4871
fi

run.sh

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,62 @@ function die() {
55
exit 1
66
}
77

8-
if [[ $# -eq 1 ]]; then
9-
image_version=$1
10-
else
11-
image_version=latest
12-
fi
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]"
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 " -g 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+
exit 0
32+
;;
33+
-i)
34+
image_version="$2"
35+
shift # past argument
36+
shift # past value
37+
;;
38+
-w)
39+
working_dir="-v "$2":/home/silveruser/projects"
40+
shift # past argument
41+
shift # past value
42+
;;
43+
-n)
44+
name="$2"
45+
shift # past argument
46+
shift # past value
47+
;;
48+
*)
49+
die "Unknown option: $1"
50+
;;
51+
esac
52+
done
1353

1454
# run the silverpeas build image by linking the required volumes for signing and deploying built artifacts.
15-
docker run -it -v "$HOME"/.m2/settings.xml:/home/silveruser/.m2/settings.xml \
55+
if [[ -f "$HOME"/.m2/settings-docker.xml ]]; then
56+
settings="$HOME"/.m2/settings-docker.xml
57+
else
58+
settings="$HOME"/.m2/settings.xml
59+
fi
60+
docker run -it ${working_dir} -v "${settings}":/home/silveruser/.m2/settings.xml \
1661
-v "$HOME"/.m2/settings-security.xml:/home/silveruser/.m2/settings-security.xml \
1762
-v "$HOME"/.gitconfig:/home/silveruser/.gitconfig \
1863
-v "$HOME"/.ssh:/home/silveruser/.ssh \
1964
-v "$HOME"/.gnupg:/home/silveruser/.gnupg \
20-
--name silverdev-${image_version} \
65+
--name ${name} \
2166
silverpeas/silverdev:${image_version} /bin/bash

0 commit comments

Comments
 (0)