-
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.
added dockerfile and compatible readme
- Loading branch information
Tobias Schoch
authored and
Tobias Schoch
committed
May 2, 2018
1 parent
9f557bc
commit 22f0619
Showing
11 changed files
with
233 additions
and
0 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 @@ | ||
.idea |
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,24 @@ | ||
Cookiecutter Docker Template | ||
============================ | ||
author: Tobias Schoch | ||
|
||
Overview | ||
-------- | ||
|
||
Cookiecutter template for new docker projects providing a compatible README.md to use with toschoch/python-gittools. | ||
|
||
Requirements | ||
------------ | ||
Install `cookiecutter` command line: `pip install cookiecutter` | ||
|
||
Change-Log | ||
---------- | ||
##### 0.0.1 | ||
* initial version | ||
|
||
Installation / Usage | ||
-------------------- | ||
Create project from template with cookiecutter | ||
``` | ||
cookiecutter git+<git-url> | ||
``` |
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,8 @@ | ||
{ | ||
"full_name": "Your name", | ||
"email": "Your address email (eq. [email protected])", | ||
"project_name": "Python Package", | ||
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}", | ||
"description": "A python package that can be installed with pip.", | ||
"version": "0.0.1" | ||
} |
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,76 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import re | ||
import shutil | ||
|
||
|
||
def fix_template_expansion(content, replacements): | ||
""" | ||
fix template expansion after hook copy | ||
:param content: the duplicated hook content | ||
:param replacements: array of dictionaries | ||
cookiecutter_key => template key expanded | ||
""" | ||
for replacement in replacements: | ||
for key, to_be_replaced in replacement.items(): | ||
replacement = chr(123) + chr(123) + \ | ||
'cookiecutter.' + key + chr(125) + chr(125) | ||
content = content.replace(to_be_replaced, replacement) | ||
return content | ||
|
||
|
||
def get_file_content(file): | ||
""" | ||
get the content of a given file | ||
:param file: the file to get the content of | ||
""" | ||
return open(file, 'r').read() | ||
|
||
|
||
def set_file_content(file, content): | ||
""" | ||
write content to file | ||
:param file: the file to rewrite its content | ||
:param content: content to write to the given file | ||
""" | ||
return open(file, 'w').write(content) | ||
|
||
# format title of the generated readme file | ||
readme = os.getcwd() + '/README.md' | ||
if (os.path.exists(readme)): | ||
title_underliner = ''.center(len('{{cookiecutter.project_name}}'), '=') | ||
set_file_content( | ||
readme, | ||
re.sub( | ||
r'^=+$', title_underliner, get_file_content(readme), 1, flags=re.M | ||
) | ||
) | ||
# end format title of the generated readme file | ||
|
||
# issue #3 - copy post hook to project directory | ||
if (re.match(r'YES', '{{cookiecutter.copy_hooks}}', re.I)): | ||
if (re.match(r'^cookiecutter\-', '{{cookiecutter.project_slug}}')): | ||
hooksdir = os.getcwd() + '/hooks' | ||
posthook = hooksdir + '/post_gen_project.py' | ||
source = os.path.realpath(__file__) | ||
replacements = [ | ||
{'project_slug': '{{cookiecutter.project_slug}}'}, | ||
{'copy_hooks': '{{cookiecutter.copy_hooks}}'}, | ||
|
||
# project_name must be set after project_slug to prevent side | ||
# effects | ||
{'project_name': '{{cookiecutter.project_name}}'} | ||
] | ||
|
||
if (not os.path.exists(hooksdir)): | ||
os.makedirs(hooksdir) | ||
shutil.copyfile(source, posthook) | ||
|
||
set_file_content( | ||
posthook, | ||
fix_template_expansion( | ||
get_file_content(posthook), replacements | ||
) + "\n" | ||
) | ||
# end issue #3 | ||
|
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,2 @@ | ||
[pytest] | ||
testpaths = tests/ |
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,4 @@ | ||
cookiecutter==1.6.0 | ||
flake8==3.5.0 | ||
pytest==3.3.2 | ||
pytest-cookies==0.3.0 |
Empty file.
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,30 @@ | ||
from contextlib import contextmanager | ||
|
||
import os | ||
|
||
|
||
@contextmanager | ||
def inside_dir(dirpath): | ||
""" | ||
Execute code from inside the given directory | ||
:param dirpath: String, path of the directory the command is being run. | ||
""" | ||
old_path = os.getcwd() | ||
try: | ||
os.chdir(dirpath) | ||
yield | ||
finally: | ||
os.chdir(old_path) | ||
|
||
|
||
def test_project_tree(cookies): | ||
result = cookies.bake(extra_context={'project_slug': 'test_project'}) | ||
assert result.exit_code == 0 | ||
assert result.exception is None | ||
assert result.project.basename == 'test_project' | ||
|
||
|
||
def test_run_flake8(cookies): | ||
result = cookies.bake(extra_context={'project_slug': 'flake8_compat'}) | ||
with inside_dir(str(result.project)): | ||
assert os.subprocess.check_call(['flake8']) == 0 |
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,34 @@ | ||
pipeline: | ||
clone: | ||
image: plugins/git | ||
tags: true | ||
|
||
# test: | ||
# image: python:3 | ||
# commands: | ||
# - python setup.py test | ||
|
||
# build: | ||
# image: python 3 | ||
# - python setup.py bdist_wheel | ||
# - python setup.py sdist | ||
# - python setup.py sdist --formats=zip | ||
# | ||
# staging: | ||
# image: shocki/drone-devpi | ||
# server: | ||
# index: | ||
# username: | ||
# password: | ||
# when: | ||
# branch: master | ||
# | ||
# release: | ||
# image: shocki/drone-devpi | ||
# server: | ||
# index: | ||
# username: | ||
# password: | ||
# when: | ||
# event: tag | ||
# status: success |
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,19 @@ | ||
FROM | ||
MAINTAINER {{ cookiecutter.full_name }} <{{ cookiecutter.email }}> | ||
|
||
# Install dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
git-core \ | ||
build-essential \ | ||
gcc \ | ||
python \ | ||
python-dev \ | ||
python-pip \ | ||
--no-install-recommends && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Define working directory | ||
WORKDIR /data | ||
VOLUME /data | ||
|
||
CMD ["/bin/bash"] |
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,35 @@ | ||
{{ cookiecutter.project_name }} | ||
=============================== | ||
author: {{ cookiecutter.full_name }} | ||
|
||
Overview | ||
-------- | ||
|
||
{{ cookiecutter.description }} | ||
|
||
|
||
Change-Log | ||
---------- | ||
##### {{ cookiecutter.version }} | ||
* initial version | ||
|
||
|
||
Installation / Usage | ||
-------------------- | ||
clone the repo: | ||
|
||
``` | ||
git clone <git-url> | ||
``` | ||
build the docker image | ||
``` | ||
docker build . -t {{ cookiecutter.project_slug }} | ||
``` | ||
|
||
Example | ||
------- | ||
|
||
run a container of the image | ||
``` | ||
docker run -v ... -p ... {{ cookiecutter.project_slug }} | ||
``` |