Skip to content

Commit

Permalink
add ACI deploy yaml with mounting azure fileshare (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinIgarashi authored Dec 20, 2024
1 parent cdda8f6 commit 7c6b908
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .azure/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AZURE_RESOUCE_GROUP=
ACR_PASSWORD=
AZURE_STORAGE_ACCOUNT_NAME=
AZURE_STORAGE_ACCOUNT_KEY=
AZURE_SSH_USERS=
38 changes: 38 additions & 0 deletions .azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Deploy docker iamge to ACI

## Create ACI

The below commands are to create new ACI by mounting fileshare storage.

This creation can only be done one time if no need to change settings.

- first replace variables in YAML

```shell
source ./.azure/.env

ACR_PASSWORD=${ACR_PASSWORD} \
AZURE_STORAGE_ACCOUNT_NAME=${AZURE_STORAGE_ACCOUNT_NAME} \
AZURE_STORAGE_ACCOUNT_KEY=${AZURE_STORAGE_ACCOUNT_KEY} \
SSH_USERS=$SSH_USERS \
./.azure/aci-deploy.sh temp.yaml
```

- deploy

```shell
az login
az container create --resource-group ${AZURE_RESOUCE_GROUP} --file temp.yaml

# delete temp.yaml
rm temp.yaml
```

## Restart

when new image is deployed, ACI can be restarted.

```shell
# restart
az container restart --resource-group ${AZURE_RESOUCE_GROUP} --name cbsurge-rapida
```
38 changes: 38 additions & 0 deletions .azure/aci-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

YAML_FILE="./.azure/aci-deploy.yaml"

if [ -z "$AZURE_STORAGE_ACCOUNT_NAME" ]; then
echo "Error: AZURE_STORAGE_ACCOUNT_NAME is not set. Please provide a valid value."
exit 1
fi

if [ -z "$AZURE_STORAGE_ACCOUNT_KEY" ]; then
echo "Error: AZURE_STORAGE_ACCOUNT_KEY is not set. Please provide a valid value."
exit 1
fi

if [ -z "$ACR_PASSWORD" ]; then
echo "Error: ACR_PASSWORD is not set. Please provide a valid value."
exit 1
fi

if [ -z "$SSH_USERS" ]; then
echo "Error: SSH_USERS is not set. Please provide a valid value."
exit 1
fi

if [ -z "$1" ]; then
echo "Error: Output file name is not specified. Please provide an output file name as the first argument."
exit 1
fi

OUTPUT_FILE="$1"

sed -e "s/{ACR_PASSWORD}/$ACR_PASSWORD/" \
-e "s/{AZURE_STORAGE_ACCOUNT_NAME}/$AZURE_STORAGE_ACCOUNT_NAME/" \
-e "s/{AZURE_STORAGE_ACCOUNT_KEY}/$AZURE_STORAGE_ACCOUNT_KEY/" \
-e "s/{SSH_USERS}/$SSH_USERS/" \
"$YAML_FILE" > $OUTPUT_FILE

echo "$YAML_FILE was exported"
39 changes: 39 additions & 0 deletions .azure/aci-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: '2019-12-01'
location: eastus
name: cbsurge-rapida
properties:
containers:
- name: cbsurge-rapida
properties:
environmentVariables:
- name: SSH_USERS
value: "{SSH_USERS}"
image: undpgeohub.azurecr.io/undp-data/geo-cb-surge:main
ports:
- port: 22
resources:
requests:
cpu: 4
memoryInGB: 16
volumeMounts:
- mountPath: /home
name: fileshare-volume
imageRegistryCredentials:
- server: undpgeohub.azurecr.io
username: undpgeohub
password: {ACR_PASSWORD}
osType: Linux
restartPolicy: OnFailure
ipAddress:
type: Public
ports:
- port: 22
dnsNameLabel: cbsurge-rapida
volumes:
- name: fileshare-volume
azureFile:
sharename: cbrapida-aci
storageAccountName: {AZURE_STORAGE_ACCOUNT_NAME}
storageAccountKey: {AZURE_STORAGE_ACCOUNT_KEY}
tags: {}
type: Microsoft.ContainerInstance/containerGroups

0 comments on commit 7c6b908

Please sign in to comment.