Skip to content

Commit b8a7e6c

Browse files
committed
Ability to adjust ownership provided from container's host
1 parent 58966e1 commit b8a7e6c

5 files changed

Lines changed: 75 additions & 18 deletions

File tree

README.md

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
# CloudStack DEB Package builder using Docker
2+
23
Docker images for building Apache CloudStack DEB packages.
34

45
This will give portable, immutable and reproducable mechanism to build packages for releases. A very good candidate to be used by the Jenkins slaves of the project.
56

6-
# Table of Contents
7+
## Table of Contents
78

8-
- [Supported tags and respective Dockerfile links](https://github.com/khos2ow/cloudstack-deb-builder#supported-tags-and-respective-dockerfile-links)
9-
- [Packges installed in Conatiner](https://github.com/khos2ow/cloudstack-deb-builder#packges-installed-in-conatiner)
10-
- [Building packages](https://github.com/khos2ow/cloudstack-deb-builder#building-packages)
9+
- [Supported tags and respective `Dockerfile` links](https://github.com/khos2ow/cloudstack-deb-builder#supported-tags-and-respective-dockerfile-links)
10+
- [Packges installed in conatiner](https://github.com/khos2ow/cloudstack-deb-builder#packges-installed-in-conatiner)
11+
- [Build DEB packages](https://github.com/khos2ow/cloudstack-deb-builder#build-deb-packages)
1112
- [Clone Apache CloudStack source code](https://github.com/khos2ow/cloudstack-deb-builder#clone-apache-cloudstack-source-code)
12-
- [Pull Docker Images](https://github.com/khos2ow/cloudstack-deb-builder#pull-docker-images)
13-
- [Build Packages](https://github.com/khos2ow/cloudstack-deb-builder#build-packages)
14-
- [Maven Cache](https://github.com/khos2ow/cloudstack-deb-builder#maven-cache)
15-
- [Build Help](https://github.com/khos2ow/cloudstack-deb-builder#build-help)
13+
- [Pull Docker images](https://github.com/khos2ow/cloudstack-deb-builder#pull-docker-images)
14+
- [Build packages](https://github.com/khos2ow/cloudstack-deb-builder#build-packages)
15+
- [Building tips](https://github.com/khos2ow/cloudstack-deb-builder#building-tips)
16+
- [Maven cache](https://github.com/khos2ow/cloudstack-deb-builder#maven-cache)
17+
- [Adjust host owner permission](https://github.com/khos2ow/cloudstack-deb-builder#adjust-host-owner-permission)
18+
- [Builder help](https://github.com/khos2ow/cloudstack-deb-builder#builder-help)
19+
- [License](https://github.com/khos2ow/cloudstack-deb-builder#license)
20+
21+
## Supported tags and respective `Dockerfile` links
1622

17-
# Supported tags and respective Dockerfile links
1823
- [`latest`, `ubuntu1604` (ubuntu1604/Dockerfile)](https://github.com/khos2ow/cloudstack-deb-builder/blob/master/ubuntu1604/Dockerfile)
1924
- [`ubuntu1404` (ubuntu1404/Dockerfile)](https://github.com/khos2ow/cloudstack-deb-builder/blob/master/ubuntu1404/Dockerfile)
2025

21-
# Packges installed in Conatiner
26+
## Packges installed in conatiner
27+
2228
List of available packages inside the container:
2329

2430
- dpkg-dev
@@ -35,25 +41,29 @@ List of available packages inside the container:
3541
- locate
3642
- which
3743

38-
# Building packages
44+
## Build DEB packages
45+
3946
Building DEB packages with the Docker container is rather easy, a few steps are required:
4047

41-
## Clone Apache CloudStack source code
48+
### Clone Apache CloudStack source code
49+
4250
The first step required is to clone the CloudStack source code somewhere on the filesystem, in `/tmp` for example:
4351

4452
cd /tmp
4553
git clone https://github.com/apache/cloudstack.git cloudstack
4654

4755
Now that you have done so we can continue.
4856

49-
## Pull Docker Images
57+
### Pull Docker images
58+
5059
Let's assume we want to build packages for Ubuntu 16.04 (Xenial). We pull that image first:
5160

5261
docker pull khos2ow/cloudstack-deb-builder:ubuntu1604
5362

5463
You can replace `ubuntu1604` tag by `ubuntu1404` or `latest` if you want.
5564

56-
## Build Packages
65+
### Build packages
66+
5767
Now that we have the Docker images we can build packages by mapping `/tmp` into `/mnt/build` in the container. (Note that the container always expects the `cloudstack` code exists in `/mnt/build` path.)
5868

5969
docker run \
@@ -68,18 +78,39 @@ Or if your local cloudstack folder has other name, you need to map it to `/mnt/b
6878

6979
After the build has finished the *.deb* packages are available in */tmp/cloudstack/dist/debbuild/DEBS* on the host system.
7080

71-
## Maven Cache
81+
## Building tips
82+
83+
Check the following tips when using the builder:
84+
85+
### Maven cache
86+
7287
You can provide Maven cache folder (`~/.m2`) as a volume to the container to make it run faster.
7388

7489
docker run \
7590
-v /tmp:/mnt/build \
7691
-v ~/.m2:/root/.m2 \
7792
khos2ow/cloudstack-deb-builder:ubuntu1604 [ARGS...]
7893

79-
# Build Help
94+
### Adjust host owner permission
95+
96+
Builder container in some cases (e.g. using `--use-timestamp` flag) may change the file and directory owner shared from host to container (through volume) and it will create `dist` directory which holds the final artifacts. You can provide `USER_ID` (mandatory) and/or `USER_GID` (optional) from host to adjust the owner from whitin the container.
97+
98+
This is specially useful if you want to use this image in Jenkins job and want to clean up the workspace afterward. By adjusting the owner, you won't need to give your Jenkins' user `sudo` privilege to clean up.
99+
100+
docker run \
101+
-v /tmp:/mnt/build \
102+
-e "USER_ID=$(id -u)" \
103+
-e "USER_GID=$(id -g)" \
104+
khos2ow/cloudstack-deb-builder:ubuntu1604 [ARGS...]
105+
106+
## Builder help
107+
80108
To see all the available options you can pass to `docker run ...` command:
81109

82110
docker run \
83111
-v /tmp:/mnt/build \
84112
khos2ow/cloudstack-deb-builder:ubuntu1604 --help
85113

114+
## License
115+
116+
Licensed under [Apache License version 2.0](http://www.apache.org/licenses/LICENSE-2.0). Please see the [LICENSE](https://github.com/khos2ow/cloudstack-deb-builder/blob/master/LICENSE) file included in the root directory of the source tree for extended license details.

ubuntu1404/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
FROM ubuntu:14.04
19-
MAINTAINER Khosrow Moossavi <kmoossavi@cloudops.com>
19+
MAINTAINER Khosrow Moossavi <me@khosrow.io>
2020

2121
RUN apt-get update -y && \
2222
apt-get install -y --no-install-recommends software-properties-common && \

ubuntu1404/builder.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818

1919
set -e
2020

21+
# Adjust user and group provided by host
22+
adjust_owner() {
23+
# if both set then change the owner
24+
if [ -n "${USER_ID}" -a -z "${USER_GID}" ]; then
25+
chown -R ${USER_ID} /mnt/build/cloudstack
26+
elif [ -n "${USER_ID}" -a -n "${USER_GID}" ]; then
27+
chown -R ${USER_ID}:${USER_GID} /mnt/build/cloudstack
28+
fi
29+
}
30+
2131
if [ ! -d "/mnt/build/cloudstack" ]; then
2232
echo "Could not find directory 'cloudstack'"
2333
exit 1
@@ -36,7 +46,10 @@ if [ $? -eq 0 ]; then
3646

3747
cp /mnt/build/cloudstack-*.deb /mnt/build/cloudstack/dist/debbuild/DEBS
3848
cp /mnt/build/cloudstack_*.changes /mnt/build/cloudstack/dist/debbuild/DEBS
49+
50+
adjust_owner
3951
else
52+
adjust_owner
4053
echo "Packaging DEB failed"
4154
exit 1
4255
fi

ubuntu1604/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
FROM ubuntu:16.04
19-
MAINTAINER Khosrow Moossavi <kmoossavi@cloudops.com>
19+
MAINTAINER Khosrow Moossavi <me@khosrow.io>
2020

2121
RUN apt-get update -y && \
2222
apt-get install -y --no-install-recommends \

ubuntu1604/builder.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818

1919
set -e
2020

21+
# Adjust user and group provided by host
22+
adjust_owner() {
23+
# if both set then change the owner
24+
if [ -n "${USER_ID}" -a -z "${USER_GID}" ]; then
25+
chown -R ${USER_ID} /mnt/build/cloudstack
26+
elif [ -n "${USER_ID}" -a -n "${USER_GID}" ]; then
27+
chown -R ${USER_ID}:${USER_GID} /mnt/build/cloudstack
28+
fi
29+
}
30+
2131
if [ ! -d "/mnt/build/cloudstack" ]; then
2232
echo "Could not find directory 'cloudstack'"
2333
exit 1
@@ -36,7 +46,10 @@ if [ $? -eq 0 ]; then
3646

3747
cp /mnt/build/cloudstack-*.deb /mnt/build/cloudstack/dist/debbuild/DEBS
3848
cp /mnt/build/cloudstack_*.changes /mnt/build/cloudstack/dist/debbuild/DEBS
49+
50+
adjust_owner
3951
else
52+
adjust_owner
4053
echo "Packaging DEB failed"
4154
exit 1
4255
fi

0 commit comments

Comments
 (0)