{"id":8094,"date":"2020-09-21T07:46:19","date_gmt":"2020-09-21T12:46:19","guid":{"rendered":"https:\/\/bobbeaty.com\/wp\/?p=8094"},"modified":"2020-09-21T15:33:34","modified_gmt":"2020-09-21T20:33:34","slug":"github-codespaces-customization","status":"publish","type":"post","link":"https:\/\/bobbeaty.com\/wp\/archives\/8094","title":{"rendered":"GitHub Codespaces Customization"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bobbeaty.com\/wp\/wp-content\/uploads\/2011\/06\/GitHub.jpg\" alt=\"GitHub Source Hosting\" title=\"GitHub.jpg\" border=\"0\" width=\"125\" height=\"125\" style=\"float:right;\" \/><\/p>\n<p>This morning I was able to make a stripped-down <a href=\"https:\/\/github.com\/drbobbeaty\/dotfiles\">dotfiles<\/a> GitHub repo that Codespaces will use when a new Docker image is created. If there is a <tt>install<\/tt> file in the repo, it'll be executed after cloning the repo to the new user - as specified in the Dockerfile's <tt>USER<\/tt> variable.<\/p>\n<p>So in my Dockerfile I now have:<\/p>\n<pre class=\"bash\" style=\"font-family:monospace;\">  <span style=\"color: #666666; font-style: italic;\"># Make my user for when we really get going, and pull in my env from GitHub<\/span>\n  ARG <span style=\"color: #007800;\">USERNAME<\/span>=drbob\n  ARG <span style=\"color: #007800;\">USER_UID<\/span>=<span style=\"color: #000000;\">1001<\/span>\n  ARG <span style=\"color: #007800;\">USER_GID<\/span>=<span style=\"color: #007800;\">$USER_UID<\/span>\n&nbsp;\n  <span style=\"color: #666666; font-style: italic;\"># Create the user and add him to the sudoers so that he can install more stuff<\/span>\n  RUN groupadd <span style=\"color: #660033;\">--gid<\/span> <span style=\"color: #007800;\">$USER_GID<\/span> <span style=\"color: #007800;\">$USERNAME<\/span> \\\n      <span style=\"color: #000000; font-weight: bold;\">&amp;&amp;<\/span> useradd <span style=\"color: #660033;\">--uid<\/span> <span style=\"color: #007800;\">$USER_UID<\/span> <span style=\"color: #660033;\">--gid<\/span> <span style=\"color: #007800;\">$USER_GID<\/span> <span style=\"color: #660033;\">-m<\/span> <span style=\"color: #007800;\">$USERNAME<\/span> \\\n      <span style=\"color: #000000; font-weight: bold;\">&amp;&amp;<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">apt-get update<\/span> \\\n      <span style=\"color: #000000; font-weight: bold;\">&amp;&amp;<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">apt-get install<\/span> <span style=\"color: #660033;\">-y<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">sudo<\/span> \\\n      <span style=\"color: #000000; font-weight: bold;\">&amp;&amp;<\/span> <span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #007800;\">$USERNAME<\/span> <span style=\"color: #007800;\">ALL<\/span>=\\<span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span>root\\<span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span> NOPASSWD:ALL <span style=\"color: #000000; font-weight: bold;\">&gt;<\/span> <span style=\"color: #000000; font-weight: bold;\">\/<\/span>etc<span style=\"color: #000000; font-weight: bold;\">\/<\/span>sudoers.d<span style=\"color: #000000; font-weight: bold;\">\/<\/span><span style=\"color: #007800;\">$USERNAME<\/span> \\\n      <span style=\"color: #000000; font-weight: bold;\">&amp;&amp;<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">chmod<\/span> 0440 <span style=\"color: #000000; font-weight: bold;\">\/<\/span>etc<span style=\"color: #000000; font-weight: bold;\">\/<\/span>sudoers.d<span style=\"color: #000000; font-weight: bold;\">\/<\/span><span style=\"color: #007800;\">$USERNAME<\/span>\n&nbsp;\n  <span style=\"color: #666666; font-style: italic;\"># [Optional] Set the default user. Omit if you want to keep the default as root.<\/span>\n  USER <span style=\"color: #007800;\">$USERNAME<\/span><\/pre>\n<p>and that lands me in the repo's home directory, but I still have to clean up the <a href=\"https:\/\/github.com\/drbobbeaty\/dotfiles\">dotfiles<\/a> repo, and all the permissions from the last post. To do that, I made a simple function in my <tt>~\/.bashrc<\/tt> that does all that:<\/p>\n<pre class=\"bash\" style=\"font-family:monospace;\">  <span style=\"color: #666666; font-style: italic;\">#<\/span>\n  <span style=\"color: #666666; font-style: italic;\"># This is a simple function to cleanup the GitHub Codespace once it's been<\/span>\n  <span style=\"color: #666666; font-style: italic;\"># created. Basically, I need to remove the left-overs of the dotfiles setup<\/span>\n  <span style=\"color: #666666; font-style: italic;\"># and clean up the permissions on all the files.<\/span>\n  <span style=\"color: #666666; font-style: italic;\">#<\/span>\n  <span style=\"color: #000000; font-weight: bold;\">function<\/span> cleanup <span style=\"color: #7a0874; font-weight: bold;\">&#40;<\/span><span style=\"color: #7a0874; font-weight: bold;\">&#41;<\/span> <span style=\"color: #7a0874; font-weight: bold;\">&#123;<\/span>\n    <span style=\"color: #7a0874; font-weight: bold;\">pushd<\/span> <span style=\"color: #007800;\">$HOME<\/span>\n    <span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;cleaning up the dotfiles...&quot;<\/span>\n    <span style=\"color: #c20cb9; font-weight: bold;\">rm<\/span> <span style=\"color: #660033;\">-rf<\/span> dotfiles <span style=\"color: #c20cb9; font-weight: bold;\">install<\/span> README.md\n    <span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;resetting the ownership of the workspace...&quot;<\/span>\n    <span style=\"color: #c20cb9; font-weight: bold;\">sudo<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">chown<\/span> <span style=\"color: #660033;\">-R<\/span> drbob:drbob workspace\n    <span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;cleaning up the permissions on the workspace...&quot;<\/span>\n    <span style=\"color: #c20cb9; font-weight: bold;\">sudo<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">chmod<\/span> <span style=\"color: #660033;\">-R<\/span> g-w workspace\n    <span style=\"color: #c20cb9; font-weight: bold;\">sudo<\/span> <span style=\"color: #c20cb9; font-weight: bold;\">chmod<\/span> <span style=\"color: #660033;\">-R<\/span> o-w workspace\n    <span style=\"color: #c20cb9; font-weight: bold;\">sudo<\/span> setfacl <span style=\"color: #660033;\">-R<\/span> <span style=\"color: #660033;\">-bn<\/span> workspace\n    <span style=\"color: #7a0874; font-weight: bold;\">echo<\/span> <span style=\"color: #ff0000;\">&quot;done&quot;<\/span>\n    <span style=\"color: #7a0874; font-weight: bold;\">popd<\/span>\n  <span style=\"color: #7a0874; font-weight: bold;\">&#125;<\/span><\/pre>\n<p>At this point, I can launch a Codespace, it'll have all my necessary environment, and I can continue to refine it in my <a href=\"https:\/\/github.com\/drbobbeaty\/dotfiles\">dotfiles<\/a> repo as that's only being used for the set-up of these Codespaces. So it's easy to remove things I'll never need there, and make sure it's customized to the things that I <em>do need<\/em> there.<\/p>\n<p>Very nice. \ud83d\ude42 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>This morning I was able to make a stripped-down dotfiles GitHub repo that Codespaces will use when a new Docker image is created. If there is a install file in the repo, it&#8217;ll be executed after cloning the repo to the new user &#8211; as specified in the Dockerfile&#8217;s USER variable. So in my Dockerfile [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3,4,5],"tags":[],"class_list":["post-8094","post","type-post","status-publish","format-standard","hentry","category-clojure-coding","category-coding","category-open-source-software","category-vendors"],"_links":{"self":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/8094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/comments?post=8094"}],"version-history":[{"count":3,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/8094\/revisions"}],"predecessor-version":[{"id":8097,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/8094\/revisions\/8097"}],"wp:attachment":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/media?parent=8094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/categories?post=8094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/tags?post=8094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}