Merge pull request #500 from cookiecutter-flask/build-in-docker
Allow cookiecutter build in dockermaster
commit
0146d26d18
@ -1,13 +1,21 @@ |
||||
# Config file for automatic testing at travis-ci.org |
||||
dist: xenial |
||||
language: python |
||||
python: |
||||
- 2.7 |
||||
- 3.5 |
||||
- 3.6 |
||||
- 3.7 |
||||
|
||||
env: |
||||
- INSTALL_NODE_VERSION=8 |
||||
- INSTALL_NODE_VERSION=10 |
||||
- INSTALL_NODE_VERSION=12 |
||||
|
||||
install: |
||||
- pip install cookiecutter |
||||
- pip install invoke==1.0.0 |
||||
- nvm install 8.11.2 |
||||
- nvm use 8.11.2 |
||||
- pip install invoke==1.2.0 |
||||
- nvm install $INSTALL_NODE_VERSION |
||||
- nvm use $INSTALL_NODE_VERSION |
||||
|
||||
script: |
||||
- invoke test |
||||
|
@ -0,0 +1,10 @@ |
||||
FROM python:3.7-alpine |
||||
|
||||
RUN apk update \ |
||||
&& apk upgrade \ |
||||
&& apk add --no-cache git |
||||
|
||||
RUN pip install \ |
||||
cookiecutter==1.6.0 |
||||
|
||||
ENTRYPOINT [ "python", "-m", "cookiecutter" ] |
@ -0,0 +1,66 @@ |
||||
#!/usr/bin/env bash |
||||
set -e |
||||
|
||||
PROGNAME=$0 |
||||
BUILD_IMAGE=false |
||||
COOKIECUTTER_TEMPLATE='.' |
||||
|
||||
|
||||
usage() { |
||||
cat << EOF >&2 |
||||
Usage: $PROGNAME [OPTIONS] |
||||
|
||||
Options: |
||||
-b, --build Build Docker image before running cookiecutter |
||||
-t, --template Specify custom cookiecutter template via a URI to a git repo |
||||
e.g. https://github.com/cookiecutter-flask/cookiecutter-flask.git |
||||
Defaults to template in current working directory |
||||
-h, --help Show this message and exit |
||||
|
||||
EOF |
||||
exit 1 |
||||
} |
||||
|
||||
|
||||
process_args() { |
||||
while test $# -gt 0 |
||||
do |
||||
case "$1" in |
||||
-h) usage |
||||
;; |
||||
--help) usage |
||||
;; |
||||
-b) BUILD_IMAGE=true |
||||
;; |
||||
--build) BUILD_IMAGE=true |
||||
;; |
||||
-t) COOKIECUTTER_TEMPLATE="$2" |
||||
shift |
||||
;; |
||||
--template) COOKIECUTTER_TEMPLATE="$2" |
||||
shift |
||||
;; |
||||
--*) usage; |
||||
exit 1; |
||||
;; |
||||
*) usage; |
||||
exit 1; |
||||
;; |
||||
esac |
||||
shift |
||||
done |
||||
} |
||||
|
||||
|
||||
run_cookiecutter() { |
||||
if [[ "$(docker images -q cookiecutter-docker 2> /dev/null)" == "" ]] || $BUILD_IMAGE ; then |
||||
docker build . --tag=cookiecutter-docker |
||||
fi |
||||
|
||||
docker run -i -t -v ${PWD}:/build -w /build cookiecutter-docker ${COOKIECUTTER_TEMPLATE} |
||||
} |
||||
|
||||
process_args "$@" |
||||
run_cookiecutter |
||||
|
||||
exit 0 |
@ -0,0 +1,28 @@ |
||||
import re |
||||
import sys |
||||
|
||||
|
||||
MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$" |
||||
|
||||
|
||||
class bcolors: |
||||
WARNING = "\033[93m" |
||||
ENDC = "\033[0m" |
||||
BOLD = "\033[1m" |
||||
|
||||
|
||||
def validate_python_module_name(): |
||||
module_name = "{{ cookiecutter.app_name }}" |
||||
if not re.match(MODULE_REGEX, module_name): |
||||
print( |
||||
( |
||||
"\n{0}ERROR:{1} " |
||||
+ "{2}{3}{1} is not a valid Python module name!\n" |
||||
+ "See https://www.python.org/dev/peps/pep-0008/#package-and-module-names for naming standards.\n" |
||||
).format(bcolors.WARNING, bcolors.ENDC, bcolors.BOLD, module_name) |
||||
) |
||||
sys.exit(1) |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
validate_python_module_name() |
Loading…
Reference in new issue