Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit

Permalink
Merge branch 'azure-dev' into tm-azure-merge-and-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Middelkoop authored and Timothy Middelkoop committed Dec 2, 2021
2 parents 4938639 + 32e2f1c commit 40c7280
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ gcloud config set project $GOOGLE_CLOUD_PROJECT
## AWS

Expect that `aws` is installed locally. A ssh-key named 'learner' is required to access the account.

## Azure

Expect that `az` is installed and configured locally. It will utilize your ~/.ssh/id_rsa.pub key.
4 changes: 3 additions & 1 deletion scripts/aws-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Options
BRANCH="${1:-aws-dev}" # checkout branch $1

# Static Config - update aws-*.sh files
# Provider Config - update aws-*.sh files.

# Static Config - update *.sh files
NAME=learner
VM=essentials
PROJECT=CLASS-Essentials
Expand Down
77 changes: 77 additions & 0 deletions scripts/azure-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# Options
BRANCH="${1:-azure-dev}" # checkout branch $1

# Provider Config - update *-azure.sh files.
LOCATION=centralus

# Static Config - update *.sh files
NAME=learner
VM=essentials
PROJECT=CLASS-Essentials
GITHUB=github.internet2.edu
REPO="git@${GITHUB}:CLASS/${PROJECT}.git"

echo "=== azure-create.sh $PROJECT $BRANCH"
SUBSCRIPTION=$(az account show --query id -otsv)
RESOURCE_GROUP="rg-${VM}-dev"

echo "+++ creating resource group $RESOURCE_GROUP $SUBSCRIPTION"
az group create --resource-group $RESOURCE_GROUP --location $LOCATION

echo "+++ creating VM $VM"
# Ubuntu is "Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest"
# Debian is "Debian:debian-10:10:latest"
# Resource Group scope "subscriptions/$SUBSCRIPTION/resourceGroups/$RESOURCE_GROUP"
az vm create --resource-group $RESOURCE_GROUP --name $VM \
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest \
--size Standard_D2_v4 \
--storage-sku Standard_LRS \
--public-ip-sku Standard \
--assign-identity \
--scope "subscriptions/$SUBSCRIPTION/resourceGroups/$RESOURCE_GROUP" \
--admin-username $NAME

IP=$(az vm show --name $VM --resource-group $RESOURCE_GROUP -d --query publicIps -otsv)
IDENTITY=$(az vm show --name $VM --resource-group $RESOURCE_GROUP --query identity.principalId -otsv)

echo "+++ assign the VM the Contributor role to the subscription ($IDENTITY to $SUBSCRIPTION)"
az role assignment create --assignee $IDENTITY --scope /subscriptions/$SUBSCRIPTION --role Contributor

echo "+++ wait for boot and cloud-init ${VM} ${IP}"
ssh-keygen -R $IP
while ! ssh $NAME@$IP sudo cloud-init status --wait ; do
sleep 1
done

echo "+++ configuring VM"
ssh -A $NAME@$IP <<EOF
echo '--- connected to $NAME@IP'
sudo apt-get update
sudo apt-get install --yes azure-cli
az login --identity
sudo apt-get install --yes git python3-pip python3-venv bash-completion
ssh-keyscan ${GITHUB} > .ssh/known_hosts
git config --global color.ui auto
git config --global push.default simple
git config --global pull.ff only
git config --global user.name "$(git config user.name)"
git config --global user.email "$(git config user.name)"
git clone --branch $BRANCH $REPO
EOF

echo "+++ configure ~/.ssh/$VM.config"
cat > ~/.ssh/$VM.config <<EOF
Host essentials
HostName $IP
CheckHostIP=no
ForwardAgent=yes
User=$NAME
EOF

echo "+++ starting Jypter"
ssh $NAME@$IP -t -L 8080:localhost:8080 -L 8081:localhost:8081 "cd $PROJECT ; ./scripts/jupyter-lab.sh"

echo "+++ ssh command"
echo "ssh $NAME@$IP"
13 changes: 13 additions & 0 deletions scripts/azure-delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Provider Config - update *-azure.sh files.

# Static Config - update *.sh files
VM=essentials

echo "=== azure-delete.sh $PROJECT $BRANCH"
SUBSCRIPTION=$(az account show --query id -otsv)
RESOURCE_GROUP="rg-${VM}-dev"

az vm delete --resource-group $RESOURCE_GROUP --name $VM --yes
az group delete --resource-group $RESOURCE_GROUP --yes
9 changes: 6 additions & 3 deletions scripts/gcp-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# Options
BRANCH="${1:-gcp-dev}" # checkout branch $1

# Static Config - update gcp-*.sh files
# Provider Config - update gcp-*.sh files.
ZONE=us-west2-c

# Static Config - update *.sh files
NAME=learner
VM=essentials
ZONE=us-west2-c
PROJECT=CLASS-Essentials
GITHUB=github.internet2.edu
REPO="git@${GITHUB}:CLASS/${PROJECT}.git"
Expand All @@ -25,7 +27,8 @@ done
echo "+++ configuring VM"

gcloud compute ssh --zone=$ZONE $NAME@$VM --ssh-flag='-A' <<EOF
sudo apt install --yes git python3-pip python3-venv bash-completion
sudo apt-get update
sudo apt-get install --yes git python3-pip python3-venv bash-completion
ssh-keyscan ${GITHUB} > .ssh/known_hosts
git config --global color.ui auto
git config --global push.default simple
Expand Down

0 comments on commit 40c7280

Please sign in to comment.