workspace-images icon indicating copy to clipboard operation
workspace-images copied to clipboard

feat(proposal): runonce scripts, eqivalent to `.bashrc.d` but runs only once without any race conditions between several terminals

Open axonasif opened this issue 2 years ago • 4 comments

Description

As IDEs start without loading the login shell for quick startup, previous assumptions about race condition between .bashrc.d startup scripts are not ideal anymore. This introduces a new directory alongside .bashrc.d called .runonce. Scripts placed inside $HOME/.runonce will be executed once in the lifecycle of a workspace, and all task terminals will wait for .runonce scripts to complete before proceeding to execute the .gitpod.yml task commands. While scripts placed inside $HOME/.bashrc.d are used for modifying the shell environment (e.g. exporting env vars) each time a terminal is created and not for starting services.

Currently Proposed
r1 r2(2)

This PR only migrates the VNC startup to .runonce. I plan to create a followup PR to migrate rust, dotnet, mysql, postgres, vnc and yugabyte startup scripts as well (see https://github.com/axonasif/workspace-images/commit/7907f57e1d2cce93e70c05c67b56905b4528c748).

Related Issue(s)

Fixes https://github.com/gitpod-io/workspace-images/issues/1067, https://github.com/gitpod-io/gitpod/issues/18491, slack report, frontapp ticket.

How to test

Open https://gitpod.io/#https://github.com/axonasif/test/tree/vnc_test and check if all task terminals are attempting to start the vnc service.

Or if you want to emulate the race-condition environment from your existing workspace:

# Creates five bash login shells at the same time
docker run -e GITPOD_REPO_ROOT -v /workspace:/workspace -it axonasif/workspace-base-vnc:latest sh -c 'for i in 1 2 3 4 5; do bash -lic "echo Hello from BASH process $i" & done; wait'

Documentation

/hold

axonasif avatar Jun 23 '23 09:06 axonasif

Overall it looks good, but it seems we've added too many tricks to bashrc that don't seem regular

iQQBot avatar Jul 05 '23 08:07 iQQBot

Overall it looks good, but it seems we've added too many tricks to bashrc that don't seem regular

@iQQBot would it make sense to sync with @axonasif , to talk about next steps?

@axonasif I'm not sure if the IDE team planned on this work? suggestion: flip this back to draft, and plan next steps with @iQQBot in the context of a Linear issue, in the IDE team, but assigned to @axonasif. cc: @laushinka

kylos101 avatar Jul 07 '23 17:07 kylos101

if the IDE team planned on this work? suggestion: flip this back to draft, and plan next steps with @iQQBot in the context of a Linear issue, in the IDE team, but assigned to @axonasif

Thanks for mentioning, Kyle!

@axonasif Thank you for the initiative 👍🏽 As per Kyle's suggestion, Asif would you mind putting the issue to the IDE team's Triage? @iQQBot let's bring it up in team sync or teaming. I'd like to understand more, e.g. the tradeoffs of this approach.

laushinka avatar Jul 10 '23 08:07 laushinka

Thanks for all the input 🙏

As per Kyle's suggestion, Asif would you mind putting the issue to the IDE team's Triage?

Yes, (IDE-219) 👍

axonasif avatar Jul 10 '23 14:07 axonasif