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

Update Build Script for Mac #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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 @@ -87,6 +87,24 @@ docker-compose up
7. Run Apache Spark code using the provided Jupyter [notebooks](build/workspace/) with Scala, PySpark and SparkR examples;
8. Stop the cluster by typing `ctrl+c`.

#### 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

- Infrastructure
Expand Down
51 changes: 33 additions & 18 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@
# -- 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 '(?<=").*(?=")')"

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

# ----------------------------------------------------------------------------------------------------------------------
# -- Functions----------------------------------------------------------------------------------------------------------
Expand All @@ -25,35 +40,35 @@ function cleanContainers() {

if [[ "${SHOULD_BUILD_JUPYTERLAB}" == "true" ]]
then
container="$(docker ps -a | grep 'jupyterlab' | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'jupyterlab' | awk '{print $1}')"
docker stop "${container}"
docker rm "${container}"
fi

if [[ "${SHOULD_BUILD_SPARK}" == "true" ]]
then

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}"

fi

if [[ "${SHOULD_BUILD_BASE}" == "true" ]]
then
container="$(docker ps -a | grep 'base' | awk '{print $1}')"
container="$(docker ps -a | ${grep} 'base' | awk '{print $1}')"
docker stop "${container}"
docker rm "${container}"
fi
Expand All @@ -64,19 +79,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