-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ADACS-Australia/feature/docker
Add testing with Docker
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
############# | ||
# Base image | ||
############# | ||
FROM python:3.11-buster | ||
|
||
RUN pip install poetry==1.4.2 | ||
|
||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_CREATE=0 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
||
ENV TEST_ROOT /test_template | ||
ENV TEMPLATE_ROOT /template | ||
|
||
WORKDIR ${TEST_ROOT} | ||
|
||
################################################################ | ||
# Copy and install Poetry dependencies (but not the actual | ||
# application, which will get installed by the entry_point | ||
# script when we start the container) | ||
################################################################ | ||
COPY pyproject.toml poetry.lock . | ||
RUN poetry install --no-root && \ | ||
rm -rf ${POETRY_CACHE_DIR} && \ | ||
rm pyproject.toml && \ | ||
mv poetry.lock poetry.lock.image | ||
|
||
########################## | ||
# Set-up the entry point | ||
########################## | ||
RUN touch entry_script.sh | ||
RUN chmod a+rx ${TEST_ROOT}/entry_script.sh | ||
RUN echo '\n\ | ||
set -e \n\ | ||
\n\ | ||
_term() {\n\ | ||
echo "Caught SIGTERM signal!"\n\ | ||
kill -TERM "$child" 2>/dev/null\n\ | ||
}\n\ | ||
\n\ | ||
# trap _term SIGTERM\n\ | ||
\n\ | ||
if ! test -d ${TEMPLATE_ROOT} ; then \n\ | ||
echo The project directory has not been mounted. Please run the container with e.g. 'docker run -v \$PWD:${TEMPLATE_ROOT}' \n\ | ||
exit 1 \n\ | ||
fi \n\ | ||
if ! cmp -s ${TEST_ROOT}/poetry.lock.image ${TEMPLATE_ROOT}/poetry.lock ; then \n\ | ||
echo poetry.lock has been updated since the image was built. Please rebuild it and try again. \n\ | ||
exit 1 \n\ | ||
fi \n\ | ||
cd ${TEMPLATE_ROOT} \n\ | ||
poetry install --only-root \n\ | ||
pytest' >> ${TEST_ROOT}/entry_script.sh | ||
ENTRYPOINT ["sh", "-c", "${TEST_ROOT}/entry_script.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# The following are needed to make sure that running: | ||
# $ make -f <path>/Makefile | ||
# will work with this Makefile. | ||
MAKEFILE_PATH = $(abspath $(lastword $(MAKEFILE_LIST))) | ||
MAKEFILE_DIR = $(dir $(MAKEFILE_PATH)) | ||
PRJ_PATH=$(realpath ${MAKEFILE_DIR} ) | ||
PRJ_SLUG=$(notdir ${PRJ_PATH}) | ||
|
||
docker-build: | ||
docker build -t ${PRJ_SLUG} . | ||
|
||
docker-tests: | ||
docker run --rm -v ${PRJ_PATH}:/template ${PRJ_SLUG} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters