Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Nov 2, 2023
1 parent 5122c20 commit 34ca1c6
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
def upgrade():
op.add_column('build', sa.Column('allow_user_ssh', sa.Boolean(),
server_default='0', nullable=False))
op.add_column('build', sa.Column('ssh_public_key', sa.Text()))


def downgrade():
op.drop_column('build', 'allow_user_ssh')
op.drop_column('build', 'ssh_public_key')
7 changes: 7 additions & 0 deletions frontend/coprs_frontend/coprs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,13 @@ def selected_chroots(self):

F.packit_forge_project = wtforms.StringField(default=None)

F.allow_user_ssh = wtforms.BooleanField(
"Allow user SSH",
default=True,
false_values=FALSE_VALUES,
)
F.ssh_public_key = wtforms.StringField(default=None)

def _validate_batch_opts(form, field):
counterpart = form.with_build_id
modifies = False
Expand Down
7 changes: 6 additions & 1 deletion frontend/coprs_frontend/coprs/logic/builds_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ def create_new(cls, user, copr, source_type, source_json, chroot_names=None, pkg
with_build_id=build_options.get("with_build_id"),
package_chroots_subset=package_chroots_subset,
packit_forge_project=build_options.get("packit_forge_project"),
allow_user_ssh=build_options.get("allow_user_ssh"),
ssh_public_key=build_options.get("ssh_public_key"),
)

if "timeout" in build_options:
Expand Down Expand Up @@ -808,7 +810,8 @@ def add(cls, user, pkgs, copr, source_type=None, source_json=None,
git_hashes=None, skip_import=False, background=False, batch=None,
srpm_url=None, copr_dirname=None, bootstrap=None, isolation=None,
package=None, after_build_id=None, with_build_id=None,
package_chroots_subset=None, packit_forge_project=None):
package_chroots_subset=None, packit_forge_project=None,
allow_user_ssh=None, ssh_public_key=None):

coprs_logic.CoprsLogic.raise_if_unfinished_blocking_action(
copr, "Can't build while there is an operation in progress: {action}")
Expand Down Expand Up @@ -862,6 +865,8 @@ def add(cls, user, pkgs, copr, source_type=None, source_json=None,
copr_dir=copr_dir,
bootstrap=bootstrap,
isolation=isolation,
allow_user_ssh=allow_user_ssh,
ssh_public_key=ssh_public_key,
)

if timeout:
Expand Down
2 changes: 2 additions & 0 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,8 @@ def __init__(self, *args, **kwargs):
# Keep builder alive after the build finishes and allow user SSH access
allow_user_ssh = db.Column(db.Boolean, default=False,
server_default="0", nullable=False)
# TODO We might want to create `_BuildPrivate` for this
ssh_public_key = db.Column(db.Text)

# if a build was resubmitted from another build, this column will contain the original build id
# the original build id is not here as a foreign key because the original build can be deleted so we can lost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ <h3 class="panel-title">
{% endmacro %}


{% macro copr_build_form_rebuild(form, view, copr, build) %}
{% macro copr_build_form_rebuild(form, view, copr, build,
allow_user_ssh, ssh_public_key) %}
{{ copr_build_form_begin(form, view, copr, build, hide_panels=True) }}
<input type="hidden" name="allow_user_ssh" value="{{ allow_user_ssh }}">
<input type="hidden" name="ssh_public_key" value="{{ ssh_public_key }}">
{{ copr_build_form_end(form, view, copr, hide_panels=True) }}
{% endmacro %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,25 @@ <h3> Original Build Details </h3>
</dd>
{{ describe_source(build.source_type_text, build.source_json_dict) }}
</dl>

{% if allow_user_ssh %}
<h3> Allow user SSH </h3>
<p>
After this build finishes, you will obtain a SSH access to the builder.
This will help you debug your package within the Copr infrastructure.

The access will be given based on the SSH public key that you configured
in FAS:
</p>

<!-- TODO This should be textarea but we maybe want to do this
in a followup -->
<pre>{{ ssh_public_key }}</pre>
{% endif %}

<h3> New Build Options </h3>
{{ copr_build_form_rebuild(form, 'coprs_ns.copr_new_build_rebuild', copr, build) }}
{{ copr_build_form_rebuild(form, 'coprs_ns.copr_new_build_rebuild',
copr, build, allow_user_ssh, ssh_public_key) }}
</div>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def get_build_record(task, for_backend=False):
"isolation": task.build.isolation,
"fedora_review": task.build.copr.fedora_review,
"appstream": bool(task.build.appstream),
"repo_priority": task.build.copr.repo_priority
"repo_priority": task.build.copr.repo_priority,
"allow_user_ssh": task.build.allow_user_ssh,
"ssh_public_key": task.build.ssh_public_key,
})

copr_chroot = ComplexLogic.get_copr_chroot_safe(task.build.copr, task.mock_chroot.name)
Expand Down
14 changes: 13 additions & 1 deletion frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def process_new_build(copr, form, create_new_build_factory, add_function, add_vi
"isolation": form.isolation.data,
"with_build_id": form.with_build_id.data,
"after_build_id": form.after_build_id.data,
"allow_user_ssh": form.allow_user_ssh.data,
"ssh_public_key": form.ssh_public_key.data,
}

try:
Expand Down Expand Up @@ -453,6 +455,9 @@ def factory(**build_options):

################################ Repeat ################################

# TODO Not introduced in this PR but we should IMHO remove the POST method.
# It is confusing because this method is not called when clicking the
# submit button
@coprs_ns.route("/<username>/<coprname>/repeat_build/<int:build_id>/",
methods=["GET", "POST"])
@coprs_ns.route("/g/<group_name>/<coprname>/repeat_build/<int:build_id>/",
Expand Down Expand Up @@ -512,9 +517,16 @@ def _copr_repeat_build(copr, build_id, allow_user_ssh):
# check checkbox on all the chroots that have not been (successfully) built before
if (ch.name not in build_chroot_names) or (ch.name in build_failed_chroot_names):
form.chroots.data.append(ch.name)

# TODO Take the FAS SSH key (from our database)
ssh_public_key = None
if allow_user_ssh:
ssh_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCxZWz5K+BGQnVrirgJi+3pQhGY6+N6iiM1+u9jIOy4cC32DUnhRiUXBMfTqBQN0/0g2mG8W/Jn3Hmvzjet89Yk2rwcIzOghJ0mKLKYxbdVxgzMQRNmHmpIIis8yBfqHkNz5OO2BtxqckaQ5/xHQTwnYSLRCyNpi68ZwJUOzdvnL9y9zpH5IDJNQ6RlscLc/u6zQk9My3uPpNkwELE4brCQffHN1zc6MkDfVlVVqamWuF04YpqjoOWBe67aepUjC49eZy6uoWwxYg7IwPeZd1KyBg2y5W0dHj3OfXobv0bv4Bo/MXaMsEexJqlF4qF5A1wx2j5DIXlf4Lr8gyU9Td42C4CU2AkVjaue1e91Ay+ggotkOCEz+Wv5DKjOiTNWGS3InChbRYO2728pB6mjEh5w3I7RGF+ixtfk1w3GtVgU71uFquN3gFvVptDts/dQumsbyIl/ft0oi+FrodRH4Oz2Cb+FnDoOTMtQl5ykxzpJCDGWPr2ZXbcdIb0zFlmVnK0fjoSmpgmEwZG8Fpl2eVzxzIbM64L8+Qdr8VmTMNnmd6Z7ID8hR4qab5OBxh2IKhmashL4gZKPvsyuzfPu4sYXtIDZNBzi5sA31eTqogh1Cj6JEsUW/h+V3c7g7y3dtR3DGnPqM0H79yAlPdE5GOVq2A8OQT4snYPI+y9PrC9Hzw== [email protected]"

return flask.render_template(
"coprs/detail/add_build/rebuild.html",
copr=copr, build=build, form=form)
copr=copr, build=build, form=form, allow_user_ssh=allow_user_ssh,
ssh_public_key=ssh_public_key)


################################ Cancel ################################
Expand Down

0 comments on commit 34ca1c6

Please sign in to comment.