SimpleDeployer 1.0.0__tar.gz → 1.2.0__tar.gz
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.
- simpledeployer-1.2.0/LICENSE +29 -0
- simpledeployer-1.2.0/PKG-INFO +56 -0
- simpledeployer-1.2.0/README.md +33 -0
- simpledeployer-1.2.0/SimpleDeployer.egg-info/PKG-INFO +56 -0
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/SimpleDeployer.egg-info/SOURCES.txt +1 -0
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/SimpleDeployer.egg-info/entry_points.txt +0 -1
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/SimpleDeployer.egg-info/requires.txt +1 -0
- simpledeployer-1.2.0/deployer/deployer.py +281 -0
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/setup.cfg +4 -4
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/setup.py +21 -14
- SimpleDeployer-1.0.0/PKG-INFO +0 -10
- SimpleDeployer-1.0.0/README.md +0 -17
- SimpleDeployer-1.0.0/SimpleDeployer.egg-info/PKG-INFO +0 -10
- SimpleDeployer-1.0.0/deployer/deployer.py +0 -89
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/SimpleDeployer.egg-info/dependency_links.txt +0 -0
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/SimpleDeployer.egg-info/top_level.txt +0 -0
- {SimpleDeployer-1.0.0 → simpledeployer-1.2.0}/deployer/__init__.py +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019, Michael Dombrowski
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SimpleDeployer
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Dead simple deployment system
|
|
5
|
+
Home-page: https://github.com/mikedombo/simpledeployer
|
|
6
|
+
Author: Michael Dombrowski
|
|
7
|
+
Author-email: michael@mikedombrowski.com
|
|
8
|
+
License: BSD-3-Clause
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: gitpython>=2.1.11
|
|
12
|
+
Requires-Dist: pyyaml>=5.1
|
|
13
|
+
Requires-Dist: click>=7.0
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: description
|
|
17
|
+
Dynamic: description-content-type
|
|
18
|
+
Dynamic: home-page
|
|
19
|
+
Dynamic: license
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: summary
|
|
23
|
+
|
|
24
|
+
# SimpleDeployer
|
|
25
|
+
|
|
26
|
+
Edit `~/.deployer/deployer.yaml` this is your config file.
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
definitions:
|
|
30
|
+
- outDir: /var/www/graphPlayground
|
|
31
|
+
repository: https://github.com/MikeDombo/graphPlayground.git
|
|
32
|
+
sourceDir: .
|
|
33
|
+
ignore:
|
|
34
|
+
- .*/* # Ignore all directories starting with ".". Ex. .git and .vscode
|
|
35
|
+
noOverwrite:
|
|
36
|
+
- .gitlab-ci.yml # If you have a local config file, for example and don't want it overwritten every time you deploy, add it here
|
|
37
|
+
postInstall: # Commands to run after the copy happens. Use this to update node_modules and similar.
|
|
38
|
+
- npm ci
|
|
39
|
+
- npm run build
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Additional options:
|
|
43
|
+
|
|
44
|
+
- branch: The branch to clone from Git
|
|
45
|
+
- deleteRemoved: Delete files from `outDir` which were deployed previously but have since been removed from the
|
|
46
|
+
repository. Default is `true`.
|
|
47
|
+
|
|
48
|
+
## Removed files
|
|
49
|
+
|
|
50
|
+
SimpleDeployer keeps a record of the files it deployed for each definition in `~/.deployer/state/`. On the next deploy,
|
|
51
|
+
any recorded file which no longer exists in the repository is deleted from `outDir`, along with directories that are
|
|
52
|
+
left empty. Only files that SimpleDeployer deployed itself are ever deleted, so anything else in `outDir` (such as
|
|
53
|
+
`node_modules` or build output from `postInstall`, or files you created) is left alone. Files matching `ignore` or
|
|
54
|
+
`noOverwrite` are never deleted.
|
|
55
|
+
|
|
56
|
+
The record is created on the first deploy, so files removed from the repository before then are not cleaned up.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# SimpleDeployer
|
|
2
|
+
|
|
3
|
+
Edit `~/.deployer/deployer.yaml` this is your config file.
|
|
4
|
+
|
|
5
|
+
```yaml
|
|
6
|
+
definitions:
|
|
7
|
+
- outDir: /var/www/graphPlayground
|
|
8
|
+
repository: https://github.com/MikeDombo/graphPlayground.git
|
|
9
|
+
sourceDir: .
|
|
10
|
+
ignore:
|
|
11
|
+
- .*/* # Ignore all directories starting with ".". Ex. .git and .vscode
|
|
12
|
+
noOverwrite:
|
|
13
|
+
- .gitlab-ci.yml # If you have a local config file, for example and don't want it overwritten every time you deploy, add it here
|
|
14
|
+
postInstall: # Commands to run after the copy happens. Use this to update node_modules and similar.
|
|
15
|
+
- npm ci
|
|
16
|
+
- npm run build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Additional options:
|
|
20
|
+
|
|
21
|
+
- branch: The branch to clone from Git
|
|
22
|
+
- deleteRemoved: Delete files from `outDir` which were deployed previously but have since been removed from the
|
|
23
|
+
repository. Default is `true`.
|
|
24
|
+
|
|
25
|
+
## Removed files
|
|
26
|
+
|
|
27
|
+
SimpleDeployer keeps a record of the files it deployed for each definition in `~/.deployer/state/`. On the next deploy,
|
|
28
|
+
any recorded file which no longer exists in the repository is deleted from `outDir`, along with directories that are
|
|
29
|
+
left empty. Only files that SimpleDeployer deployed itself are ever deleted, so anything else in `outDir` (such as
|
|
30
|
+
`node_modules` or build output from `postInstall`, or files you created) is left alone. Files matching `ignore` or
|
|
31
|
+
`noOverwrite` are never deleted.
|
|
32
|
+
|
|
33
|
+
The record is created on the first deploy, so files removed from the repository before then are not cleaned up.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SimpleDeployer
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Dead simple deployment system
|
|
5
|
+
Home-page: https://github.com/mikedombo/simpledeployer
|
|
6
|
+
Author: Michael Dombrowski
|
|
7
|
+
Author-email: michael@mikedombrowski.com
|
|
8
|
+
License: BSD-3-Clause
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: gitpython>=2.1.11
|
|
12
|
+
Requires-Dist: pyyaml>=5.1
|
|
13
|
+
Requires-Dist: click>=7.0
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: description
|
|
17
|
+
Dynamic: description-content-type
|
|
18
|
+
Dynamic: home-page
|
|
19
|
+
Dynamic: license
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: summary
|
|
23
|
+
|
|
24
|
+
# SimpleDeployer
|
|
25
|
+
|
|
26
|
+
Edit `~/.deployer/deployer.yaml` this is your config file.
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
definitions:
|
|
30
|
+
- outDir: /var/www/graphPlayground
|
|
31
|
+
repository: https://github.com/MikeDombo/graphPlayground.git
|
|
32
|
+
sourceDir: .
|
|
33
|
+
ignore:
|
|
34
|
+
- .*/* # Ignore all directories starting with ".". Ex. .git and .vscode
|
|
35
|
+
noOverwrite:
|
|
36
|
+
- .gitlab-ci.yml # If you have a local config file, for example and don't want it overwritten every time you deploy, add it here
|
|
37
|
+
postInstall: # Commands to run after the copy happens. Use this to update node_modules and similar.
|
|
38
|
+
- npm ci
|
|
39
|
+
- npm run build
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Additional options:
|
|
43
|
+
|
|
44
|
+
- branch: The branch to clone from Git
|
|
45
|
+
- deleteRemoved: Delete files from `outDir` which were deployed previously but have since been removed from the
|
|
46
|
+
repository. Default is `true`.
|
|
47
|
+
|
|
48
|
+
## Removed files
|
|
49
|
+
|
|
50
|
+
SimpleDeployer keeps a record of the files it deployed for each definition in `~/.deployer/state/`. On the next deploy,
|
|
51
|
+
any recorded file which no longer exists in the repository is deleted from `outDir`, along with directories that are
|
|
52
|
+
left empty. Only files that SimpleDeployer deployed itself are ever deleted, so anything else in `outDir` (such as
|
|
53
|
+
`node_modules` or build output from `postInstall`, or files you created) is left alone. Files matching `ignore` or
|
|
54
|
+
`noOverwrite` are never deleted.
|
|
55
|
+
|
|
56
|
+
The record is created on the first deploy, so files removed from the repository before then are not cleaned up.
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
from fnmatch import fnmatch
|
|
2
|
+
import hashlib
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
import tempfile
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Callable, Dict, Iterable, Set
|
|
9
|
+
import git
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
import click
|
|
14
|
+
import yaml
|
|
15
|
+
|
|
16
|
+
home = Path.home()
|
|
17
|
+
config_path = Path.joinpath(home, ".deployer")
|
|
18
|
+
config_file = Path.joinpath(config_path, "deployer.yaml")
|
|
19
|
+
# Records which files each definition has deployed, so files that are later removed
|
|
20
|
+
# from the repository can be removed from the output directory too.
|
|
21
|
+
state_path = Path.joinpath(config_path, "state")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@click.command()
|
|
25
|
+
@click.option("--create/--no-create", default=True,
|
|
26
|
+
help="Should automatically create config file if it doesn't already exist. "
|
|
27
|
+
"Default is to automatically create.")
|
|
28
|
+
@click.option("-f", "--file", default=config_file, type=click.Path(exists=False, file_okay=True, dir_okay=False,
|
|
29
|
+
readable=True, resolve_path=True),
|
|
30
|
+
help="Config file to use or create")
|
|
31
|
+
@click.option("--prompt", default=False, is_flag=True, help="Ask before running on each configured repository")
|
|
32
|
+
@click.option("-v", "--verbose", default=False, is_flag=True)
|
|
33
|
+
def main(create, file, prompt, verbose):
|
|
34
|
+
if type(file) is str:
|
|
35
|
+
file = Path(file)
|
|
36
|
+
if Path.exists(file):
|
|
37
|
+
with open(str(file), 'r') as cfg:
|
|
38
|
+
run(yaml.safe_load(cfg), prompt, verbose)
|
|
39
|
+
elif create:
|
|
40
|
+
try:
|
|
41
|
+
file.parent.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
cfg = open(str(file), 'w')
|
|
43
|
+
except OSError as e:
|
|
44
|
+
raise click.FileError(str(file), hint=f"unable to create example config file: {e}")
|
|
45
|
+
with cfg:
|
|
46
|
+
print(f"Creating example config file at {file}")
|
|
47
|
+
yaml.safe_dump({"definitions": [
|
|
48
|
+
{"repository": "https://github.com...",
|
|
49
|
+
"sourceDir": ".",
|
|
50
|
+
"outDir": "c:\\Users\\mikep\\Desktop\\test",
|
|
51
|
+
"ignore": [".*/*"],
|
|
52
|
+
"noOverwrite": []
|
|
53
|
+
}
|
|
54
|
+
]}, cfg)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run(config: Dict, prompt: bool, verbose=False):
|
|
58
|
+
for definition in config["definitions"]:
|
|
59
|
+
out_dir = Path(definition["outDir"]).absolute()
|
|
60
|
+
if prompt:
|
|
61
|
+
if not query_yes_no(f"Run for {definition['repository']} to write into {out_dir}?"):
|
|
62
|
+
continue
|
|
63
|
+
try:
|
|
64
|
+
# Get temp dir
|
|
65
|
+
temp_dir = Path(tempfile.mkdtemp())
|
|
66
|
+
|
|
67
|
+
# Clone requested repo with no history
|
|
68
|
+
print(f"Cloning repo {definition['repository']}" +
|
|
69
|
+
(f" branch: {definition['branch']}" if "branch" in definition else "") +
|
|
70
|
+
(f" to {temp_dir}" if verbose else ""))
|
|
71
|
+
if "branch" in definition:
|
|
72
|
+
git.Repo.clone_from(definition["repository"], temp_dir, depth=1, branch=definition["branch"])
|
|
73
|
+
else:
|
|
74
|
+
git.Repo.clone_from(definition["repository"], temp_dir, depth=1)
|
|
75
|
+
|
|
76
|
+
src_dir = temp_dir.joinpath(Path(definition.get("sourceDir", ".")))
|
|
77
|
+
ignore_patterns = definition.get("ignore", [])
|
|
78
|
+
no_overwrite_patterns = definition.get("noOverwrite", [])
|
|
79
|
+
|
|
80
|
+
# All matchers take paths relative to the source/output root, using "/" separators
|
|
81
|
+
def ignorer(rel_path, is_dir=False):
|
|
82
|
+
if is_dir and rel_path and rel_path[-1] != "/":
|
|
83
|
+
rel_path += "/"
|
|
84
|
+
return matches_any(rel_path, ignore_patterns)
|
|
85
|
+
|
|
86
|
+
def non_overwriter(rel_path):
|
|
87
|
+
return matches_any(rel_path, no_overwrite_patterns)
|
|
88
|
+
|
|
89
|
+
manifest_path = get_manifest_path(definition, out_dir)
|
|
90
|
+
previously_deployed = load_manifest(manifest_path)
|
|
91
|
+
source_files = list_source_files(str(src_dir), ignore=ignorer)
|
|
92
|
+
|
|
93
|
+
# Files we deployed last time which are no longer in the repository
|
|
94
|
+
stale = previously_deployed - source_files
|
|
95
|
+
if definition.get("deleteRemoved", True):
|
|
96
|
+
not_deleted = delete_removed(out_dir, stale, ignore=ignorer, no_overwrite=non_overwriter,
|
|
97
|
+
verbose=verbose)
|
|
98
|
+
else:
|
|
99
|
+
not_deleted = stale
|
|
100
|
+
|
|
101
|
+
copied = cp(str(src_dir), str(out_dir), ignore=ignorer, no_overwrite=non_overwriter, verbose=verbose)
|
|
102
|
+
|
|
103
|
+
# Keep tracking anything still deployed by us: freshly copied files, files we deployed before which
|
|
104
|
+
# were not overwritten this time, and removed files we did not (or could not) delete.
|
|
105
|
+
save_manifest(manifest_path, definition, out_dir,
|
|
106
|
+
copied | (previously_deployed & source_files) | not_deleted)
|
|
107
|
+
finally:
|
|
108
|
+
try:
|
|
109
|
+
if verbose:
|
|
110
|
+
print(f"Cleaning up temporary directory {str(temp_dir)}")
|
|
111
|
+
shutil.rmtree(str(temp_dir))
|
|
112
|
+
except PermissionError:
|
|
113
|
+
if verbose:
|
|
114
|
+
print(f"Failed to delete temporary directory {str(temp_dir)}")
|
|
115
|
+
|
|
116
|
+
print("Running post install scripts if any")
|
|
117
|
+
for command in definition.get("postInstall", []):
|
|
118
|
+
print(command)
|
|
119
|
+
subprocess.Popen(command, cwd=str(out_dir), stdout=sys.stdout, stderr=sys.stderr, shell=True).wait()
|
|
120
|
+
print("=" * 30)
|
|
121
|
+
print()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def matches_any(rel_path: str, patterns: Iterable[str]) -> bool:
|
|
125
|
+
return any(fnmatch(rel_path, pat) for pat in patterns)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def walk_relative(src: str):
|
|
129
|
+
"""Like os.walk, but yields the directory relative to src as a "/" separated path ("" for src itself)"""
|
|
130
|
+
for src_dir, dirs, files in os.walk(src):
|
|
131
|
+
rel_dir = os.path.relpath(src_dir, src)
|
|
132
|
+
rel_dir = "" if rel_dir == "." else Path(rel_dir).as_posix()
|
|
133
|
+
yield src_dir, rel_dir, files
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def join_rel(rel_dir: str, name: str) -> str:
|
|
137
|
+
return f"{rel_dir}/{name}" if rel_dir else name
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def list_source_files(src: str, ignore: Callable) -> Set[str]:
|
|
141
|
+
"""Relative paths of every file in src which is not ignored, i.e. every file that will be deployed"""
|
|
142
|
+
return {join_rel(rel_dir, file)
|
|
143
|
+
for _, rel_dir, files in walk_relative(src)
|
|
144
|
+
for file in files
|
|
145
|
+
if not ignore(join_rel(rel_dir, file))}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def get_manifest_path(definition: Dict, out_dir: Path) -> Path:
|
|
149
|
+
key = "\n".join([str(out_dir), definition["repository"], str(definition.get("sourceDir", "."))])
|
|
150
|
+
return state_path.joinpath(hashlib.sha256(key.encode("utf-8")).hexdigest() + ".json")
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def load_manifest(manifest_path: Path) -> Set[str]:
|
|
154
|
+
try:
|
|
155
|
+
with open(str(manifest_path), "r") as f:
|
|
156
|
+
return set(json.load(f).get("files", []))
|
|
157
|
+
except FileNotFoundError:
|
|
158
|
+
return set()
|
|
159
|
+
except (OSError, ValueError, AttributeError) as e:
|
|
160
|
+
print(f"Unable to read deployment record {manifest_path}, removed files will not be deleted this time: {e}")
|
|
161
|
+
return set()
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def save_manifest(manifest_path: Path, definition: Dict, out_dir: Path, files: Set[str]):
|
|
165
|
+
manifest_path.parent.mkdir(parents=True, exist_ok=True)
|
|
166
|
+
tmp_path = manifest_path.with_suffix(".tmp")
|
|
167
|
+
with open(str(tmp_path), "w") as f:
|
|
168
|
+
json.dump({"repository": definition["repository"],
|
|
169
|
+
"sourceDir": str(definition.get("sourceDir", ".")),
|
|
170
|
+
"outDir": str(out_dir),
|
|
171
|
+
"files": sorted(files)}, f, indent=2)
|
|
172
|
+
os.replace(str(tmp_path), str(manifest_path))
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def is_within(path: Path, root: Path) -> bool:
|
|
176
|
+
try:
|
|
177
|
+
path.relative_to(root)
|
|
178
|
+
return True
|
|
179
|
+
except ValueError:
|
|
180
|
+
return False
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def delete_removed(out_dir: Path, stale: Iterable[str], ignore: Callable, no_overwrite: Callable,
|
|
184
|
+
verbose: bool) -> Set[str]:
|
|
185
|
+
"""
|
|
186
|
+
Delete files which were previously deployed into out_dir but no longer exist in the source.
|
|
187
|
+
Files matching an ignore or noOverwrite pattern are left alone. Directories left empty are removed.
|
|
188
|
+
Returns the files which should have been deleted but could not be, so that they stay tracked.
|
|
189
|
+
"""
|
|
190
|
+
not_deleted = set()
|
|
191
|
+
root = out_dir.resolve()
|
|
192
|
+
for rel_path in sorted(stale):
|
|
193
|
+
if ignore(rel_path) or no_overwrite(rel_path):
|
|
194
|
+
if verbose:
|
|
195
|
+
print(f"Not deleting removed file because it is ignored or not allowed to be overwritten {rel_path}")
|
|
196
|
+
continue
|
|
197
|
+
|
|
198
|
+
parts = rel_path.split("/")
|
|
199
|
+
target = out_dir.joinpath(*parts)
|
|
200
|
+
# Never follow ".." or a symlinked parent directory out of the output directory
|
|
201
|
+
if ".." in parts or Path(rel_path).is_absolute() or not is_within(target.parent.resolve(), root):
|
|
202
|
+
print(f"Not deleting {target} because it is outside of {out_dir}")
|
|
203
|
+
continue
|
|
204
|
+
|
|
205
|
+
if target.is_symlink() or target.is_file():
|
|
206
|
+
print(f"Deleting removed file {target}")
|
|
207
|
+
try:
|
|
208
|
+
target.unlink()
|
|
209
|
+
except OSError as e:
|
|
210
|
+
print(e)
|
|
211
|
+
not_deleted.add(rel_path)
|
|
212
|
+
continue
|
|
213
|
+
elif target.exists():
|
|
214
|
+
print(f"Not deleting {target} because it is now a directory")
|
|
215
|
+
continue
|
|
216
|
+
|
|
217
|
+
# Clean up directories which are now empty, up to (but not including) out_dir itself
|
|
218
|
+
parent = target.parent
|
|
219
|
+
while parent != out_dir and is_within(parent, out_dir):
|
|
220
|
+
try:
|
|
221
|
+
parent.rmdir()
|
|
222
|
+
except OSError:
|
|
223
|
+
break # Not empty, or not removable
|
|
224
|
+
if verbose:
|
|
225
|
+
print(f"Deleted empty directory {parent}")
|
|
226
|
+
parent = parent.parent
|
|
227
|
+
return not_deleted
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def cp(src, dest, ignore, no_overwrite, verbose) -> Set[str]:
|
|
231
|
+
"""Copy src into dest, returning the relative paths of the files which were copied"""
|
|
232
|
+
copied = set()
|
|
233
|
+
for src_dir, rel_dir, files in walk_relative(src):
|
|
234
|
+
dst_dir = os.path.join(dest, rel_dir) if rel_dir else dest
|
|
235
|
+
if not os.path.exists(dst_dir) and not ignore(rel_dir, True):
|
|
236
|
+
Path(dst_dir).mkdir(parents=True, exist_ok=True)
|
|
237
|
+
for file in files:
|
|
238
|
+
rel_file = join_rel(rel_dir, file)
|
|
239
|
+
src_file = os.path.join(src_dir, file)
|
|
240
|
+
dst_file = os.path.join(dst_dir, file)
|
|
241
|
+
if not ignore(rel_file):
|
|
242
|
+
allowed_to_overwrite = not no_overwrite(rel_file)
|
|
243
|
+
if not os.path.exists(dst_file) or allowed_to_overwrite:
|
|
244
|
+
try:
|
|
245
|
+
shutil.copy2(src_file, dst_dir)
|
|
246
|
+
copied.add(rel_file)
|
|
247
|
+
except PermissionError as e:
|
|
248
|
+
print(e)
|
|
249
|
+
elif not allowed_to_overwrite and verbose:
|
|
250
|
+
print(f"Skipping because file exists and not allowed to overwrite {dst_file}")
|
|
251
|
+
elif verbose:
|
|
252
|
+
print(f"Ignoring {src_file}")
|
|
253
|
+
return copied
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def query_yes_no(question, default="yes"):
|
|
257
|
+
valid = {"yes": True, "y": True, "ye": True,
|
|
258
|
+
"no": False, "n": False}
|
|
259
|
+
if default is None:
|
|
260
|
+
prompt = " [y/n] "
|
|
261
|
+
elif default == "yes":
|
|
262
|
+
prompt = " [Y/n] "
|
|
263
|
+
elif default == "no":
|
|
264
|
+
prompt = " [y/N] "
|
|
265
|
+
else:
|
|
266
|
+
raise ValueError("invalid default answer: '%s'" % default)
|
|
267
|
+
|
|
268
|
+
while True:
|
|
269
|
+
sys.stdout.write(question + prompt)
|
|
270
|
+
choice = input().lower()
|
|
271
|
+
if default is not None and choice == '':
|
|
272
|
+
return valid[default]
|
|
273
|
+
elif choice in valid:
|
|
274
|
+
return valid[choice]
|
|
275
|
+
else:
|
|
276
|
+
sys.stdout.write("Please respond with 'yes' or 'no' "
|
|
277
|
+
"(or 'y' or 'n').\n")
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
if __name__ == "__main__":
|
|
281
|
+
main()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[egg_info]
|
|
2
|
-
tag_build =
|
|
3
|
-
tag_date = 0
|
|
4
|
-
|
|
1
|
+
[egg_info]
|
|
2
|
+
tag_build =
|
|
3
|
+
tag_date = 0
|
|
4
|
+
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
from os import path
|
|
4
|
+
this_directory = path.abspath(path.dirname(__file__))
|
|
5
|
+
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
|
|
6
|
+
long_description = f.read()
|
|
7
|
+
|
|
8
|
+
setup(
|
|
9
|
+
name="SimpleDeployer",
|
|
10
|
+
version="1.2.0",
|
|
11
|
+
url="https://github.com/mikedombo/simpledeployer",
|
|
12
|
+
license="BSD-3-Clause",
|
|
13
|
+
author="Michael Dombrowski",
|
|
14
|
+
entry_points={"console_scripts": ["simpledeployer=deployer.deployer:main"]},
|
|
15
|
+
install_requires=["gitpython>=2.1.11", "pyyaml>=5.1", "click>=7.0"],
|
|
16
|
+
packages=find_packages(),
|
|
17
|
+
author_email="michael@mikedombrowski.com",
|
|
18
|
+
description="Dead simple deployment system",
|
|
19
|
+
long_description=long_description,
|
|
20
|
+
long_description_content_type='text/markdown'
|
|
21
|
+
)
|
SimpleDeployer-1.0.0/PKG-INFO
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.0
|
|
2
|
-
Name: SimpleDeployer
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: Dead simple deployment system
|
|
5
|
-
Home-page: https://github.com/mikedombo/simpledeployer
|
|
6
|
-
Author: Michael Dombrowski
|
|
7
|
-
Author-email: michael@mikedombrowski.com
|
|
8
|
-
License: BSD-3-Clause
|
|
9
|
-
Description: UNKNOWN
|
|
10
|
-
Platform: UNKNOWN
|
SimpleDeployer-1.0.0/README.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# SimpleDeployer
|
|
2
|
-
|
|
3
|
-
Edit `~/.deployer/deployer.yaml` this is your config file.
|
|
4
|
-
|
|
5
|
-
```yaml
|
|
6
|
-
definitions:
|
|
7
|
-
- outDir: /var/www/graphPlayground
|
|
8
|
-
repository: https://github.com/MikeDombo/graphPlayground.git
|
|
9
|
-
sourceDir: .
|
|
10
|
-
ignore:
|
|
11
|
-
- .*/* # Ignore all directories starting with ".". Ex. .git and .vscode
|
|
12
|
-
noOverwrite:
|
|
13
|
-
- .gitlab-ci.yml # If you have a local config file, for example and don't want it overwritten every time you deploy, add it here
|
|
14
|
-
postInstall: # Commands to run after the copy happens. Use this to update node_modules and similar.
|
|
15
|
-
- npm ci
|
|
16
|
-
- npm run build
|
|
17
|
-
```
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.0
|
|
2
|
-
Name: SimpleDeployer
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: Dead simple deployment system
|
|
5
|
-
Home-page: https://github.com/mikedombo/simpledeployer
|
|
6
|
-
Author: Michael Dombrowski
|
|
7
|
-
Author-email: michael@mikedombrowski.com
|
|
8
|
-
License: BSD-3-Clause
|
|
9
|
-
Description: UNKNOWN
|
|
10
|
-
Platform: UNKNOWN
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
from fnmatch import fnmatch
|
|
2
|
-
import os
|
|
3
|
-
import shutil
|
|
4
|
-
import tempfile
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from typing import Dict
|
|
7
|
-
import git
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
|
|
11
|
-
import yaml
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def main():
|
|
15
|
-
home = Path.home()
|
|
16
|
-
config_path = Path.joinpath(home, ".deployer")
|
|
17
|
-
config_file = Path.joinpath(config_path, "deployer.yaml")
|
|
18
|
-
|
|
19
|
-
if Path.exists(config_file):
|
|
20
|
-
with open(str(config_file), 'r') as cfg:
|
|
21
|
-
run(yaml.safe_load(cfg))
|
|
22
|
-
else:
|
|
23
|
-
config_path.mkdir(parents=True, exist_ok=True)
|
|
24
|
-
with open(str(config_file), 'w') as cfg:
|
|
25
|
-
yaml.safe_dump({"definitions": [
|
|
26
|
-
{"repository": "https://github.com...",
|
|
27
|
-
"sourceDir": ".",
|
|
28
|
-
"outDir": "c:\\Users\\mikep\\Desktop\\test",
|
|
29
|
-
"ignore": [".*/*"],
|
|
30
|
-
"noOverwrite": []
|
|
31
|
-
}
|
|
32
|
-
]}, cfg)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def run(config: Dict):
|
|
36
|
-
for definition in config["definitions"]:
|
|
37
|
-
try:
|
|
38
|
-
# Get temp dir
|
|
39
|
-
temp_dir = Path(tempfile.mkdtemp())
|
|
40
|
-
|
|
41
|
-
# Clone requested repo with no history
|
|
42
|
-
git.Repo.clone_from(definition["repository"], temp_dir, depth=1)
|
|
43
|
-
|
|
44
|
-
src_dir = temp_dir.joinpath(Path(definition.get("sourceDir", ".")))
|
|
45
|
-
out_dir = Path(definition["outDir"]).absolute()
|
|
46
|
-
|
|
47
|
-
def ignorer(path, isDir=False):
|
|
48
|
-
path = str(Path(path).as_posix())
|
|
49
|
-
path = path[len(str(src_dir))+1:]
|
|
50
|
-
if isDir and path and path[-1] != "/":
|
|
51
|
-
path += "/"
|
|
52
|
-
|
|
53
|
-
return any(fnmatch(path, pat) for pat in definition.get("ignore", []))
|
|
54
|
-
|
|
55
|
-
def nonOverwriter(path):
|
|
56
|
-
path = str(Path(path).as_posix())
|
|
57
|
-
path = path[len(str(src_dir)) + 1:]
|
|
58
|
-
return any(fnmatch(path, pat) for pat in definition.get("noOverwrite", []))
|
|
59
|
-
|
|
60
|
-
cp(str(src_dir), str(out_dir), ignore=ignorer, noOverwrite=nonOverwriter)
|
|
61
|
-
finally:
|
|
62
|
-
try:
|
|
63
|
-
shutil.rmtree(str(temp_dir))
|
|
64
|
-
except PermissionError:
|
|
65
|
-
pass
|
|
66
|
-
|
|
67
|
-
for command in definition.get("postInstall", []):
|
|
68
|
-
print(command)
|
|
69
|
-
subprocess.Popen(command, cwd=str(out_dir), stdout=sys.stdout, stderr=sys.stderr, shell=True).wait()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def cp(src, dest, ignore, noOverwrite):
|
|
73
|
-
for src_dir, dirs, files in os.walk(src):
|
|
74
|
-
dst_dir = src_dir.replace(src, dest)
|
|
75
|
-
if not os.path.exists(dst_dir) and not ignore(src_dir, True):
|
|
76
|
-
os.mkdir(dst_dir)
|
|
77
|
-
for file in files:
|
|
78
|
-
src_file = os.path.join(src_dir, file)
|
|
79
|
-
dst_file = os.path.join(dst_dir, file)
|
|
80
|
-
if not ignore(src_file):
|
|
81
|
-
if not os.path.exists(dst_file) or not noOverwrite(src_file):
|
|
82
|
-
try:
|
|
83
|
-
shutil.copy2(src_file, dst_dir)
|
|
84
|
-
except PermissionError as e:
|
|
85
|
-
print(e)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if __name__ == "__main__":
|
|
89
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|