Skip to content
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
16 changes: 16 additions & 0 deletions docker-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG BASE_IMAGE=python:${PYTHON_VERSION}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to get familiar with hadolint and apply it to your Dockerfile to see what suggestions it gives you in terms of improving the code, here's a post to learn more about it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used hadolint to format the Dockerfile accordingly :)

FROM ${BASE_IMAGE} as base

RUN apt-get update \
&& apt-get install --no-install-recommends -y cmake \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /nlp_profiler

COPY . .

RUN pip install --no-cache-dir -r requirements-dev.txt \
&& pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir -r requirements-nix-dev.txt
28 changes: 28 additions & 0 deletions docker-image/run-nlp-profiler-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to get familiar with a bash shell linter to see what comments it has about your shell script - search for shellcheck, install it and then use it on this shell script.

Use the comments from shellcheck to improve the code if any comments are given


set -e
set -u
set -o pipefail

PYTHON_VERSION=${1:-"3.8"}

MOUNT_VOLUME="${PWD}/../"
TARGET_FOLDER="/nlp_profiler"
DOCKER_IMAGE_NAME="nlp_profiler"

echo "~~~ Running nlp_profiler in a docker container"
echo "Docker image name: ${DOCKER_IMAGE_NAME}"
echo "Mounted volume: ${MOUNT_VOLUME}"
echo "Target folder: ${TARGET_FOLDER}"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a good practise to echo the steps that are executed at the different lines in the code - this way when one reads the console they can tell what stage of the shellscript it is at - look at examples of my own code to find out how we have been doing it, the clue is look for echos in the shell script and also in the Dockerfile

echo "~~~ Building docker image ${DOCKER_IMAGE_NAME} with Python version ${PYTHON_VERSION}."
docker build -t ${DOCKER_IMAGE_NAME} --build-arg python_version="${PYTHON_VERSION}" ../

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good practice to show this line executing with all its parameters, how would you do that in bash?

Also look at one of the examples from the resources shared above

echo "~~~ Running docker container ${DOCKER_IMAGE_NAME}."
docker run -it \
--volume "${MOUNT_VOLUME}":${TARGET_FOLDER} \
--workdir ${TARGET_FOLDER} \
${DOCKER_IMAGE_NAME} \
/bin/bash

echo "~~~ Exited docker container."