travis2docker 7.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,162 @@
1
+ # pylint: disable=useless-object-inheritance,consider-using-with,print-used
2
+ import pathlib
3
+ import re
4
+ import shutil
5
+ import stat
6
+ from tempfile import gettempdir
7
+
8
+ import jinja2
9
+
10
+ RE_ENV_STR = r"(?P<var>[\w]*)[ ]*[\=][ ]*[\"\']{0,1}" + r"(?P<value>[\w\.\-\_/\$\{\}\:,\(\)\#\* ]*)[\"\']{0,1}"
11
+ RE_EXPORT_STR = r"^(?P<export>export|EXPORT)( )+" + RE_ENV_STR
12
+
13
+
14
+ class Travis2Docker:
15
+ re_export = re.compile(RE_EXPORT_STR, re.MULTILINE)
16
+
17
+ @property
18
+ def dockerfile_template(self):
19
+ return self.jinja_env.get_template("Dockerfile_deployv")
20
+
21
+ @property
22
+ def new_image(self):
23
+ image_name = "%(repo_owner)s-%(repo_project)s" % self.os_kwargs
24
+ revision = self.os_kwargs["revision"]
25
+ for invalid_char in "@:/#.":
26
+ image_name = image_name.replace(invalid_char, "_")
27
+ revision = revision.replace(invalid_char, "_")
28
+ return ("%s:%s" % (image_name, revision)).lower()
29
+
30
+ @property
31
+ def build_template(self):
32
+ return self.jinja_env.get_template("10-build.sh")
33
+
34
+ @property
35
+ def run_template(self):
36
+ return self.jinja_env.get_template("20-run.sh")
37
+
38
+ @staticmethod
39
+ def chmod_execution(file_path):
40
+ file_path.chmod(file_path.stat().st_mode | stat.S_IEXEC)
41
+
42
+ def __init__(
43
+ self,
44
+ image=None,
45
+ work_path=None,
46
+ dockerfile=None,
47
+ templates_path=None,
48
+ os_kwargs=None,
49
+ copy_paths=None,
50
+ build_env_args=None,
51
+ build_extra_steps=None,
52
+ ):
53
+ self.curr_work_path = None
54
+ self.build_extra_params = {}
55
+ self.run_extra_params = {}
56
+ self.build_env_args = build_env_args
57
+ self.build_extra_steps = build_extra_steps
58
+ if os_kwargs is None:
59
+ os_kwargs = {}
60
+ if copy_paths is None:
61
+ copy_paths = []
62
+ self.variables_sh_data = {
63
+ var.lower(): value for _, _, var, value in self.re_export.findall(os_kwargs["variables_sh"])
64
+ }
65
+ self.variables_sh_data.update({"sha_short": os_kwargs["sha"][:7]})
66
+ if not image:
67
+ image = "%(docker_image_repo)s:%(main_app)s-%(version)s-%(sha_short)s" % self.variables_sh_data
68
+ module_dir = pathlib.Path(__file__).resolve().parent
69
+ templates_dir = module_dir / "templates"
70
+ copy_paths.append([templates_dir / "build.sh", "/home/odoo/build.sh"])
71
+ copy_paths.append([templates_dir / "entrypoint_deployv.sh", "/entrypoint.sh"])
72
+ copy_paths.append([module_dir / "docker_helper", "/home/odoo/build"])
73
+ copy_paths.append([templates_dir / ".vscode", "/home/odoo/.vscode"])
74
+ copy_paths.append([templates_dir / ".coveragerc", "/home/odoo/.coveragerc"])
75
+ os_kwargs.setdefault("user", "odoo")
76
+ if dockerfile is None:
77
+ dockerfile = "Dockerfile"
78
+ if templates_path is None:
79
+ templates_path = templates_dir
80
+ self.copy_paths = copy_paths
81
+ self.os_kwargs = os_kwargs
82
+ self.jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_path))
83
+ self.image = image
84
+ if work_path is None:
85
+ self.work_path = pathlib.Path(gettempdir()) / pathlib.Path(__file__).stem
86
+ else:
87
+ self.work_path = pathlib.Path(work_path).expanduser()
88
+ self.dockerfile = dockerfile
89
+
90
+ def compute_build_scripts(self):
91
+ build_path = self.curr_work_path / "10-build.sh"
92
+ run_path = self.curr_work_path / "20-run.sh"
93
+ with build_path.open("w") as f_build, run_path.open("w") as f_run:
94
+ build_content = self.build_template.render(
95
+ image=self.new_image, dirname_dockerfile=self.curr_work_path, **self.build_extra_params
96
+ ).strip("\n ")
97
+ f_build.write(build_content)
98
+ run_content = self.run_template.render(image=self.new_image, **self.run_extra_params).strip("\n ")
99
+ f_run.write(run_content)
100
+ self.chmod_execution(build_path)
101
+ self.chmod_execution(run_path)
102
+
103
+ def compute_dockerfile(self):
104
+ self.curr_work_path = self.work_path
105
+ curr_dockerfile = self.curr_work_path / self.dockerfile
106
+ self.curr_work_path.mkdir(exist_ok=True, parents=True)
107
+ copies = []
108
+ for copy_path, dest in self.copy_paths:
109
+ copies.append((self.copy_path(copy_path), dest))
110
+ self.set_authorized_key()
111
+ kwargs = {
112
+ "copies": copies,
113
+ "image": self.image,
114
+ "build_env_args": self.build_env_args,
115
+ "build_extra_steps": self.build_extra_steps,
116
+ }
117
+ kwargs.update(self.os_kwargs)
118
+ with curr_dockerfile.open("w") as f_dockerfile:
119
+ dockerfile_content = self.dockerfile_template.render(kwargs).strip("\n ")
120
+ f_dockerfile.write(dockerfile_content)
121
+ self.compute_build_scripts()
122
+ work_paths = [str(self.curr_work_path)]
123
+ self.curr_work_path = None
124
+ return work_paths
125
+
126
+ def copy_path(self, path):
127
+ """:param paths list: List of paths to copy"""
128
+ src = pathlib.Path(path).expanduser()
129
+ dest_path = self.curr_work_path / src.name
130
+ if dest_path.is_dir():
131
+ shutil.rmtree(dest_path)
132
+ if src.is_dir():
133
+ try:
134
+ shutil.copytree(src, dest_path)
135
+ except shutil.Error: # pylint: disable=except-pass
136
+ pass # There are permissions errors to copy
137
+ elif src.is_file():
138
+ shutil.copy(src, dest_path)
139
+ else:
140
+ raise UserWarning("Just directory or file is supported to copy [%s]" % src)
141
+ return str(dest_path.relative_to(self.curr_work_path))
142
+
143
+ def set_authorized_key(self):
144
+ ssh_dir = pathlib.Path("~/.ssh").expanduser()
145
+ ed_key = ssh_dir / "id_ed25519.pub"
146
+ rsa_key = ssh_dir / "id_rsa.pub"
147
+
148
+ to_copy = None
149
+ if ed_key.is_file():
150
+ to_copy = ed_key
151
+ elif rsa_key.is_file():
152
+ print("RSA keys are deprecated, consider changing to ed25519")
153
+ to_copy = rsa_key
154
+
155
+ if not to_copy:
156
+ print("No public key found. No key added to ~/.ssh/authorized_keys. SSH login won't work.")
157
+ return
158
+
159
+ pub_key = to_copy.read_text(encoding="utf-8")
160
+
161
+ with (self.curr_work_path / ".ssh" / "authorized_keys").open("a", encoding="utf-8") as auth_fd:
162
+ auth_fd.write(pub_key)
@@ -0,0 +1,268 @@
1
+ Metadata-Version: 2.4
2
+ Name: travis2docker
3
+ Version: 7.0.0
4
+ Summary: Script to generate a development Dockerfile from the deployv image of a repository
5
+ Home-page: https://github.com/vauxoo/travis2docker
6
+ Author: Vauxoo
7
+ Author-email: info@vauxoo.com
8
+ License: BSD-3-Clause
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: Unix
12
+ Classifier: Operating System :: POSIX
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: 3.15
22
+ Classifier: Programming Language :: Python :: Implementation :: CPython
23
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
24
+ Classifier: Topic :: Utilities
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/x-rst
27
+ License-File: LICENSE
28
+ License-File: AUTHORS.rst
29
+ Requires-Dist: Jinja2==3.1.*
30
+ Dynamic: author
31
+ Dynamic: author-email
32
+ Dynamic: classifier
33
+ Dynamic: description
34
+ Dynamic: description-content-type
35
+ Dynamic: home-page
36
+ Dynamic: license
37
+ Dynamic: license-file
38
+ Dynamic: requires-dist
39
+ Dynamic: requires-python
40
+ Dynamic: summary
41
+
42
+ ========
43
+ Overview
44
+ ========
45
+
46
+
47
+
48
+ Script to generate a development Dockerfile from the deployv image of a repository (based on its ``variables.sh`` file)
49
+
50
+ * Free software: BSD license
51
+
52
+ Installation
53
+ ============
54
+
55
+ ::
56
+
57
+ pip install travis2docker
58
+
59
+ Usage
60
+ =====
61
+
62
+ `travisfile2dockerfile REPO_URL BRANCH`
63
+
64
+ Or with pull request
65
+ `travisfile2dockerfile REPO_URL pull/##`
66
+
67
+ In REPO_URL use the ssh url of github.
68
+
69
+ For more information execute:
70
+ `travisfile2dockerfile --help`
71
+
72
+ Example:
73
+ `travisfile2dockerfile --root-path=$HOME/t2d git@github.com:Vauxoo/forecast.git 8.0`
74
+
75
+ The output is:
76
+ `${HOME}/t2d/script/git_github.com_Vauxoo_forecast.git/8.0`
77
+
78
+ To build image:
79
+ `${HOME}/t2d/script/git_github.com_Vauxoo_forecast.git/8.0/10-build.sh`
80
+
81
+ To create container:
82
+ `${HOME}/t2d/script/git_github.com_Vauxoo_forecast.git/8.0/20-run.sh --entrypoint=bash`
83
+
84
+ The repository needs a ``variables.sh`` file in its root path (the one used by
85
+ the deployv images built from the CI). By default the docker image is built
86
+ from its values as ``DOCKER_IMAGE_REPO:MAIN_APP-VERSION-SHA_SHORT``; use
87
+ ``--docker-image=quay.io/vauxoo/PROJECT:TAG`` to pick the image pushed by the
88
+ ``build_docker`` pipeline instead.
89
+
90
+ Optional tools (``--build-env-args``)
91
+ =====================================
92
+
93
+ Some development tools are **not** installed by default. They are enabled with
94
+ a flag passed as a build environment variable using ``--build-env-args``, which
95
+ generates an ``ENV <FLAG>=TRUE`` line in the Dockerfile. If the flag is not
96
+ defined, the installation step is skipped.
97
+
98
+ .. list-table::
99
+ :widths: 30 70
100
+ :header-rows: 1
101
+
102
+ * - Flag
103
+ - Installs
104
+ * - ``VIM_INSTALL``
105
+ - vim + spf13-vim, vim-openerp, jedi-vim, wakatime and the pylint_odoo/eslint syntastic configuration
106
+ * - ``ZSH_INSTALL``
107
+ - zsh + oh-my-zsh with the ``odoo-shippable`` theme
108
+
109
+ Example enabling more than one::
110
+
111
+ travisfile2dockerfile --build-env-args VIM_INSTALL ZSH_INSTALL \
112
+ git@github.com:Vauxoo/forecast.git 8.0
113
+
114
+ codebase-memory-deployv
115
+ =======================
116
+
117
+ The image ships with `codebase-memory-deployv
118
+ <https://pypi.org/project/codebase-memory-deployv>`__, a wrapper that deploys
119
+ `codebase-memory-mcp <https://github.com/DeusData/codebase-memory-mcp>`__
120
+ (code knowledge graph for AI agents) for instances following this layout.
121
+
122
+ The repository is **not** indexed while building the image. Run inside the
123
+ container::
124
+
125
+ codebase-memory-deployv
126
+
127
+ It installs codebase-memory-mcp if it is missing, derives the project name from
128
+ ``${MAIN_REPO_FULL_PATH}/variables.sh`` (e.g. ``forecast_17.0``), and indexes
129
+ ``/home/odoo/instance`` in batches of modules. Indexing takes a few minutes on
130
+ a big instance, so it is left as an explicit step for the user.
131
+
132
+ Depends
133
+ =======
134
+
135
+ SSH key without password
136
+ ************************
137
+
138
+ Dockerfile doesn't support a prompt to enter your password, so you need to remove it from your ssh keys.
139
+
140
+ ::
141
+
142
+ export fname=~/.ssh/id_rsa
143
+ cp ${fname} ${fname}_with_pwd
144
+ openssl rsa -in ${fname} -out ${fname}_without_pwd
145
+ cp ${fname}_without_pwd ${fname}
146
+
147
+ Install docker
148
+ **************
149
+
150
+ https://docs.docker.com/engine/installation/
151
+
152
+ Documentation
153
+ =============
154
+
155
+ https://travis2docker.readthedocs.io/
156
+
157
+ Development
158
+ ===========
159
+
160
+ To run the all tests run::
161
+
162
+ tox
163
+
164
+ Note, to combine the coverage data from all the tox environments run:
165
+
166
+ .. list-table::
167
+ :widths: 10 90
168
+ :stub-columns: 1
169
+
170
+ - - Windows
171
+ - ::
172
+
173
+ set PYTEST_ADDOPTS=--cov-append
174
+ tox
175
+
176
+ - - Other
177
+ - ::
178
+
179
+ PYTEST_ADDOPTS=--cov-append tox
180
+
181
+
182
+ Release process
183
+ ===============
184
+
185
+ This project uses `bump2version <https://github.com/c4urself/bump2version>`_ to
186
+ manage version bumps across ``.bumpversion.cfg``, ``docs/conf.py``,
187
+ ``setup.py`` and ``src/travis2docker/__init__.py``.
188
+
189
+ Requirements
190
+ ************
191
+
192
+ * Write access to push to ``main`` and to push tags.
193
+ * A GPG key configured for signing git tags. The CI pipeline that publishes
194
+ the package to PyPI only builds from **signed** tags::
195
+
196
+ git config --global user.signingkey <YOUR_GPG_KEY_ID>
197
+
198
+ * ``bump2version`` installed::
199
+
200
+ pip install bump2version
201
+
202
+ Steps to release a new version
203
+ ******************************
204
+
205
+
206
+ 1. Make sure you are on ``main`` and it is up to date, with no local commits
207
+ ahead of ``origin``::
208
+
209
+ git checkout main
210
+ git pull origin main
211
+ git status # must be clean
212
+
213
+ 2. Bump the version. This creates a commit and a tag automatically
214
+ (choose ``patch``, ``minor`` or ``major`` as needed)::
215
+
216
+ bump2version patch
217
+
218
+ This updates::
219
+
220
+ .bumpversion.cfg
221
+ docs/conf.py
222
+ setup.py
223
+ src/travis2docker/__init__.py
224
+
225
+ 3. Verify the tag was created and that it is **signed**::
226
+
227
+ git tag -v vX.Y.Z
228
+
229
+ If ``sign_tags`` is not enabled in ``.bumpversion.cfg``, the tag created
230
+ in step 2 will **not** be signed and the CI build/publish step will not
231
+ run. In that case, re-create the tag manually before pushing::
232
+
233
+ git tag -d vX.Y.Z
234
+ git tag -s vX.Y.Z -m "vX.Y.Z"
235
+
236
+ To avoid this every time, add the following to ``.bumpversion.cfg``::
237
+
238
+ [bumpversion]
239
+ current_version = X.Y.Z
240
+ commit = True
241
+ tag = True
242
+ sign_tags = True
243
+
244
+ 4. Push the branch and the tag::
245
+
246
+ git push origin main --tags
247
+
248
+ Pushing the signed tag is what triggers the CI job that builds and
249
+ publishes the package to PyPI.
250
+
251
+ Troubleshooting
252
+ ***************
253
+
254
+ * **"tag already exists" / dirty working tree**: make sure ``git status`` is
255
+ clean and ``git pull origin main`` was run before ``bump2version``,
256
+ otherwise the bump commit/tag will be based on stale history.
257
+ * **CI does not trigger a PyPI build**: check that the pushed tag is signed
258
+ (``git tag -v vX.Y.Z`` should show a valid GPG signature) and that
259
+ ``user.signingkey`` is configured correctly.
260
+
261
+
262
+ Changelog
263
+ =========
264
+
265
+ 3.0.0 (2016-07-26)
266
+ ******************
267
+
268
+ * First release on PyPI.
@@ -0,0 +1,23 @@
1
+ travis2docker/__init__.py,sha256=VgMOOqsYbyb60I1RmlZpqwqQ0C0IyT3R0c8_xX4pRGM,22
2
+ travis2docker/__main__.py,sha256=WqseXLnYDF9u77kkfkWSNQmmqbloKs6jB_6SuYdqxDU,360
3
+ travis2docker/cli.py,sha256=x4fPZnTZ_QmP83facpAzIbuoNJHchjdVxgxTHuv8ZcI,10294
4
+ travis2docker/exceptions.py,sha256=03fh-vq7OIxnV-mdZlJOXaPmpuuaJ4bWAyjjICTPb4U,164
5
+ travis2docker/git_run.py,sha256=hGAjZshe6hgs_IK5iweveojD-QZdxPLSWpfOvXX3W58,4053
6
+ travis2docker/travis2docker.py,sha256=3yIQuYLuOjTQJCK2DX1m4fpnZWFHzBPXPUhLjMBJKt4,6357
7
+ travis2docker/docker_helper/build.py,sha256=j3Ie0uohdqF4uSk0DA_7Tt78CeNPTvsZMKwIGJILmgQ,3181
8
+ travis2docker/templates/.coveragerc,sha256=2r1H579-4RtUvI9yIUvNRTDcdn--OFaG4m4rx6S7PdA,1001
9
+ travis2docker/templates/10-build.sh,sha256=1c6l2M5HncVD0Ci8l7Eo5W9Wf2D1lc7J57mg_JY5JLo,131
10
+ travis2docker/templates/20-run.sh,sha256=qKqbuXQ5ZgyUwnAnIwtV5-VHa9SHY1VZ37GAeNwGSVg,688
11
+ travis2docker/templates/Dockerfile_deployv,sha256=uIWcdjMgxMiX2JVfpWllnAzq82uEG6QDNaVmvKNbw2A,1541
12
+ travis2docker/templates/build.sh,sha256=rsMa5pmNGrBbK3EZdS45eODMfxXfVADUId4zcv8ojpk,13546
13
+ travis2docker/templates/entrypoint_deployv.sh,sha256=OFJSfWOuyAYutr6Tdq3usrXmG7-Fv6YYhCe4DzFcgw8,3750
14
+ travis2docker/templates/.vscode/extensions.json,sha256=gfizS2OHGvKWXo-y0Q7oj4UyvFCGLdusglh8xLo_vuE,348
15
+ travis2docker/templates/.vscode/launch.json,sha256=WkyQDKy_oS2CrqcaxivYbN9V00MSZGZUpva2cogNVLQ,842
16
+ travis2docker/templates/.vscode/settings.json,sha256=ymRKw7lpudvSRk5oJFlb1jZsdCVuBmgSpmAF848bH5Y,436
17
+ travis2docker-7.0.0.dist-info/licenses/AUTHORS.rst,sha256=5F1EtJ9_HPOlWYSO5YznKQdhPrdWpLAJkemyhRRtUis,53
18
+ travis2docker-7.0.0.dist-info/licenses/LICENSE,sha256=bgW3tu3ZoMF92osxQEVZ62pRV61kN8YrRwmeSpKx_ks,1285
19
+ travis2docker-7.0.0.dist-info/METADATA,sha256=0TxodLsIKEztqLodE4AqVLuGiVjye-j03W44MzBiGBc,7348
20
+ travis2docker-7.0.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
21
+ travis2docker-7.0.0.dist-info/entry_points.txt,sha256=V-QtEHdMvHrLLRJOHHhvy0oMUI-yLYPxnTQ_f24Y6pA,65
22
+ travis2docker-7.0.0.dist-info/top_level.txt,sha256=oCQJpJtAbfaMnh6ahkgn6d-RLqofWNZ_iNoEiIOUkpY,14
23
+ travis2docker-7.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ travisfile2dockerfile = travis2docker.cli:main
@@ -0,0 +1,5 @@
1
+
2
+ Authors
3
+ =======
4
+
5
+ * Vauxoo - https://www.vauxoo.com/
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016, Vauxoo
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5
+ following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8
+ disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11
+ disclaimer in the documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
14
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
18
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
19
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ travis2docker