Skip to content

Commit

Permalink
Updated Build for Mac based on PR cluster-apps-on-docker#42 on the main
Browse files Browse the repository at this point in the history
  • Loading branch information
HarisMichailidis committed Jul 13, 2021
1 parent d908cb6 commit 2c8aaea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ docker-compose up

### Build from your local machine

> **Note**: Local build is currently only supported on Linux OS distributions.
> **Note**: Local build is currently only supported on Linux OS and Mac OSX distributions.

1. Download the source code or clone the repository;
2. Move to the build directory;
Expand All @@ -83,7 +83,7 @@ cd build

3. Edit the [build.yml](build/build.yml) file with your favorite tech stack version;
4. Match those version on the [docker compose](build/docker-compose.yml) file;
5. Build up the images;
5. Build up the images (for Mac OSX see below and then continue to step 6);

```bash
chmod +x build.sh ; ./build.sh
Expand All @@ -99,6 +99,22 @@ docker-compose up
8. Stop the cluster by typing `ctrl+c` on the terminal;
9. Run step 6 to restart the cluster.

#### Mac OSX

Mac OSX comes with the preinstalled BSD version of `grep`.
In order to be able to build these Docker images, you will need to install GNU version of grep with Homebrew:

```
brew install grep
```

> **Note**: From now on you can use the GNU version of grep by calling ``ggrep``.
Now you can run the steps described above, but add an argument in step 5:

```bash
chmod +x build.sh ; ./build.sh mac
```

## <a name="tech-stack"></a>Tech Stack

- Infra
Expand Down
48 changes: 32 additions & 16 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@
# -- Variables ---------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------

# check if 'mac' is passed as an argument and use 'ggrep' then
# 'ggrep' (GNU version of grep for Mac) can be installed from homebrew
if [[ $1 == "mac" ]]
then
grep="ggrep"
else
grep="grep"
fi

grep_origin="$(${grep} --version)"
if [[ $grep_origin != *"GNU"* ]]; then
echo "Using wrong grep: ${grep_origin}. GNU version is required. You can install it e.g. with homebrew on Mac."
exit
fi


BUILD_DATE="$(date -u +'%Y-%m-%d')"

SHOULD_BUILD_BASE="$(grep -m 1 build_base build.yml | grep -o -P '(?<=").*(?=")')"
SHOULD_BUILD_SPARK="$(grep -m 1 build_spark build.yml | grep -o -P '(?<=").*(?=")')"
SHOULD_BUILD_JUPYTERLAB="$(grep -m 1 build_jupyter build.yml | grep -o -P '(?<=").*(?=")')"
SHOULD_BUILD_BASE="$(${grep} -m 1 build_base build.yml | ${grep} -o -P '(?<=").*(?=")')"
SHOULD_BUILD_SPARK="$(${grep} -m 1 build_spark build.yml | ${grep} -o -P '(?<=").*(?=")')"
SHOULD_BUILD_JUPYTERLAB="$(${grep} -m 1 build_jupyter build.yml | ${grep} -o -P '(?<=").*(?=")')"

SPARK_VERSION="$(grep -m 1 spark build.yml | grep -o -P '(?<=").*(?=")')"
JUPYTERLAB_VERSION="$(grep -m 1 jupyterlab build.yml | grep -o -P '(?<=").*(?=")')"
SPARK_VERSION="$(${grep} -m 1 spark build.yml | ${grep} -o -P '(?<=").*(?=")')"
JUPYTERLAB_VERSION="$(${grep} -m 1 jupyterlab build.yml | ${grep} -o -P '(?<=").*(?=")')"

SPARK_VERSION_MAJOR=${SPARK_VERSION:0:1}

Expand All @@ -37,27 +53,27 @@ fi

function cleanContainers() {

container="$(docker ps -a | grep 'jupyterlab' | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'jupyterlab' | awk '{print $1}')"
docker stop "${container}"
docker rm "${container}"

container="$(docker ps -a | grep 'spark-worker' -m 1 | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'spark-worker' -m 1 | awk '{print $1}')"
while [ -n "${container}" ];
do
docker stop "${container}"
docker rm "${container}"
container="$(docker ps -a | grep 'spark-worker' -m 1 | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'spark-worker' -m 1 | awk '{print $1}')"
done

container="$(docker ps -a | grep 'spark-master' | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'spark-master' | awk '{print $1}')"
docker stop "${container}"
docker rm "${container}"

container="$(docker ps -a | grep 'spark-base' | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'spark-base' | awk '{print $1}')"
docker stop "${container}"
docker rm "${container}"

container="$(docker ps -a | grep 'base' | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'base' | awk '{print $1}')"
docker stop "${container}"
docker rm "${container}"

Expand All @@ -67,19 +83,19 @@ function cleanImages() {

if [[ "${SHOULD_BUILD_JUPYTERLAB}" == "true" ]]
then
docker rmi -f "$(docker images | grep -m 1 'jupyterlab' | awk '{print $3}')"
docker rmi -f "$(docker images | ${grep} -m 1 'jupyterlab' | awk '{print $3}')"
fi

if [[ "${SHOULD_BUILD_SPARK}" == "true" ]]
then
docker rmi -f "$(docker images | grep -m 1 'spark-worker' | awk '{print $3}')"
docker rmi -f "$(docker images | grep -m 1 'spark-master' | awk '{print $3}')"
docker rmi -f "$(docker images | grep -m 1 'spark-base' | awk '{print $3}')"
docker rmi -f "$(docker images | ${grep} -m 1 'spark-worker' | awk '{print $3}')"
docker rmi -f "$(docker images | ${grep} -m 1 'spark-master' | awk '{print $3}')"
docker rmi -f "$(docker images | ${grep} -m 1 'spark-base' | awk '{print $3}')"
fi

if [[ "${SHOULD_BUILD_BASE}" == "true" ]]
then
docker rmi -f "$(docker images | grep -m 1 'base' | awk '{print $3}')"
docker rmi -f "$(docker images | ${grep} -m 1 'base' | awk '{print $3}')"
fi

}
Expand Down

0 comments on commit 2c8aaea

Please sign in to comment.