Add build rules for "nocron" deployments

Add build rules for creating "nocron" war and ear files for use during
database restores in production and alpha.

After a little consideration, I think this is the right way to do this.  If we
want to set it up in other environments, we'll need to add these rules for
them, too, and at that point it may be worthwhile to wrap the rules we want in
a macro, but for now this is fairly clear and not execessively redundant.

This change works by modifying the zip_file rule to allow us to exclude
"cron.xml".  I have verified that:

- The alpha "nocron" files are generated without cron.xml.
- The production "nocron" files are generated without cron.xml.
- I can do a full push to alpha based on deploy_nocron which doesn't install a
  new cron.
- The normal production and alpha war-files _do_ contain cron.xml.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=153853205
This commit is contained in:
mmuller 2017-04-21 11:52:29 -07:00 committed by Ben McIlwain
parent c5d6a1f6fb
commit 0cbcfcc3c1
2 changed files with 64 additions and 0 deletions

View file

@ -45,6 +45,22 @@ registry_ear_file(
},
)
# We use the production "nocron" earfile only in the event of a datastore
# restore.
registry_ear_file(
name = "registry_nocron_ear",
out = "registry_nocron.ear",
configs = {
"env/common/META-INF/appengine-application.xml": "META-INF/appengine-application.xml",
"env/common/META-INF/application.xml": "META-INF/application.xml",
},
wars = {
"registry_default_nocron.war": "default",
"registry_backend.war": "backend",
"registry_tools.war": "tools",
},
)
zip_file(
name = "registry_default_war",
srcs = [
@ -69,6 +85,13 @@ zip_file(
],
)
zip_file(
name = "registry_default_nocron_war",
out = "registry_default_nocron.war",
exclude = ["WEB-INF/cron.xml"],
deps = [":registry_default_war"],
)
zip_file(
name = "registry_backend_war",
srcs = [
@ -185,6 +208,26 @@ registry_ear_file(
},
)
# The "nocron" files are, unsurprisingly, versions of the archives that have
# had cron.xml removed. We do this because it's necessary to deploy them in
# this way when restoring a backup.
#
# "nocron" archives are currently prepared for production and alpha. To
# prepare them for another environment, just do something similar.
registry_ear_file(
name = "registry_alpha_nocron_ear",
out = "registry_alpha_nocron.ear",
configs = {
"env/common/META-INF/appengine-application.xml": "META-INF/appengine-application.xml",
"env/common/META-INF/application.xml": "META-INF/application.xml",
},
wars = {
"registry_default_alpha_nocron.war": "default",
"registry_backend_alpha.war": "backend",
"registry_tools_alpha.war": "tools",
},
)
zip_file(
name = "registry_default_alpha_war",
srcs = [
@ -198,6 +241,13 @@ zip_file(
deps = [":registry_default_war"],
)
zip_file(
name = "registry_default_alpha_nocron_war",
out = "registry_default_alpha_nocron.war",
exclude = ["WEB-INF/cron.xml"],
deps = [":registry_default_alpha_war"],
)
zip_file(
name = "registry_backend_alpha_war",
srcs = [

View file

@ -107,6 +107,18 @@ A zip file can be assembled across many rules. For example:
mappings = {"webapp/html": ""},
)
You can exclude files with the "exclude" attribute:
# //webapp/BUILD
zip_file(
name = "war_without_tears",
deps = ["war"],
exclude = ["assets/js/tears.js"],
)
Note that "exclude" excludes based on the mapped path relative to the root of
the zipfile. If the file doesn't exist, you'll get an error.
"""
load('//java/google/registry/builddefs:defs.bzl',
@ -136,6 +148,7 @@ def _zip_file(ctx):
]
cmd += ['"${zipper}" x "${repo}/%s"' % dep.zip_file.path
for dep in ctx.attr.deps]
cmd += ['rm %s' % filename for filename in ctx.attr.exclude]
cmd += ['mkdir -p "${tmp}/%s"' % zip_path
for zip_path in set(
[zip_path[:zip_path.rindex('/')]
@ -217,6 +230,7 @@ zip_file = rule(
'srcs': attr.label_list(allow_files=True),
'data': attr.label_list(cfg='data', allow_files=True),
'deps': attr.label_list(providers=['zip_file']),
'exclude': attr.string_list(),
'mappings': attr.string_dict(),
'_zipper': attr.label(default=Label(ZIPPER), single_file=True),
})