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

[scag] Add option to switch between Gramine repositories #15

Open
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions Documentation/manpages/scag-setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Options
Initialize an empty directory with an example application from
the given framework.

.. option:: --gramine_unstable

Use a pre-release version of Gramine.

.. option:: --framework <framework>

The framework used by the scaffolded application.
Expand Down Expand Up @@ -120,6 +124,7 @@ Example of the generated file (from

[gramine]
passthrough_env = []
gramine_unstable = false

[python_plain]
application = "hello_world.py"
Expand Down
9 changes: 7 additions & 2 deletions graminescaffolding/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ def cli_version(project_dir, bootstrap):
help='The directory of the application to scaffold.')
@gramine_option_prompt('--bootstrap', required=False, is_flag=True,
default=False, help='Bootstrap directory with framework example.')
@gramine_option_prompt('--gramine_unstable', required=False, is_flag=True,
default=False, help='Use gramine unstable repo.')
@gramine_option_prompt('--passthrough_env', required=False, multiple=True,
help='List of passthrough environment variables.')
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
@click.pass_context
def setup(ctx, framework, project_dir, bootstrap, passthrough_env, args):
def setup(ctx, framework, project_dir, bootstrap, gramine_unstable,
passthrough_env, args
):
"""
Build Gramine application using Scaffolding framework.

Expand All @@ -155,7 +159,8 @@ def setup(ctx, framework, project_dir, bootstrap, passthrough_env, args):
ctx.fail(f'{err}')

framework = gramine_load_framework(framework)
parser = framework.cmdline_setup_parser(project_dir, passthrough_env)
parser = framework.cmdline_setup_parser(
project_dir, gramine_unstable, passthrough_env)
if bootstrap:
if len(args) > 0:
print(
Expand Down
26 changes: 18 additions & 8 deletions graminescaffolding/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def _init_jinja_env(self):
types.MappingProxyType({}))
templates.globals['passthrough_env'] = list(
self.config['gramine'].get('passthrough_env', []))
templates.globals['gramine_unstable'] = self.config['gramine'].get(
'gramine_unstable', False)

return templates

Expand Down Expand Up @@ -385,7 +387,7 @@ def get_docker_run_cmd(self, docker_id):


@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
def click_parser():
return cls(project_dir, {
Expand All @@ -394,6 +396,7 @@ def click_parser():
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
})
return click_parser
Expand All @@ -406,7 +409,7 @@ class PythonBuilder(Builder):
)

@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
@utils.gramine_option_prompt('--application', type=str,
required=True,
Expand All @@ -419,6 +422,7 @@ def click_parser(application):
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
cls.framework: {
'application': application,
Expand Down Expand Up @@ -449,7 +453,7 @@ class NodejsBuilder(Builder):
)

@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
@utils.gramine_option_prompt('--application', required=True, type=str,
prompt="Which script is the main one")
Expand All @@ -460,6 +464,7 @@ def click_parser(application):
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
cls.framework: {
'application': application,
Expand All @@ -483,7 +488,7 @@ class ExpressjsBuilder(Builder):
)

@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
@utils.gramine_option_prompt('--application', required=True, type=str,
prompt="Which script is the main one")
Expand All @@ -494,6 +499,7 @@ def click_parser(application):
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
cls.framework: {
'application': application,
Expand All @@ -517,7 +523,7 @@ class KoajsBuilder(Builder):
)

@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
@utils.gramine_option_prompt('--application', required=True, type=str,
prompt="Which script is the main one")
Expand All @@ -528,6 +534,7 @@ def click_parser(application):
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
cls.framework: {
'application': application,
Expand All @@ -546,7 +553,7 @@ class JavaJARBuilder(Builder):
)

@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
@utils.gramine_option_prompt('--application', required=True, type=str,
prompt="Which JAR is the main one")
Expand All @@ -557,6 +564,7 @@ def click_parser(application):
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
cls.framework: {
'application': application,
Expand All @@ -572,7 +580,7 @@ class JavaGradleBuilder(Builder):
)

@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
@utils.gramine_option_prompt('--application', required=True, type=str,
prompt="Which JAR is the main one")
Expand All @@ -583,6 +591,7 @@ def click_parser(application):
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
cls.framework: {
'application': application,
Expand All @@ -603,7 +612,7 @@ class DotnetBuilder(Builder):
)

@classmethod
def cmdline_setup_parser(cls, project_dir, passthrough_env):
def cmdline_setup_parser(cls, project_dir, gramine_unstable, passthrough_env):
@click.command()
@utils.gramine_option_prompt('--build_config', required=True,
type=click.Choice(['Debug', 'Release']),
Expand All @@ -621,6 +630,7 @@ def click_parser(build_config, project_file, target):
},
'gramine': {
'passthrough_env': passthrough_env,
'gramine_unstable': gramine_unstable,
},
cls.framework: {
'build_config': build_config,
Expand Down
1 change: 1 addition & 0 deletions graminescaffolding/templates/scag.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ framework = "{{ scag.builder.framework }}"
{% block gramine -%}
[gramine]
passthrough_env = {{ passthrough_env }}
gramine_unstable = {{ gramine_unstable | lower }}
{%- endblock %}

[{{ scag.builder.framework }}]
Expand Down
2 changes: 1 addition & 1 deletion graminescaffolding/templates/sources.list
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% block sources %}
deb http://deb.debian.org/debian/ bookworm main
deb http://security.debian.org/debian-security bookworm-security main
deb https://packages.gramineproject.io/ bookworm main
deb https://packages.gramineproject.io/ {% if gramine_unstable %}unstable-{% endif %}bookworm main
deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu jammy main
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion graminescaffolding/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def write_dl(self, rows, col_max=30, col_spacing=2):

for name in gramine_list_frameworks():
parser = gramine_load_framework(name).cmdline_setup_parser(
None, None)
None, False, None)
self.indent()
opts = []
for param in parser.params:
Expand Down