diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2023-02-08 16:25:28 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2023-02-08 16:25:28 +0100 |
| commit | 64ed12685a418cbaebdac3103ca10921b1e45338 (patch) | |
| tree | cec16c8ac6ff514999cde263dc0f203f72765948 | |
| parent | 50e5c186ca0bc14903f928b6f13fa56a11bcd760 (diff) | |
| parent | 8fe02b1fb99ac7781f2779b7d1d2acfc863ec633 (diff) | |
| download | mullvadvpn-64ed12685a418cbaebdac3103ca10921b1e45338.tar.xz mullvadvpn-64ed12685a418cbaebdac3103ca10921b1e45338.zip | |
Merge branch 'add-container-helper-script'
| -rwxr-xr-x | building/container-run.sh | 55 | ||||
| -rwxr-xr-x | building/containerized-build.sh | 38 |
2 files changed, 62 insertions, 31 deletions
diff --git a/building/container-run.sh b/building/container-run.sh new file mode 100755 index 0000000000..eaaa115149 --- /dev/null +++ b/building/container-run.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# Gives you a shell or runs a given command in the Android or Linux build container, +# as designated by the *-container-image.txt files. Uses podman unless overridden using the +# environment variable `CONTAINER_RUNNER`. Note that this script uses named +# docker volumes that can be overridden using enviornment variables (see the +# beginning of the script). +# +# Usage: $ container-run.sh <linux/android> [command ...] +# +# Not supplying any command gives you a shell in the container. + +set -eu + +REPO_MOUNT_TARGET="/build" +CARGO_TARGET_VOLUME_NAME=${CARGO_TARGET_VOLUME_NAME:-"cargo-target"} +CARGO_REGISTRY_VOLUME_NAME=${CARGO_REGISTRY_VOLUME_NAME:-"cargo-registry"} +GRADLE_CACHE_VOLUME_NAME=${GRADLE_CACHE_VOLUME_NAME:-"gradle-cache"} +ANDROID_CREDENTIALS_DIR=${ANDROID_CREDENTIALS_DIR:-""} +CONTAINER_RUNNER=${CONTAINER_RUNNER:-"podman"} + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +REPO_DIR="$( cd "$SCRIPT_DIR/.." && pwd )" +cd "$SCRIPT_DIR" + +source "$REPO_DIR/scripts/utils/log" + +case ${1-:""} in + linux) + container_image_name=$(cat "$SCRIPT_DIR/linux-container-image.txt") + shift 1 + ;; + android) + container_image_name=$(cat "$SCRIPT_DIR/android-container-image.txt") + optional_gradle_cache_volume=(-v "$GRADLE_CACHE_VOLUME_NAME:/root/.gradle:Z") + + if [ -n "$ANDROID_CREDENTIALS_DIR" ]; then + optional_android_credentials_volume=(-v "$ANDROID_CREDENTIALS_DIR:$REPO_MOUNT_TARGET/android/credentials:Z") + fi + + shift 1 + ;; + *) + log_error "Invalid platform. Specify 'linux' or 'android' as first argument" + exit 1 +esac + +set -x +exec "$CONTAINER_RUNNER" run --rm -it \ + -v "$REPO_DIR:$REPO_MOUNT_TARGET:Z" \ + -v "$CARGO_TARGET_VOLUME_NAME:/root/.cargo/target:Z" \ + -v "$CARGO_REGISTRY_VOLUME_NAME:/root/.cargo/registry:Z" \ + "${optional_gradle_cache_volume[@]}" \ + "${optional_android_credentials_volume[@]}" \ + "$container_image_name" "$@" diff --git a/building/containerized-build.sh b/building/containerized-build.sh index 32b75df116..dd8bf17fa8 100755 --- a/building/containerized-build.sh +++ b/building/containerized-build.sh @@ -1,41 +1,24 @@ #!/usr/bin/env bash -# Builds the Android or Linux app in the current build container, as designated -# by the *-container-image.txt files. Uses podman unless overridden using the -# environment variable `CONTAINER_RUNNER`. Note that this script uses named -# docker volumes that can be overridden using enviornment variables (see the -# beginning of the script). +# Builds the Android or Linux app in the current build container. +# See the `container-run.sh` script for possible configuration. set -eu -REPO_MOUNT_TARGET="/build" -CARGO_TARGET_VOLUME_NAME=${CARGO_TARGET_VOLUME_NAME:-"cargo-target"} -CARGO_REGISTRY_VOLUME_NAME=${CARGO_REGISTRY_VOLUME_NAME:-"cargo-registry"} -GRADLE_CACHE_VOLUME_NAME=${GRADLE_CACHE_VOLUME_NAME:-"gradle-cache"} -ANDROID_CREDENTIALS_DIR=${ANDROID_CREDENTIALS_DIR:-""} -CONTAINER_RUNNER=${CONTAINER_RUNNER:-"podman"} - SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REPO_DIR="$( cd "$SCRIPT_DIR/.." && pwd )" cd "$SCRIPT_DIR" source "$REPO_DIR/scripts/utils/log" -case ${1-:""} in +platform=${1-:""} +case $platform in linux) - container_image_name=$(cat "$SCRIPT_DIR/linux-container-image.txt") - build_command=("$REPO_MOUNT_TARGET/build.sh") + build_command=("./build.sh") shift 1 ;; android) - container_image_name=$(cat "$SCRIPT_DIR/android-container-image.txt") - build_command=("$REPO_MOUNT_TARGET/build-apk.sh" "--no-docker") - optional_gradle_cache_volume=(-v "$GRADLE_CACHE_VOLUME_NAME:/root/.gradle:Z") - - if [ -n "$ANDROID_CREDENTIALS_DIR" ]; then - optional_android_credentials_volume=(-v "$ANDROID_CREDENTIALS_DIR:$REPO_MOUNT_TARGET/android/credentials:Z") - fi - + build_command=("./build-apk.sh" "--no-docker") shift 1 ;; *) @@ -44,11 +27,4 @@ case ${1-:""} in esac set -x -exec "$CONTAINER_RUNNER" run --rm -it \ - -v "$REPO_DIR:$REPO_MOUNT_TARGET:Z" \ - -v "$CARGO_TARGET_VOLUME_NAME:/root/.cargo/target:Z" \ - -v "$CARGO_REGISTRY_VOLUME_NAME:/root/.cargo/registry:Z" \ - "${optional_gradle_cache_volume[@]}" \ - "${optional_android_credentials_volume[@]}" \ - "$container_image_name" \ - "${build_command[@]}" "$@" +exec "$SCRIPT_DIR/container-run.sh" "$platform" "${build_command[@]}" "$@" |
