Skip to content

Instantly share code, notes, and snippets.

@m-bers
Last active July 27, 2022 03:27
Show Gist options
  • Save m-bers/7c9792fd2edb68f02f571bbe057c96a0 to your computer and use it in GitHub Desktop.
Save m-bers/7c9792fd2edb68f02f571bbe057c96a0 to your computer and use it in GitHub Desktop.

UDF environment deployment script

This script will configure a fresh UDF instance in several ways:

  • Adds vscode web UI for an interactive editing/terminal session
  • Installs zsh, powerlevel10k, and Nerd Fonts
  • Installs AWS CLI
  • Sets up AWS credentials from UDF API in ~/.aws/

UDF Console steps:

  1. In the sidebar, click Deployments, then click Create Deployment in the top right
  2. Set provider to UDF and give the deployment a name
  3. Open the new deployment, click Cloud Accounts, then Add AWS Cloud Account
  4. Click Components, then Systems, then Add.
  5. Choose template Ubuntu 20.04 LTS Server
  6. Set to 4 vCPUs, 15GB RAM, 370GB Disk, then click Create
  7. Click start, and select n1-standard-4 as the deployment size
  8. Once the deployment has started, go to Access Methods -> Web Shell
  9. In the terminal that appears, run the following commands:
# su - ubuntu
$ curl https://gist.githubusercontent.com/m-bers/7c9792fd2edb68f02f571bbe057c96a0/raw/d5bb292bee5e2ac853c11e8f13882414d5a37713/udf.sh | sh
  1. Under Systems, click the Details button under the instance you just created
  2. Click the Access Methods tab and click Create
  3. In the Label field, enter "vscode"
  4. From the Protocol dropdown, select HTTPS
  5. From the Instance Address dropdown, select the instance IP
  6. In the Instance Port field, enter "8081"
  7. Click the blue Save icon in the top right.
  8. Go back to the main deployment screen
  9. Go to Access Methods -> vscode

Congratulations, you should be set up with a working vscode installation and everything you need to get started deploying infrastructure in AWS.

#!/bin/bash
set -x
mkdir -p temp
cd temp
# Install prereqs
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install \
ca-certificates \
curl \
gnupg \
lsb-release \
unzip \
jq \
git \
gnupg \
software-properties-common
# Install Docker Engine
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-compose-plugin
sudo groupadd docker
sudo usermod -aG docker $USER
# Get latest AWS credentials from UDI API
mkdir -p ~/.aws
sudo cat << EOF | sudo tee /usr/local/bin/awsCreds.sh
printf "[default]\naws_access_key_id=" > "${HOME}/.aws/credentials"
curl -s 10.1.1.1/cloudAccounts | jq '.cloudAccounts[0]' | jq -r ' .apiKey' >> "${HOME}/.aws/credentials"
printf "aws_secret_access_key=" >> "${HOME}/.aws/credentials"
curl -s 10.1.1.1/cloudAccounts | jq '.cloudAccounts[0]' | jq -r ' .apiSecret' >> "${HOME}/.aws/credentials"
printf "[default]\nregion=us-west-2" > "${HOME}/.aws/config"
EOF
sudo chmod +x /usr/local/bin/awsCreds.sh
crontab -l > cron
echo "@reboot /usr/local/bin/awsCreds.sh" >> cron
crontab cron
rm cron
awsCreds.sh
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Install Terraform
wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update
sudo apt-get -y install terraform
# Install code-server
export VERSION=4.4.0
curl -fOL "https://github.com/coder/code-server/releases/download/v${VERSION}/code-server_${VERSION}_amd64.deb"
sudo dpkg -i "code-server_${VERSION}_amd64.deb"
sudo systemctl enable --now code-server@${USER}
mkdir -p ~/.config/code-server
cat << 'EOF' > ~/.config/code-server/config.yaml
bind-addr: 127.0.0.1:8080
auth: none
cert: false
EOF
mkdir -p ~/.local/share/code-server/User
cat << 'EOF' > ~/.local/share/code-server/User/settings.json
{
"workbench.colorTheme": "GitHub Dark Default",
"terminal.integrated.fontFamily": "MesloLGS NF",
"security.workspace.trust.enabled": false,
"workbench.editorAssociations": {
"*.md": "vscode.markdown.preview.editor"
},
"explorer.sortOrder": "type",
"terminal.integrated.defaultProfile.linux": "zsh"
}
EOF
# vscode extensions
wget https://nightly.link/hangxingliu/vscode-nginx-conf-hint/actions/artifacts/304167943.zip
unzip 304167943.zip
curl -s https://api.github.com/repos/f5devcentral/vscode-f5/releases/latest | jq '.assets[0]' | jq -r '.browser_download_url' | wget -qi -
code-server --install-extension vscode-nginx*.vsix
code-server --install-extension vscode-f5*.vsix
code-server --install-extension hashicorp.terraform
code-server --install-extension GitHub.github-vscode-theme
sudo systemctl restart --now code-server@${USER}
sudo apt-get update && sudo apt-get -y install nginx libnginx-mod-http-subs-filter zsh
# Install NGINX proxy
sudo cat << 'EOF' | sudo tee /etc/nginx/sites-available/code-server
server {
listen 8081;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Accept-Encoding "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
sub_filter
'</head>'
'<link rel="stylesheet" type="text/css" href="/code-server/css/fonts.css">
</head>';
sub_filter
'<meta http-equiv="Content-Security-Policy" content="'
'<meta http-equiv="Content-Security-Policy" content="
style-src-elem * \'unsafe-inline\';
font-src * \'unsafe-inline\';';
sub_filter_once on;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
location /code-server {
autoindex on;
root /var/www/html;
}
location /_static/src/browser/media {
autoindex on;
root /var/www/html/code-server;
}
location /manifest.json {
autoindex on;
root /var/www/html/code-server;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/code-server /etc/nginx/sites-enabled/code-server
# Install icons
sudo mkdir -p /var/www/html/code-server/_static/src/browser/media
sudo wget https://vscode.dev/static/stable/code-192.png -O /var/www/html/code-server/_static/src/browser/media/pwa-icon-192.png
sudo wget https://vscode.dev/static/stable/code-192.png -O /var/www/html/code-server/_static/src/browser/media/pwa-icon-512.png
sudo wget https://vscode.dev/static/stable/favicon.ico -O /var/www/html/code-server/_static/src/browser/media/favicon.ico
# Install fonts
sudo mkdir -p /var/www/html/code-server/fonts
sudo wget https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Regular.ttf -P /var/www/html/code-server/fonts
sudo wget https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Bold.ttf -P /var/www/html/code-server/fonts
sudo wget https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Italic.ttf -P /var/www/html/code-server/fonts
sudo wget https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/MesloLGS%20NF%20Bold%20Italic.ttf -P /var/www/html/code-server/fonts
sudo mkdir -p /var/www/html/code-server/css
sudo cat << 'EOF' | sudo tee /var/www/html/code-server/css/fonts.css
@font-face {
font-family: "MesloLGS NF";
src: url("/code-server/fonts/MesloLGS%20NF%20Regular.ttf");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "MesloLGS NF";
src: url("/code-server/fonts/MesloLGS%20NF%20Bold.ttf");
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: "MesloLGS NF";
src: url("/code-server/fonts/MesloLGS%20NF%20Italic.ttf");
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: "MesloLGS NF";
src: url("/code-server/fonts/MesloLGS%20NF%20Bold%20Italic.ttf");
font-weight: bold;
font-style: italic;
}
EOF
sudo cat << 'EOF' | sudo tee /var/www/html/code-server/manifest.json
{
"name": "Visual Studio Code",
"short_name": "Code",
"start_url": ".",
"display": "fullscreen",
"description": "Run Code on a remote server.",
"icons": [
{
"src": "./_static/src/browser/media/pwa-icon-192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "./_static/src/browser/media/pwa-icon-512.png",
"type": "image/png",
"sizes": "512x512"
}
]
}
EOF
sudo systemctl restart nginx
mkdir -p ~/.zsh
wget https://raw.githubusercontent.com/m-bers/udf-template/main/.p10k.zsh -P ~/.zsh
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.zsh/powerlevel10k
cat << 'EOF' > ~/.zshrc
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
source ~/.zsh/powerlevel10k/powerlevel10k.zsh-theme
[[ ! -f ~/.zsh/.p10k.zsh ]] || source ~/.zsh/.p10k.zsh
alias code="code-server"
export EDITOR="code-server -w"
EOF
cd ~
rm -rf temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment