-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (64 loc) · 3.19 KB
/
Copy pathDockerfile
File metadata and controls
84 lines (64 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# syntax = docker/dockerfile:1.4.0
################################# [Base Python Image] ##################################
# Allow the Python version to be specified as a build argument, with a preferred default
ARG VERSION=3.13
FROM python:${VERSION} AS base
# Create a symlink between the installed Python version path and a versionless path to
# ease long-term maintenance that simply requires the symlink to be generated when the
# Python version is modified, rather than a whole range of absolute paths. Many Python
# installations create a versionless path symlink by default; Docker's doesn't seem to.
RUN <<ENDRUN
# Use 'awk' and 'cut' to extract the major.minor version from `python --version` as
# the major.minor, but not micro, version parts are used in the installation path:
VERSION=$(python --version 2>&1 | awk '{print $2}' | cut -d'.' -f1,2)
echo "Creating a symlink from the versioned installation path to a generic path:"
ln -s -v "/usr/local/lib/python${VERSION}" "/usr/local/lib/python"
ENDRUN
# Ensure pip has been upgraded to the latest version before installing dependencies
RUN pip install --upgrade pip
############################# [Development Python Image] ###############################
FROM base AS development
# Copy and install the dependencies from requirements.txt
COPY requirements.txt /app/requirements.txt
RUN pip install --requirement /app/requirements.txt
# Copy and install the dependencies from requirements.development.txt
COPY requirements.development.txt /app/requirements.development.txt
RUN pip install --requirement /app/requirements.development.txt
# Copy and install the dependencies from requirements.distribution.txt
# COPY requirements.deployment.txt /app/requirements.distribution.txt
# RUN pip install --requirement /app/requirements.distribution.txt
# Copy the library source into the container's source folder for black lint checking
COPY ./source/classicist /source/classicist
# Copy the README into the container's root folder for PyTest README code block testing
COPY ./README.md /README.md
# Copy the tests into the container
COPY ./tests /tests
# Copy the library source into the container's site-packages folder for running unit tests
COPY ./source/classicist /usr/local/lib/python/site-packages/classicist
# Create a custom entry point that allows us to override the command as needed
COPY <<"COPYEOF" /entrypoint.sh
#!/bin/bash
ARGS=( "$@" );
echo -e "entrypoint.sh called with arguments: ${ARGS[@]}";
if [[ "${SERVICE}" == "black" ]]; then
if [[ "${ARGS[0]}" == "--reformat" ]]; then
echo -e "black --verbose ${ARGS[@]:1} /source /tests";
black --verbose ${ARGS[@]:1} /source /tests;
else
echo -e "black --check ${ARGS[@]:1} /source /tests";
black --check ${ARGS[@]:1} /source /tests;
fi
elif [[ "${SERVICE}" == "flakes" ]]; then
echo -e "pyflakes /source /tests ${ARGS[@]}";
pyflakes /source /tests ${ARGS[@]};
elif [[ "${SERVICE}" == "tests" ]]; then
echo -e "pytest /tests ${ARGS[@]}";
pytest /tests ${ARGS[@]};
pytest --verbose --codeblocks /README.md;
else
echo -e "No valid command was specified nor defined in the `SERVICE` environment!";
fi
COPYEOF
RUN chmod +x /entrypoint.sh
# Run the unit tests starter shell script
ENTRYPOINT [ "/entrypoint.sh" ]