From fcf12e5361477f8587f5585c0d5786b76aa5dbce Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Tue, 26 Sep 2023 16:23:29 +0200 Subject: [PATCH] Allow the users to run earthly without docker Running earthly inside docker adds a layer of complexity to the system, which is bound to bring bugs with it. I ran into a few issue running earthly inside docker, e.g. https://github.com/earthly/earthly/issues/2838 and https://github.com/earthly/earthly/issues/3167. Hence, I added the environment variable EARTHLY_BIN and documented it. --- README.md | 1 + earthly.sh | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d5b083a..0f635e1 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ Skip this step if your base image is ubuntu or opensuse-leap. If you are buildin | Parameter | Description | Type | Default Value | |------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|-------------------------| | CUSTOM_TAG | Environment name for provider image tagging. The default value is `demo`. | String | `demo` | +| EARTHLY_BIN | Path to earthly binary on the host system (e.g. /usr/local/bin/earthly). If empty the docker image of earthly is used. | String | | | IMAGE_REGISTRY | Image registry name that will store the image artifacts. The default value points to the *ttl.sh* image registry, an anonymous and ephemeral Docker image registry where images live for a maximum of 24 hours by default. If you wish to make the images exist longer than 24 hours, you can use any other image registry to suit your needs. | String | `ttl.sh` | | OS_DISTRIBUTION | OS distribution of your choice. For example, it can be `ubuntu` or `opensuse-leap`. | String | `ubuntu` | | IMAGE_REPO | Image repository name in your chosen registry. | String | `$OS_DISTRIBUTION` | diff --git a/earthly.sh b/earthly.sh index 84650b7..e092247 100755 --- a/earthly.sh +++ b/earthly.sh @@ -1,4 +1,7 @@ #!/bin/bash + +set -e + function build_with_proxy() { export HTTP_PROXY=$HTTP_PROXY export HTTPS_PROXY=$HTTPS_PROXY @@ -37,7 +40,9 @@ if ! docker run --rm --privileged alpine sh -c 'echo "Privileged container test" echo "Privileged containers are not allowed for the current user." exit 1 fi -if [ -z "$HTTP_PROXY" ] && [ -z "$HTTPS_PROXY"]; then +if [ ! -z "${EARTHLY_BIN}" ]; then + "${EARTHLY_BIN}" --allow-privileged "$@" +elif [ -z "$HTTP_PROXY" ] && [ -z "$HTTPS_PROXY"]; then build_without_proxy "$@" else build_with_proxy "$@"