Skip to content

Commit 9bac1d3

Browse files
authored
Feature/containers update (#1)
* added makes for container building * added option for the git protocol in the container to be https or ssh
1 parent c937019 commit 9bac1d3

File tree

5 files changed

+141
-11
lines changed

5 files changed

+141
-11
lines changed

cookiecutter.json

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,47 @@
44
"git_username": "user-name",
55
"git_repo_name": "my-python-thing",
66
"git_url": "https://github.com/{{ cookiecutter.git_username }}/{{ cookiecutter.git_repo_name }}",
7-
"library_description": "A short description",
8-
"library_version": "0.1.0",
9-
"library_documents_location": ["readthedocs.io", "github-pages"],
10-
"library_documents_theme": ["sphinx_rtd_theme", "alabaster"],
7+
"library_description": "A short description",
8+
"library_version": "0.1.0",
9+
"library_documents_location": [
10+
"readthedocs.io",
11+
"github-pages"
12+
],
13+
"library_documents_theme": [
14+
"sphinx_rtd_theme",
15+
"alabaster"
16+
],
1117
"__library_name": "{{ cookiecutter.git_repo_name.lower().replace(' ', '_').replace('-', '_') }}",
12-
"minimum_python_version": ["3.9", "3.10", "3.11", "3.12", "3.13"],
13-
"use_requests": ["n", "y"],
14-
"use_pydantic": ["n", "y"],
15-
"include_cli": ["y", "n"],
16-
"container_runtime": ["podman", "docker"],
18+
"minimum_python_version": [
19+
"3.9",
20+
"3.10",
21+
"3.11",
22+
"3.12",
23+
"3.13"
24+
],
25+
"use_requests": [
26+
"n",
27+
"y"
28+
],
29+
"use_pydantic": [
30+
"n",
31+
"y"
32+
],
33+
"include_cli": [
34+
"y",
35+
"n"
36+
],
37+
"container_runtime": [
38+
"podman",
39+
"docker"
40+
],
41+
"container_git_protocol": [
42+
"ssh",
43+
"https"
44+
],
1745
"__template_repo": "https://github.com/btr1975/cookiecutter-python-library",
18-
"__template_version": "1.0.14",
19-
"_new_lines":"\n",
46+
"__template_version": "1.0.15",
47+
"_new_lines": "\n",
2048
"_copy_without_render": [
2149
".github"
2250
],
@@ -65,6 +93,11 @@
6593
"__prompt__": "Which container runtime will be used",
6694
"podman": "Podman",
6795
"docker": "Docker"
96+
},
97+
"container_git_protocol": {
98+
"__prompt__": "Which protocol will be used for installing in the container",
99+
"ssh": "SSH",
100+
"https": "HTTPS"
68101
}
69102
}
70103
}

{{cookiecutter.git_repo_name}}/containers/Containerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ ARG build_branch=main
1313

1414
ENV BUILD_BRANCH=${build_branch}
1515

16+
{% if cookiecutter.container_git_protocol == "https" %}
17+
# This can only be used if you repo is a public repo
18+
RUN ${PIP_INSTALL_COMMAND} git+https://github.com/{{ cookiecutter.git_username }}/{{ cookiecutter.git_repo_name }}@${BUILD_BRANCH}
19+
{% endif %}
20+
21+
{% if cookiecutter.container_git_protocol == "ssh" %}
1622
RUN --mount=type=ssh,required=true \
1723
${PIP_INSTALL_COMMAND} git+ssh://git@github.com/{{ cookiecutter.git_username }}/{{ cookiecutter.git_repo_name }}@${BUILD_BRANCH}
24+
{% endif %}
1825

1926
EXPOSE 8080/tcp
2027

{{cookiecutter.git_repo_name}}/containers/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ ARG build_branch=main
1313

1414
ENV BUILD_BRANCH=${build_branch}
1515

16+
{% if cookiecutter.container_git_protocol == "https" %}
17+
# This can only be used if you repo is a public repo
18+
RUN ${PIP_INSTALL_COMMAND} git+https://github.com/{{ cookiecutter.git_username }}/{{ cookiecutter.git_repo_name }}@${BUILD_BRANCH}
19+
{% endif %}
20+
21+
{% if cookiecutter.container_git_protocol == "ssh" %}
1622
RUN --mount=type=ssh,required=true \
1723
${PIP_INSTALL_COMMAND} git+ssh://git@github.com/{{ cookiecutter.git_username }}/{{ cookiecutter.git_repo_name }}@${BUILD_BRANCH}
24+
{% endif %}
1825

1926
EXPOSE 8080/tcp
2027

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Makefile for container needs
2+
# Author: Ben Trachtenberg
3+
# Version: 1.0.0
4+
#
5+
6+
.PHONY: build-container
7+
8+
info:
9+
@echo "make options"
10+
@echo " build-container To build the container"
11+
12+
{% if cookiecutter.container_runtime == "podman" %}
13+
build-container:
14+
@echo "Building the container with build_branch=$(build_branch)"
15+
{% if cookiecutter.container_git_protocol == "https" %}
16+
@podman build --build-arg=build_branch=$(build_branch) -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:$(build_branch) -f Containerfile
17+
{% else %}
18+
@podman build --ssh=default --build-arg=build_branch=$(build_branch) -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:$(build_branch) -f Containerfile
19+
{% endif %}
20+
{% endif %}
21+
22+
{% if cookiecutter.container_runtime == "docker" %}
23+
build-container:
24+
@echo "Building the container with build_branch=$(build_branch)"
25+
{% if cookiecutter.container_git_protocol == "https" %}
26+
@docker build --build-arg=build_branch=$(build_branch) -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:$(build_branch) -f Dockerfile
27+
{% else %}
28+
@docker build --ssh=default --build-arg=build_branch=$(build_branch) -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:$(build_branch) -f Dockerfile
29+
{% endif %}
30+
{% endif %}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@ECHO OFF
2+
REM Makefile for container needs
3+
REM Author: Ben Trachtenberg
4+
REM Version: 1.0.0
5+
REM
6+
7+
SET option=%1
8+
SET build_branch=%2
9+
10+
IF "%option%" == "" (
11+
GOTO BAD_OPTIONS
12+
)
13+
14+
IF "%build_branch%" == "" (
15+
GOTO BAD_OPTIONS
16+
)
17+
18+
{% if cookiecutter.container_runtime == "podman" %}
19+
IF "%option%" == "build-container" (
20+
@ECHO "Building the container with build_branch=%build_branch%"
21+
{% if cookiecutter.container_git_protocol == "https" %}
22+
podman build --build-arg=build_branch=%build_branch% -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:%build_branch% -f Containerfile
23+
{% else %}
24+
podman build --ssh=default --build-arg=build_branch=%build_branch% -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:%build_branch% -f Containerfile
25+
{% endif %}
26+
GOTO END
27+
)
28+
{% endif %}
29+
30+
{% if cookiecutter.container_runtime == "docker" %}
31+
IF "%option%" == "build-container" (
32+
@ECHO "Building the container with build_branch=%build_branch%"
33+
{% if cookiecutter.container_git_protocol == "https" %}
34+
docker build --build-arg=build_branch=%build_branch% -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:%build_branch% -f Containerfile
35+
{% else %}
36+
docker build --ssh=default --build-arg=build_branch=%build_branch% -t {{ cookiecutter.git_repo_name }}:latest -t {{ cookiecutter.git_repo_name }}:%build_branch% -f Containerfile
37+
{% endif %}
38+
GOTO END
39+
)
40+
{% endif %}
41+
42+
43+
@ECHO make options
44+
@ECHO build-container To build the container
45+
GOTO END
46+
47+
:BAD_OPTIONS
48+
@ECHO Argument is missing
49+
@ECHO Usage: moo.bat option build_branch
50+
@ECHO.
51+
GOTO END
52+
53+
:END

0 commit comments

Comments
 (0)