Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations. #552

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# test.py in template-builder root

import os
import json
import dodo
from datetime import datetime

def get_templates_list():

templates_path = "{0}/templates".format(os.getcwd())
with os.scandir(templates_path) as p:
for entry in p:
if entry.is_dir():
yield entry.name

def document_migration_steps(template):

mypath = "{0}/templates/{1}/files".format(os.getcwd(), template)
template_link = 'https://raw.githubusercontent.com/platformsh/template-builder/master/'

def get_files(path, depth):
"""Retrieve files added to upstream templates."""
depth -= 1
with os.scandir(path) as p:
for entry in p:
file_link = entry.path.replace("{0}/".format(mypath),template_link)
yield file_link
if entry.is_dir() and depth > 0:
yield from get_files(entry.path, depth)

def get_commands(data):
# data = dodo.project_factory(template).update
commands = []
for item in data:
if isinstance(item, str):
# if 'echo' not in item and 'git' not in item and 'rsync' not in item:
if "&&" in item:
if len(item.split(" && ")) == 2:
# new_item = item.split(" && ")[1]
commands.append(item.split(" && ")[1])
# print(new_item)
# if 'composer require' in new_item or 'composer update' in new_item:
# commands.append(new_item.split(" --")[0])
# else:
# commands.append(item.split(" && ")[1])
else:
commands.append(item)
return commands

'cleanup', 'init', 'update', 'platformify', 'branch', 'push'

def get_cleanup_commands():
return get_commands(dodo.project_factory(template).cleanup)

def get_init_commands():
return get_commands(dodo.project_factory(template).init)

def get_update_commands():
return get_commands(dodo.project_factory(template).update)

def get_platformify_commands():
return get_commands(dodo.project_factory(template).platformify)

def get_branch_commands():
return get_commands(dodo.project_factory(template).branch)

def get_push_commands():
return get_commands(dodo.project_factory(template).push)

# Files.
migrate_files = list(get_files(mypath, 10))

# Commands.
cleanup_commands = get_cleanup_commands()
init_commands = get_init_commands()
update_commands = get_update_commands()
platformify_commands = get_platformify_commands()
branch_commands = get_branch_commands()
push_commands = get_push_commands()

try:
major_version = dodo.project_factory(template).major_version
except:
major_version = None
try:
remote = dodo.project_factory(template).remote
except:
remote = None
try:
imageType = dodo.project_factory(template).type
except:
imageType = None
try:
imageTypeVersion = dodo.project_factory(template).typeVersion
except:
imageTypeVersion = None

data = {
"template": template,
"type": imageType,
"type_version": imageTypeVersion,
"remote": {
"major_version": major_version,
"repository": remote,
},
"last_updated_on": datetime.today().strftime('%Y-%m-%d-%H:%M:%S'),
"migration": {
"files": migrate_files,
"commands": [
*cleanup_commands,
*init_commands,
*update_commands,
*platformify_commands,
*branch_commands,
*push_commands
]
}
}

json_data=json.dumps(data, indent = 4)
projectType = "remote"
if remote == None:
projectType = "basic"
with open("{0}/migrations/{1}/{2}.migrate.json".format(os.getcwd(), projectType, template), "w") as outfile:
outfile.write(json_data)

def run():
templates = list(get_templates_list())
for template in templates:
document_migration_steps(template)

# default_attributes = ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_platformify', 'branch', 'builddir', 'cleanup', 'commitMessage', 'composer_defaults', 'init', 'latest_tag', 'major_version', 'name', 'package_update_actions', 'platformify', 'push', 'remote', 'type', 'typeVersion', 'update', 'updateBranch', 'updateCommands']
# l_func = lambda x, y: list((set(x)- set(y))) + list((set(y)- set(x)))
# non_match = l_func(default_attributes, dir(dodo.project_factory('wordpress-composer')))
# print(non_match)
# print(dodo.project_factory('wordpress-composer').wp_modify_composer)


if __name__ == "__main__":
run()
63 changes: 63 additions & 0 deletions migrations/basic/aspnet-core.migrate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"template": "aspnet-core",
"type": "dotnet",
"type_version": "2.2",
"remote": {
"major_version": null,
"repository": null
},
"last_updated_on": "2022-02-25-13:06:48",
"migration": {
"files": [
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot/favicon.ico",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot/css",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot/css/site.css",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot/js",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot/js/site.js",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot/lib",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wwwroot/lib/.gitkeep",
"https://raw.githubusercontent.com/platformsh/template-builder/master/LICENSE",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Startup.cs",
"https://raw.githubusercontent.com/platformsh/template-builder/master/appsettings.json",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Models",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Models/ErrorViewModel.cs",
"https://raw.githubusercontent.com/platformsh/template-builder/master/PlatformshAspNetCore.csproj",
"https://raw.githubusercontent.com/platformsh/template-builder/master/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/app.config",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.gitignore",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Properties",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Properties/launchSettings.json",
"https://raw.githubusercontent.com/platformsh/template-builder/master/PlatformshAspNetCore.sln",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform.app.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/appsettings.Development.json",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Controllers",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Controllers/HomeController.cs",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Data",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Data/MyDbContext.cs",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Home",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Home/Privacy.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Home/Index.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/_ViewImports.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Shared",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Shared/_Layout.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Shared/Error.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Shared/_CookieConsentPartial.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/Shared/_ValidationScriptsPartial.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Views/_ViewStart.cshtml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/PlatformConfig",
"https://raw.githubusercontent.com/platformsh/template-builder/master/PlatformConfig/PlatformRelationship.cs",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/services.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/routes.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/Program.cs"
],
"commands": [
"rm -rf /Users/chadcarlson/template-builder/templates/aspnet-core/build/",
"git clone [email protected]:platformsh-templates/aspnet-core.git /Users/chadcarlson/template-builder/templates/aspnet-core/build/",
"rsync -aP /Users/chadcarlson/template-builder/templates/aspnet-core/files/ /Users/chadcarlson/template-builder/templates/aspnet-core/build/",
"git checkout -b updatesLocal"
]
}
}
40 changes: 40 additions & 0 deletions migrations/basic/backdrop.migrate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"template": "backdrop",
"type": "php",
"type_version": "7.3",
"remote": {
"major_version": null,
"repository": null
},
"last_updated_on": "2022-02-25-13:06:46",
"migration": {
"files": [
"https://raw.githubusercontent.com/platformsh/template-builder/master/config",
"https://raw.githubusercontent.com/platformsh/template-builder/master/config/staging",
"https://raw.githubusercontent.com/platformsh/template-builder/master/config/staging/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/config/active",
"https://raw.githubusercontent.com/platformsh/template-builder/master/config/active/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web/settings.php",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web/.gitignore",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web/settings.platformsh.php",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.editorconfig",
"https://raw.githubusercontent.com/platformsh/template-builder/master/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.gitignore",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform.app.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/services.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/routes.yaml"
],
"commands": [
"rm -rf /Users/chadcarlson/template-builder/templates/backdrop/build/",
"git clone [email protected]:platformsh-templates/backdrop.git /Users/chadcarlson/template-builder/templates/backdrop/build/",
"tar xzvf 1.21.1.tar.gz -C /Users/chadcarlson/template-builder/templates/backdrop/build/",
"rm 1.21.1.tar.gz",
"rm -rf /Users/chadcarlson/template-builder/templates/backdrop/build/web || true",
"mv /Users/chadcarlson/template-builder/templates/backdrop/build/backdrop-1.21.1 /Users/chadcarlson/template-builder/templates/backdrop/build/web",
"rsync -aP /Users/chadcarlson/template-builder/templates/backdrop/files/ /Users/chadcarlson/template-builder/templates/backdrop/build/",
"git checkout -b updatesLocal"
]
}
}
42 changes: 42 additions & 0 deletions migrations/basic/beego.migrate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"template": "beego",
"type": "golang",
"type_version": "1.16",
"remote": {
"major_version": null,
"repository": null
},
"last_updated_on": "2022-02-25-13:06:52",
"migration": {
"files": [
"https://raw.githubusercontent.com/platformsh/template-builder/master/routers",
"https://raw.githubusercontent.com/platformsh/template-builder/master/routers/router.go",
"https://raw.githubusercontent.com/platformsh/template-builder/master/go.mod",
"https://raw.githubusercontent.com/platformsh/template-builder/master/tests",
"https://raw.githubusercontent.com/platformsh/template-builder/master/tests/default_test.go",
"https://raw.githubusercontent.com/platformsh/template-builder/master/go.sum",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.editorconfig",
"https://raw.githubusercontent.com/platformsh/template-builder/master/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.gitignore",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform.app.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/controllers",
"https://raw.githubusercontent.com/platformsh/template-builder/master/controllers/services.go",
"https://raw.githubusercontent.com/platformsh/template-builder/master/controllers/default.go",
"https://raw.githubusercontent.com/platformsh/template-builder/master/views",
"https://raw.githubusercontent.com/platformsh/template-builder/master/views/index.tpl",
"https://raw.githubusercontent.com/platformsh/template-builder/master/conf",
"https://raw.githubusercontent.com/platformsh/template-builder/master/conf/app.conf",
"https://raw.githubusercontent.com/platformsh/template-builder/master/conf/conf.go",
"https://raw.githubusercontent.com/platformsh/template-builder/master/main.go",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/services.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/routes.yaml"
],
"commands": [
"rm -rf /Users/chadcarlson/template-builder/templates/beego/build/",
"git clone [email protected]:platformsh-templates/beego.git /Users/chadcarlson/template-builder/templates/beego/build/",
"rsync -aP /Users/chadcarlson/template-builder/templates/beego/files/ /Users/chadcarlson/template-builder/templates/beego/build/",
"git checkout -b updatesLocal"
]
}
}
28 changes: 28 additions & 0 deletions migrations/basic/directus.migrate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"template": "directus",
"type": "nodejs",
"type_version": "12",
"remote": {
"major_version": null,
"repository": null
},
"last_updated_on": "2022-02-25-13:06:58",
"migration": {
"files": [
"https://raw.githubusercontent.com/platformsh/template-builder/master/.environment",
"https://raw.githubusercontent.com/platformsh/template-builder/master/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.gitignore",
"https://raw.githubusercontent.com/platformsh/template-builder/master/package.json",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform.app.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/services.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/routes.yaml"
],
"commands": [
"rm -rf /Users/chadcarlson/template-builder/templates/directus/build/",
"git clone [email protected]:platformsh-templates/directus.git /Users/chadcarlson/template-builder/templates/directus/build/",
"rsync -aP /Users/chadcarlson/template-builder/templates/directus/files/ /Users/chadcarlson/template-builder/templates/directus/build/",
"git checkout -b updatesLocal"
]
}
}
Loading