Skip to content

Commit a62f9fc

Browse files
authored
Add Ubuntu 18.04 image (#9)
* Add Ubuntu 18.04 image * Add ubuntu1804 to Travis, Makefile and README * Set ubuntu1804 as 'latest' * Add `--workspace-path` flag to ubuntu1804
1 parent da93096 commit a62f9fc

File tree

5 files changed

+332
-5
lines changed

5 files changed

+332
-5
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ env:
3737
matrix:
3838
- TAG="ubuntu1404" PARAMS=""
3939
- TAG="ubuntu1604" PARAMS=""
40+
- TAG="ubuntu1804" PARAMS=""
4041
- TAG="latest" PARAMS=""
4142

4243
install: make ${TAG}

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
.PHONY: all ubuntu1404 ubuntu1604 latest
18+
.PHONY: all ubuntu1404 ubuntu1604 ubuntu1804 latest
1919

2020
# Build docker tag based on provided info
2121
#
@@ -25,13 +25,16 @@ define build_tag
2525
docker build -t khos2ow/cloudstack-deb-builder:$(1) $(2)
2626
endef
2727

28-
all: ubuntu1404 ubuntu1604 latest
28+
all: ubuntu1404 ubuntu1604 ubuntu1804 latest
2929

3030
ubuntu1404:
3131
$(call build_tag,ubuntu1404,ubuntu1404)
3232

3333
ubuntu1604:
3434
$(call build_tag,ubuntu1604,ubuntu1604)
3535

36+
ubuntu1804:
37+
$(call build_tag,ubuntu1804,ubuntu1804)
38+
3639
latest:
37-
$(call build_tag,latest,ubuntu1604)
40+
$(call build_tag,latest,ubuntu1804)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ This will give portable, immutable and reproducable mechanism to build packages
2828

2929
## Supported tags and respective `Dockerfile` links
3030

31-
- [`latest`, `ubuntu1604` (ubuntu1604/Dockerfile)](https://github.com/khos2ow/cloudstack-deb-builder/blob/master/ubuntu1604/Dockerfile)
31+
- [`latest`, `ubuntu1804` (ubuntu1804/Dockerfile)](https://github.com/khos2ow/cloudstack-deb-builder/blob/master/ubuntu1804/Dockerfile)
32+
- [`ubuntu1604` (ubuntu1604/Dockerfile)](https://github.com/khos2ow/cloudstack-deb-builder/blob/master/ubuntu1604/Dockerfile)
3233
- [`ubuntu1404` (ubuntu1404/Dockerfile)](https://github.com/khos2ow/cloudstack-deb-builder/blob/master/ubuntu1404/Dockerfile)
3334

3435
## Packges installed in conatiner
@@ -59,7 +60,7 @@ Let's assume we want to build packages for Ubuntu 16.04 (Xenial). We pull that i
5960

6061
docker pull khos2ow/cloudstack-deb-builder:ubuntu1604
6162

62-
You can replace `ubuntu1604` tag by `ubuntu1404` or `latest` if you want.
63+
You can replace `ubuntu1604` tag by `ubuntu1804`, `ubuntu1404` or `latest` if you want.
6364

6465
### Build local repository
6566

ubuntu1804/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
FROM ubuntu:18.04
19+
LABEL maintainer="Khosrow Moossavi <me@khosrow.io> (@khos2ow)"
20+
21+
RUN apt-get update -y && \
22+
apt-get install -y --no-install-recommends \
23+
make \
24+
locate \
25+
tar \
26+
lsb-release \
27+
build-essential \
28+
dpkg-dev \
29+
devscripts \
30+
debhelper \
31+
genisoimage \
32+
git \
33+
maven \
34+
openjdk-8-jdk \
35+
python \
36+
python-mysqldb \
37+
python-mysql.connector \
38+
dh-systemd \
39+
python-setuptools && \
40+
apt-get clean && \
41+
rm -rf /var/lib/apt/lists/* && \
42+
update-java-alternatives -s java-1.8.0-openjdk-amd64
43+
44+
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
45+
46+
VOLUME /mnt/build
47+
WORKDIR /mnt/build
48+
49+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
50+
ENTRYPOINT ["docker-entrypoint.sh"]

ubuntu1804/docker-entrypoint.sh

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
set -e
20+
21+
# Flag to show help text
22+
show_help=false
23+
24+
# Workspace path
25+
workspace_path=""
26+
27+
# Using remote git repository variables
28+
use_remote=false
29+
git_remote=""
30+
git_ref=""
31+
remove_first=false
32+
33+
# packaging flags to be sent to script
34+
PKG_ARGS=""
35+
HELP_ARG=""
36+
37+
while [ -n "$1" ]; do
38+
case "$1" in
39+
--git-remote)
40+
if [ -n "$git_remote" ]; then
41+
echo "Error: you have already entered value for --git-remote"
42+
exit 1
43+
else
44+
git_remote=$2
45+
use_remote=true
46+
shift 2
47+
fi
48+
;;
49+
50+
--git-ref)
51+
if [ -n "$git_ref" ]; then
52+
echo "Error: you have already entered value for --git-ref"
53+
exit 1
54+
else
55+
git_ref=$2
56+
use_remote=true
57+
shift 2
58+
fi
59+
;;
60+
61+
--remove-first)
62+
if [ $remove_first = true ]; then
63+
echo "Error: you have already entered --remove_first"
64+
exit 1
65+
else
66+
remove_first=true
67+
shift 1
68+
fi
69+
;;
70+
71+
--workspace-path)
72+
if [ -n "$workspace_path" ]; then
73+
echo "Error: you have already entered value for --workspace-path"
74+
exit 1
75+
else
76+
workspace_path=$2
77+
shift 2
78+
fi
79+
;;
80+
81+
-h | --help)
82+
if [ $show_help = true ]; then
83+
echo "Error: you have already entered -h, --help"
84+
exit 1
85+
else
86+
show_help=true
87+
HELP_ARG="$1"
88+
shift 1
89+
fi
90+
;;
91+
92+
-* | --* | *)
93+
PKG_ARGS="$PKG_ARGS $1"
94+
shift 1
95+
;;
96+
esac
97+
done
98+
99+
set -- $PKG_ARGS
100+
101+
# use '/mnt/build/cloudstack' as default workspace path
102+
if [ -z "$workspace_path" ]; then
103+
workspace_path="/mnt/build/cloudstack"
104+
fi
105+
106+
# Both of --git-remote AND --git-ref must be specified at the same time
107+
if [ $use_remote = true ]; then
108+
if [ -z "$git_remote" -o -z "$git_ref" ]; then
109+
echo "Error: you must specify --git-remote and --git-ref at the same time"
110+
exit 1
111+
fi
112+
fi
113+
114+
# Check if cloudstack directory exists or not. Options are either:
115+
#
116+
# 1) cloudstack directory is provided through the host's volume
117+
# 2) cloudstack directory is NOT provided and git remote and ref are provided
118+
#
119+
# Any combination of the above situations is invalid.
120+
if [ -d "${workspace_path}" ]; then
121+
if [ $use_remote = true ]; then
122+
if [ $remove_first = false ]; then
123+
echo "Error: Could not clone remote git repository, '${workspace_path}' exists"
124+
exit 1
125+
else
126+
echo "Removing ${workspace_path} ..."
127+
rm -rf ${workspace_path}
128+
echo -e "\n--------\n"
129+
fi
130+
fi
131+
else
132+
if [ $use_remote = false ]; then
133+
echo "Could not find '${workspace_path}'"
134+
exit 1
135+
fi
136+
fi
137+
138+
# Print out some environment information
139+
echo -e "System information:"
140+
cat /etc/*-release
141+
142+
echo -e "\nGit version:"
143+
git --version
144+
145+
echo -e "\nJava version:"
146+
java -version
147+
148+
echo -e "\nMaven version:"
149+
mvn --version
150+
151+
echo -e "\nPython version:"
152+
python --version
153+
154+
echo -e "\ndpkg version:"
155+
dpkg --version
156+
157+
echo -e "\ndevscripts version:"
158+
dpkg -s devscripts | grep "Version:" | awk '{print $2}'
159+
160+
echo -e "\ndebhelper version:"
161+
dpkg -s debhelper | grep "Version:" | awk '{print $2}'
162+
163+
echo -e "\ngenisoimage version:"
164+
genisoimage --version
165+
166+
echo -e "\nlsb-release version:"
167+
dpkg -s lsb-release | grep "Version:" | awk '{print $2}'
168+
169+
echo -e "\nbuild-essential version:"
170+
dpkg -s build-essential | grep "Version:" | awk '{print $2}'
171+
172+
echo -e "\n--------\n"
173+
174+
# Clone the remote provided git repo and ref
175+
if [ $use_remote = true ]; then
176+
echo "Cloning $git_remote ..."
177+
git clone --quiet --depth=50 $git_remote ${workspace_path}
178+
179+
cd ${workspace_path}
180+
181+
echo "Fetching $git_ref ..."
182+
git fetch --quiet origin +$git_ref:
183+
184+
echo "Checking out $git_ref ..."
185+
git checkout --quiet --force FETCH_HEAD
186+
187+
echo -e "\n--------\n"
188+
fi
189+
190+
# Make sure build-deb.sh script exists before going any further
191+
if [ ! -f "${workspace_path}/packaging/build-deb.sh" ]; then
192+
echo "Could not find '${workspace_path}/packaging/build-deb.sh'"
193+
exit 1
194+
fi
195+
196+
# convert LONG flags to SHORT flags for anything prior 4.12.x.x
197+
echo "Detecting CloudStack version ..."
198+
pom_version=$(cd ${workspace_path}; mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
199+
echo "${pom_version}"
200+
major_version=$(echo ${pom_version} | cut -d. -f1)
201+
minor_version=$(echo ${pom_version} | cut -d. -f2)
202+
echo -e "\n--------\n"
203+
204+
if [ $major_version -lt 4 ] || [ $major_version -eq 4 -a $minor_version -lt 12 ]; then
205+
if [ $show_help = true ]; then
206+
HELP_ARG=""
207+
fi
208+
fi
209+
210+
# Show help, both from docker-entrypoint.sh and ${workspace_path}/packaging/build-deb.sh
211+
if [ $show_help = true ]; then
212+
if [ -n "$HELP_ARG" ]; then
213+
help=$(cd ${workspace_path}/packaging; bash -x ./build-deb.sh $HELP_ARG)
214+
else
215+
help=""
216+
fi
217+
cat << USAGE
218+
Usage: docker run ... khos2ow/cloudstack-deb-builder [DOCKER_OPTIONS] ... [PACKAGING_OPTIONS]...
219+
CloudStack DEB builder which acts as a wrapper for CloudStack package script. Optionally
220+
you can specify remote git repository and ref to be cloned and checked out and run the
221+
packaging script on in.
222+
223+
Optional arguments:
224+
--git-remote string Set the git remote repository to clone (must be set together with \`--git-ref\`) (default: none)
225+
--git-ref string Set the ref from remote repository to check out (must be set together with \`--git-remote\`) (default: none)
226+
--remove-first Remove existing \`${workspace_path}\` directory before cloning (default: false)
227+
--workspace-path string Set the directory path of workspace to work with (default: \`/mnt/build/cloudstack\`)
228+
229+
Other arguments:
230+
-h, --help Display this help message and exit
231+
232+
Examples:
233+
docker run ... khos2ow/cloudstack-deb-builder [PACKAGING_OPTIONS] ...
234+
docker run ... khos2ow/cloudstack-deb-builder --git-remote https://path.to.repo/cloudstack.git --git-ref foo-branch [PACKAGING_OPTIONS] ...
235+
236+
--------
237+
238+
$help
239+
240+
USAGE
241+
exit 0
242+
fi
243+
244+
# Adjust user and group provided by host
245+
function adjust_owner() {
246+
# if both set then change the owner
247+
if [ -n "${USER_ID}" -a -z "${USER_GID}" ]; then
248+
chown -R ${USER_ID} ${workspace_path}
249+
elif [ -n "${USER_ID}" -a -n "${USER_GID}" ]; then
250+
chown -R ${USER_ID}:${USER_GID} ${workspace_path}
251+
fi
252+
}
253+
254+
{
255+
cd ${workspace_path}/packaging
256+
257+
# do the packaging
258+
bash -x ./build-deb.sh $@ && {
259+
mkdir -p ${workspace_path}/dist/debbuild/DEBS
260+
261+
cp ${workspace_path}/../cloudstack-*.deb ${workspace_path}/dist/debbuild/DEBS
262+
cp ${workspace_path}/../cloudstack_*.changes ${workspace_path}/dist/debbuild/DEBS
263+
264+
adjust_owner
265+
}
266+
} || {
267+
status=$?
268+
269+
adjust_owner
270+
echo "Packaging DEB failed"
271+
exit $status
272+
}

0 commit comments

Comments
 (0)