Skip to content

Instantly share code, notes, and snippets.

@ianphil
Last active July 15, 2019 11:48
Show Gist options
  • Save ianphil/e03ebac3fd5e3ec5e851d19a1f0c64ef to your computer and use it in GitHub Desktop.
Save ianphil/e03ebac3fd5e3ec5e851d19a1f0c64ef to your computer and use it in GitHub Desktop.
Run ZNC in Azure Containers
#!/bin/sh
# Variables
RESOURCE_GROUP='ianphil-znc'
LOCATION='eastus'
STORAGE_NAME='ianphilznc'
STORAGE_SKU='Standard_LRS'
SHARE_NAME='config'
CONTAINER_NAME=$RESOURCE_GROUP
CONTAINER_PORT=6697
# Resource Group
## Create Resource Group
az group create --name $RESOURCE_GROUP --location $LOCATION \
| jq '. | .properties.provisioningState' --raw-output # Succeeded
# Azure Storage Account
## Check Name
az storage account check-name --name $STORAGE_NAME \
| jq '. | .nameAvailable' # true
## Create Storage Account
az storage account create --name $STORAGE_NAME \
--resource-group $RESOURCE_GROUP --sku $STORAGE_SKU --location $LOCATION \
| jq '. | .provisioningState' --raw-output # Succeeded
# Azure File Share
## Get Storage Account Connection String
CONN_STRING=$(az storage account show-connection-string --name $STORAGE_NAME \
--resource-group $RESOURCE_GROUP --query 'connectionString' -o tsv)
if [[ $CONN_STRING == "" ]]; then
echo "Couldn't retrieve the connection string."
fi
# Create Azure File Share
az storage share create --name $SHARE_NAME --connection-string $CONN_STRING \
| jq '. | .created' # true
# ZNC Setup
## Create config dir
mkdir /tmp/znc
## ZNC Container Config
docker run -it -v /tmp/znc:/znc-data znc --makeconf
### Need to add Allow = * to User section
### Need to add ProtectWebSessions = false to global
## Mount Share locally
sudo az storage file upload-batch --destination config \
--source /tmp/znc --connection-string $CONN_STRING
## Get Azure Storage Account Key
STORAGE_KEY=$(az storage account keys list --resource-group $RESOURCE_GROUP \
--account-name $STORAGE_NAME --query '[0].{Key:value}' --output tsv)
## Create Container
az container create --name $CONTAINER_NAME --image znc --cpu 1 --memory 1 \
--ip-address public --ports $CONTAINER_PORT --resource-group $RESOURCE_GROUP \
--azure-file-volume-account-key $STORAGE_KEY --azure-file-volume-account-name $STORAGE_NAME \
--azure-file-volume-mount-path /znc-data --azure-file-volume-share-name $SHARE_NAME
## Get Container State
az container show --name $CONTAINER_NAME --resource-group $RESOURCE_GROUP --query instanceView.state -o tsv
## Get Container IP Address
az container show --name $CONTAINER_NAME --resource-group $RESOURCE_GROUP --query ipAddress.ip -o tsv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment