Merge pull request #500 from cookiecutter-flask/build-in-docker

Allow cookiecutter build in docker
master
James Curtin 6 years ago committed by GitHub
commit 0146d26d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      .travis.yml
  2. 10
      Dockerfile
  3. 23
      README.rst
  4. 66
      cookiecutter-docker.sh
  5. 2
      cookiecutter.json
  6. 6
      hooks/post_gen_project.py
  7. 28
      hooks/pre_gen_project.py

@ -1,13 +1,21 @@
# Config file for automatic testing at travis-ci.org # Config file for automatic testing at travis-ci.org
dist: xenial
language: python language: python
python: python:
- 2.7
- 3.5 - 3.5
- 3.6 - 3.6
- 3.7
env:
- INSTALL_NODE_VERSION=8
- INSTALL_NODE_VERSION=10
- INSTALL_NODE_VERSION=12
install: install:
- pip install cookiecutter - pip install cookiecutter
- pip install invoke==1.0.0 - pip install invoke==1.2.0
- nvm install 8.11.2 - nvm install $INSTALL_NODE_VERSION
- nvm use 8.11.2 - nvm use $INSTALL_NODE_VERSION
script: script:
- invoke test - 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" ]

@ -16,7 +16,26 @@ A Flask template for cookiecutter_.
Use it now Use it now
---------- ----------
::
Docker
******
.. code-block:: bash
$ ./cookiecutter-docker.sh --help
Usage: ./cookiecutter-docker.sh [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
Standard
********
.. code-block:: bash
$ pip install cookiecutter $ pip install cookiecutter
$ cookiecutter https://github.com/cookiecutter-flask/cookiecutter-flask.git $ cookiecutter https://github.com/cookiecutter-flask/cookiecutter-flask.git
@ -120,7 +139,7 @@ Changelog
- Update stale requirements. - Update stale requirements.
- Add CSRF protection. - Add CSRF protection.
- Run ``lint`` commmand on Travis builds. - Run ``lint`` command on Travis builds.
- Test against Python 3.5. - Test against Python 3.5.
0.8.0 (11/09/2015) 0.8.0 (11/09/2015)

@ -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

@ -7,5 +7,5 @@
"project_short_description": "A flasky app.", "project_short_description": "A flasky app.",
"use_pipenv": ["no", "yes"], "use_pipenv": ["no", "yes"],
"python_version": ["3.7", "3.6", "3.5"], "python_version": ["3.7", "3.6", "3.5"],
"node_version": ["12", "11", "10", "8"] "node_version": ["12", "10", "8"]
} }

@ -1,13 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Post gen hook to ensure that the generated project """Post gen hook to ensure that the generated project
hase only one package managment, either pipenv or pip.""" has only one package management, either pipenv or pip."""
import os import os
import shutil import shutil
import sys import sys
def clean_extra_package_managment_files(): def clean_extra_package_management_files():
"""Removes either requirements files and folder or the Pipfile.""" """Removes either requirements files and folder or the Pipfile."""
use_pipenv = '{{cookiecutter.use_pipenv}}' use_pipenv = '{{cookiecutter.use_pipenv}}'
to_delete = [] to_delete = []
@ -32,4 +32,4 @@ def clean_extra_package_managment_files():
if __name__ == '__main__': if __name__ == '__main__':
clean_extra_package_managment_files() clean_extra_package_management_files()

@ -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…
Cancel
Save