Skip to content

Commit

Permalink
[scag] Add option to switch between Gramine repositories
Browse files Browse the repository at this point in the history
Gramine maintains two repositories: stable and unstable.
The unstable repository is mostly used for testing release candidates.
This commit adds an option to switch between these repositories.

Signed-off-by: Mariusz Zaborski <[email protected]>
  • Loading branch information
oshogbo committed Apr 24, 2024
1 parent 50ef6e1 commit f9d14a3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
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
4 changes: 4 additions & 0 deletions graminescaffolding/templates/sources.list
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{% block sources %}
deb http://deb.debian.org/debian/ bookworm main
deb http://security.debian.org/debian-security bookworm-security main
{% if gramine_unstable %}
deb https://packages.gramineproject.io/ unstable-bookworm main
{% else %}
deb https://packages.gramineproject.io/ bookworm main
{% endif %}
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

0 comments on commit f9d14a3

Please sign in to comment.