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

Podman build #3

Merged
merged 1 commit into from
Jun 22, 2022
Merged
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
45 changes: 34 additions & 11 deletions scripts/rundocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,20 @@ DOCKER=${DOCKER:-"docker"}

BUILD_CACHE_VOLUME=kolibri-android-cache
BUILD_CACHE_PATH=/cache
BUILD_UID=$(id -u)
BUILD_GID=$(id -g)

docker_is_podman() {
"${DOCKER}" --version 2>/dev/null | grep -q "^podman"
}

# Build array of options to pass to docker run.
RUN_OPTS=(
-it --rm

# Mount the cache volume.
--mount "type=volume,src=${BUILD_CACHE_VOLUME},dst=${BUILD_CACHE_PATH}"

# Bind mount the source directory into the container and make it the
# working dirctory.
--mount "type=bind,src=${SRCDIR},dst=${SRCDIR}"
--workdir "${SRCDIR}"

# Run as the calling user and make the cache volume the user's home
# directory so all the intermediate build outputs (e.g.,
# ~/.local/share/python-for-android and ~/.gradle) are stored.
--user "${BUILD_UID}:${BUILD_GID}"
--env HOME="${BUILD_CACHE_PATH}"

# Pass through other environment variables.
--env BUILDKITE_BUILD_NUMBER
--env P4A_RELEASE_KEYALIAS
Expand All @@ -37,6 +30,36 @@ RUN_OPTS=(
--env ARCHES
)

# If we're running in podman, assume the user namespace is setup so that
# root inside the container is the same as the outside user. Otherwise,
# get the UID and GID to run as.
if docker_is_podman; then
BUILD_UID=0
BUILD_GID=0
else
BUILD_UID=$(id -u)
BUILD_GID=$(id -g)
fi

# If the container user is root, mount the cache at /root. Otherwise,
# set HOME since there's likely no account with that UID in the image.
# The user's home directory is where all the intermediate build outputs
# (e.g., ~/.local/share/python-for-android and ~/.gradle) are stored.
if [ "$BUILD_UID" -eq 0 ]; then
BUILD_CACHE_PATH=/root
else
BUILD_CACHE_PATH=/cache
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing here. The changes in the --user parameter works for me. But the change in BUILD_CACHE_PATH is making the caching worse. I ran the build a second time and is taking ages. I will keep testing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing here. The changes in the --user parameter works for me. But the change in BUILD_CACHE_PATH is making the caching worse. I ran the build a second time and is taking ages. I will keep testing.

I was wrong! This branch in fact reduces the successive builds to 1 minute. Great!!

RUN_OPTS+=(
--user "${BUILD_UID}:${BUILD_GID}"
--env HOME="${BUILD_CACHE_PATH}"
)
fi

# Mount the cache volume.
RUN_OPTS+=(
--mount "type=volume,src=${BUILD_CACHE_VOLUME},dst=${BUILD_CACHE_PATH}"
)

# If the release signing key has been specified and exists, ensure the
# path is absolute and bind mount it readonly into the container.
if [ -e "${P4A_RELEASE_KEYSTORE}" ]; then
Expand Down