Skip to content

Commit

Permalink
Move Dockerfile to docker dir + add build & run scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jlegrand62 committed Sep 11, 2020
1 parent bea4805 commit f1ea73a
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 7 deletions.
13 changes: 7 additions & 6 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ ENV LANG=C.UTF-8
ENV PYTHONUNBUFFERED=1

# Set non-root user name:
ENV USER_NAME=scanner
ARG USER_NAME=scanner
ARG BRANCH=master
ARG API_URL='https://db.romi-project.eu'

USER root
# Change shell to 'bash', default is 'sh'
Expand All @@ -21,22 +23,21 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/* && \
useradd -m ${USER_NAME} && \
cd /home/${USER_NAME} && \
mkdir project && \
chown -R ${USER_NAME}: /home/${USER_NAME}

# Change user
USER ${USER_NAME}
# Change working directory:
WORKDIR /home/${USER_NAME}/project
WORKDIR /home/${USER_NAME}

RUN git clone https://github.com/romi/3d-plantviewer.git && \
RUN git clone --branch $BRANCH https://github.com/romi/3d-plantviewer.git && \
cd 3d-plantviewer && \
# Install modules listed as dependencies in `package.json`:
npm install

WORKDIR /home/${USER_NAME}/project/3d-plantviewer
WORKDIR /home/${USER_NAME}/3d-plantviewer

# Link the docker image to romi database:
ENV REACT_APP_API_URL='https://db.romi-project.eu'
ENV REACT_APP_API_URL=$API_URL

CMD ["/bin/bash", "-c", "npm start"]
103 changes: 103 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash

###############################################################################
# Example usages:
###############################################################################
# 1. Default build options will create `roboticsmicrofarms/plantviewer:latest` pointing at ROMI database:
# $ ./build.sh
#
# 2. Build image with 'debug' image tag & another 'plantviewer' branch options:
# $ ./build.sh -t debug -b 'feature/faster_docker'

user=$USER
vtag="latest"
branch='master'
api_url='https://db.romi-project.eu'
docker_opts=""

usage() {
echo "USAGE:"
echo " ./build.sh [OPTIONS]
"

echo "DESCRIPTION:"
echo " Build a docker image named 'roboticsmicrofarms/plantviewer' using Dockerfile in same location.
"

echo "OPTIONS:"
echo " -t, --tag
Docker image tag to use, default to '$vtag'.
"
echo " -u, --user
User name to create inside docker image, default to '$user'.
"
echo " -b, --branch
Git branch to use for cloning '3d-plantviewer' inside docker image, default to '$branch'.
"
echo " --api_url
REACT API URL to use to retrieve dataset, default is '$api_url'.
"
# Docker options:
echo " --no-cache
Do not use cache when building the image, (re)start from scratch.
"
echo " --pull
Always attempt to pull a newer version of the parent image.
"
# General options:
echo " -h, --help
Output a usage message and exit.
"
}

while [ "$1" != "" ]; do
case $1 in
-t | --tag)
shift
vtag=$1
;;
-u | --user)
shift
user=$1
;;
-b | --branch)
shift
branch=$1
;;
--api_url)
shift
api_url=$1
;;
--no-cache)
shift
docker_opts="$docker_opts --no-cache"
;;
--pull)
shift
docker_opts="$docker_opts --pull"
;;
-h | --help)
usage
exit
;;
*)
usage
exit 1
;;
esac
shift
done

# Get the date to estimate docker image build time:
start_time=`date +%s`

# Start the docker image build:
docker build -t roboticsmicrofarms/plantviewer:$vtag $docker_opts \
--build-arg USER_NAME=$user \
--build-arg BRANCH=$branch \
--build-arg API_URL=$api_url \
.

# Print docker image build time:
echo
echo "Build time: $(expr `date +%s` - $start_time)s"
2 changes: 1 addition & 1 deletion docker-compose.yml → docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ services:
depends_on:
- db
environment:
REACT_APP_API_URL: http://172.21.0.2:5000
REACT_APP_API_URL: http://172.21.0.1:5000
ports:
- "3000:3000"
67 changes: 67 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

###############################################################################
# Example usages:
###############################################################################
# 1. Default run starts an interactive shell:
# $ ./run.sh

vtag="latest"
api_url='https://db.romi-project.eu'

usage() {
echo "USAGE:"
echo " ./run.sh [OPTIONS]
"

echo "DESCRIPTION:"
echo " Run 'roboticsmicrofarms/plantviewer:<vtag>' container with a mounted local (host) database.
"

echo "OPTIONS:"
echo " -t, --tag
Docker image tag to use, default to '$vtag'.
"
echo " --api_url
REACT API URL to use to retrieve dataset, default is '$api_url'.
"

echo " -h, --help
Output a usage message and exit.
"
}

while [ "$1" != "" ]; do
case $1 in
-t | --tag)
shift
vtag=$1
;;
--api_url)
shift
api_url=$1
;;
-h | --help)
usage
exit
;;
*)
usage
exit 1
;;
esac
shift
done

# Use 'host database path' & 'docker user' to create a bind mount:
if [ "$api_url" != "" ]
then
docker run \
--env REACT_APP_API_URL="$api_url" \
-it roboticsmicrofarms/plantviewer:$vtag
else
docker run \
-it roboticsmicrofarms/plantviewer:$vtag
fi


0 comments on commit f1ea73a

Please sign in to comment.