Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted fixes #29

Merged
merged 7 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Dockerfile-7.x
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.

# Set up the builder user
RUN bash -c ' \
OPTS=(); \
if [ -n "${CUSTOM_BUILDER_UID}" ]; then \
if [ -z "${CUSTOM_BUILDER_GID}" ]; then \
export CUSTOM_BUILDER_GID="${CUSTOM_BUILDER_UID}"; \
fi; \
if ! egrep -q "^.*:.:${CUSTOM_BUILDER_GID}:"; then \
OPTS+=("-u" "${CUSTOM_BUILDER_UID}"); \
fi; \
if [ -n "${CUSTOM_BUILDER_GID}" ]; then \
OPTS+=("-g" "${CUSTOM_BUILDER_GID}"); \
if ! getent group "${CUSTOM_BUILDER_GID}" >/dev/null; then \
groupadd -g "${CUSTOM_BUILDER_GID}" builder; \
fi; \
useradd -u "${CUSTOM_BUILDER_UID}" -g "${CUSTOM_BUILDER_GID}" builder; \
else \
useradd builder; \
fi; \
useradd "${OPTS[@]}" builder; \
' \
&& echo "builder:builder" | chpasswd \
&& echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers \
Expand Down
14 changes: 7 additions & 7 deletions Dockerfile-8.x
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ RUN sed -i "/gpgkey/a exclude=ocaml*" /etc/yum.repos.d/Cent* /etc/yum.repos.

# Set up the builder user
RUN bash -c ' \
OPTS=(); \
if [ -n "${CUSTOM_BUILDER_UID}" ]; then \
if [ -z "${CUSTOM_BUILDER_GID}" ]; then \
export CUSTOM_BUILDER_GID="${CUSTOM_BUILDER_UID}"; \
fi; \
if ! egrep -q "^.*:.:${CUSTOM_BUILDER_GID}:"; then \
OPTS+=("-u" "${CUSTOM_BUILDER_UID}"); \
fi; \
if [ -n "${CUSTOM_BUILDER_GID}" ]; then \
OPTS+=("-g" "${CUSTOM_BUILDER_GID}"); \
if ! getent group "${CUSTOM_BUILDER_GID}" >/dev/null; then \
groupadd -g "${CUSTOM_BUILDER_GID}" builder; \
fi; \
useradd -u "${CUSTOM_BUILDER_UID}" -g "${CUSTOM_BUILDER_GID}" builder; \
else \
useradd builder; \
fi; \
useradd "${OPTS[@]}" builder; \
' \
&& echo "builder:builder" | chpasswd \
&& echo "builder ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
Expand Down
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ make
```

## Mounting external directories into the container

If you'd like to develop using the tools on your host and preserve the changes
to source and revision control but still use the container for building, you
can do using by using a docker volume.
Expand All @@ -156,15 +157,5 @@ example, if I clone some repos into a directory on my host, say `/work/code/`,
then I can mount it inside the container as follows:

```sh
docker run -i -t -v /work/code:/mnt/repos -u builder <IMAGE> /bin/bash
```

The `-u` flag uses the right UID inside so that changes made in the container
are with the same UID as outside the container. Docker >=1.6 supports group IDs
as well and both the group and user can be referenced by name.

Then the following format is available to set the UID/GID:

```sh
-u, --user= Username or UID (format: <name|uid>[:<group|gid>])
./run.py -b 8.0 -v /work/code:/mnt/repos
```
40 changes: 20 additions & 20 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ cd $(dirname "$0")

CUSTOM_ARGS=()

MAJOR=${1:0:1}

RE_ISNUM='^[0-9]$'
if ! [[ ${MAJOR} =~ ${RE_ISNUM} ]]; then
echo "[WARNING] The first character of version should be a number: '${MAJOR}' was passed:"
exit 1
fi

if [ ${MAJOR} -eq 7 ]; then
REPO_FILE=files/xcp-ng.repo.7.x.in
CENTOS_VERSION=7.2.1511
else
REPO_FILE=files/xcp-ng.repo.8.x.in
CENTOS_VERSION=7.5.1804
fi
case "$1" in
7.*)
REPO_FILE=files/xcp-ng.repo.7.x.in
DOCKERFILE=Dockerfile-7.x
CENTOS_VERSION=7.2.1511
;;
8.*)
REPO_FILE=files/xcp-ng.repo.8.x.in
DOCKERFILE=Dockerfile-8.x
CENTOS_VERSION=7.5.1804
;;
*)
echo >&2 "Unsupported release '$1'"
exit 1
;;
esac

sed -e "s/@XCP_NG_BRANCH@/${1}/g" "$REPO_FILE" > files/tmp-xcp-ng.repo
sed -e "s/@CENTOS_VERSION@/${CENTOS_VERSION}/g" files/CentOS-Vault.repo.in > files/tmp-CentOS-Vault.repo

# Support using docker on arm64, building
# for amd64 (e.g. Apple Silicon)
if [ "$(uname -m)" == "arm64" ]; then
# Support using docker on other archs (e.g. arm64 for Apple Silicon), building for amd64
if [ "$(uname -m)" != "x86_64" ]; then
CUSTOM_ARGS+=( "--platform" "linux/amd64" )
fi

Expand All @@ -57,10 +57,10 @@ CUSTOM_ARGS+=( "--build-arg" "CUSTOM_BUILDER_UID=${CUSTOM_UID}" )
CUSTOM_ARGS+=( "--build-arg" "CUSTOM_BUILDER_GID=${CUSTOM_GID}" )

docker build \
$(echo "${CUSTOM_ARGS[@]}") \
"${CUSTOM_ARGS[@]}" \
-t xcp-ng/xcp-ng-build-env:${1} \
--ulimit nofile=1024 \
-f Dockerfile-${MAJOR}.x .
-f $DOCKERFILE .

rm -f files/tmp-xcp-ng.repo
rm -f files/tmp-CentOS-Vault.repo
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def main():
args = parser.parse_args(sys.argv[1:])

docker_args = ["docker", "run", "-i", "-t", "-u", "builder"]
if os.uname()[4] == "arm64":
if os.uname()[4] != "x86_64":
docker_args += ["--platform", "linux/amd64"]
if args.rm:
docker_args += ["--rm=true"]
Expand Down
Loading