logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

Introducing-shell-access-for-builds.md (3432B)


  1. ---
  2. date: 2019-08-19
  3. layout: post
  4. title: Shell access for builds.sr.ht CI
  5. tags: ["announcement", "sourcehut"]
  6. ---
  7. Have you ever found yourself staring at a failed CI build, wondering desperately
  8. what happened? Or, have you ever needed a fresh machine on-demand to test out an
  9. idea in? Have you been working on Linux, but need to test something on OpenBSD?
  10. Starting this week, builds.sr.ht can help with all of these problems, because
  11. you can now SSH into the build environment.
  12. <small class="text-muted">
  13. If you didn't know, <a href="https://sourcehut.org">Sourcehut</a> is the 100%
  14. open/libre software forge for hackers, complete with git and Mercurial
  15. hosting, CI, mailing lists, and more - with no JavaScript. Try it out!
  16. </small>
  17. The next time your build fails on builds.sr.ht, you'll probably notice the
  18. following message:
  19. ![Screenshot of builds.sr.ht showing a prompt to SSH into the failed build
  20. VM and examine it](https://sr.ht/thL-.png)
  21. After the build fails, we process everything normally - sending emails,
  22. webhooks, and so on - but keep the VM booted for an additional 10 minutes. If
  23. you do log in during this window, we keep the VM alive until you log out or
  24. until your normal build time limit has elapsed. Once you've logged in, you get a
  25. shell and can do anything you like, such as examining the build artifacts or
  26. tweaking the source and trying again.
  27. ```
  28. $ ssh -t builds@azusa.runners.sr.ht connect 81809
  29. Connected to build job #81809 (failed):
  30. https://builds.sr.ht/jobs/~sircmpwn/81809
  31. Your VM will be terminated 4 hours from now, or when you log out.
  32. bash-5.0 $
  33. ```
  34. You can also connect to any build over SSH by adding `shell: true` to your build
  35. manifest. When you do, the VM will be kept alive after all of the tasks have
  36. finished (even if it doesn't fail) so you can SSH in. You can also SSH in before
  37. the tasks have finished, and tail the output of the build in your terminal. An
  38. example use case might be getting a fresh Alpine environment to test build your
  39. package on:
  40. <script
  41. id="asciicast-wnLYZwDuvkbIHwgTdmnqtQpXh"
  42. src="https://asciinema.org/a/pafXXANiWHY9MOH2yXdVHHJRd.js" async
  43. ></script>
  44. <noscript><i>This article includes third-party JavaScript content from
  45. asciinema.org, a free- and open-source platform that I trust.</i></noscript>
  46. This was accomplished with a simple build manifest:
  47. ```
  48. image: alpine/edge
  49. shell: true
  50. sources:
  51. - https://git.alpinelinux.org/aports
  52. tasks:
  53. - "prep-abuild": |
  54. abuild-keygen -an
  55. ```
  56. Since build manifests run normally in advance of your shell login, you can do
  57. things like install your preferred editor and dotfiles, pull down your SSH keys
  58. through [build
  59. secrets](https://man.sr.ht/tutorials/builds.sr.ht/using-build-secrets.md), or
  60. anything else you desire to set up a comfortable working environment.
  61. Furthermore, by leveraging the [builds.sr.ht
  62. API](https://man.sr.ht/builds.sr.ht/api.md), you can write scripts which take
  63. advantage of the shell features. Need a NetBSD shell? With a little scripting
  64. you can get something like this working:
  65. <script
  66. id="asciicast-8etTNE7Ptgmu6hO3cVDlvrAal"
  67. src="https://asciinema.org/a/pafXXANiWHY9MOH2yXdVHHJRd.js" async
  68. ></script>
  69. With experimental multiarch support being rolled out, soon you'll be just a few
  70. keystrokes away from an ARM or PowerPC shell, too.
  71. I want to expand more on SSH access in the future. Stay tuned and [let me
  72. know](mailto:sir@cmpwn.com) if you have any cool ideas!