Skip to content

Update README.md

Update README.md #107

Workflow file for this run

name: grepolis-live-map CICD
on:
workflow_dispatch:
push:
branches: [ main ]
jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
env:
TERRAFORM_RESOURCE_GROUP: ${{ 'terraform' }}
TERRAFORM_STORAGE_ACCOUNT: ${{ 'peteterraformsa' }}
TERRAFORM_CONTAINER: ${{ 'state' }}
TERRAFORM_KEY: ${{ 'grepolislivemap' }}
TERRAFORM_ACCESS_KEY: ${{ secrets.TERRAFORM_ACCESS_KEY }}
SERVICE_LOCATION: ${{ 'UK South' }}
SERVICE_NAME: ${{ 'grepolis-live-map' }}
DOMAIN: ${{ 'grepolislivemap.com' }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
steps:
- uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
- name: Checkout
uses: actions/checkout@v2
- name: Terraform
working-directory: ./terraform
run: |
terraform init -backend-config="resource_group_name=$TERRAFORM_RESOURCE_GROUP" -backend-config="storage_account_name=$TERRAFORM_STORAGE_ACCOUNT" -backend-config="container_name=$TERRAFORM_CONTAINER" -backend-config="key=$TERRAFORM_KEY" -backend-config="access_key=$TERRAFORM_ACCESS_KEY"
terraform plan -out=plan -var="domain=$DOMAIN" -var="service_name=$SERVICE_NAME" -var="location=$SERVICE_LOCATION" -var="subscription_id=$AZURE_SUBSCRIPTION_ID" -var="tenant_id=$AZURE_TENANT_ID" -var="client_id=$AZURE_CLIENT_ID" -var="client_secret=$AZURE_CLIENT_SECRET"
terraform apply "plan"
echo "STORAGE_ACCOUNT_URL=$(terraform output storage_account_url)" >> $GITHUB_ENV
saConnString="$(terraform output storage_account_connection_string)"
echo "Masking connection string:"
echo "::add-mask::$saConnString"
echo "STORAGE_ACCOUNT_CONNECTION_STRING=$saConnString" >> $GITHUB_ENV
- name: Setup Node Environment
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Build Func
working-directory: ./func
run: |
npm install
npm run build
npm test
- name: Build Client
working-directory: ./client
run: |
tee config.json <<< "{\"storageAccountUrl\": \"${{ env.STORAGE_ACCOUNT_URL }}\"}"
npm install
npm run build
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Setup Azure Resources
uses: azure/powershell@v1
with:
inlineScript: |
$connectionString = ${{ env.STORAGE_ACCOUNT_CONNECTION_STRING }}
az storage blob service-properties update --static-website --404-document "index.html" --index-document "index.html" --connection-string $connectionString --output none
az storage blob delete-batch --source '$web' --connection-string $connectionString --output none
az storage blob upload-batch -s "./client/dist" -d '$web' --connection-string $connectionString --output none
$containerExistsResponse = az storage container exists --connection-string $connectionString --name "world-data" --output none
$containerExists = ($containerExistsResponse | ConvertFrom-Json).exists
if(!$containerExists){
az storage container create --connection-string $connectionString --name "world-data" --public-access blob --output none
}
azPSVersion: "latest"
- name: Fetch Publishing Profile
id: profilefetch
uses: azure/powershell@v1
with:
inlineScript: |
$profile = ""
$profile = Get-AzWebAppPublishingProfile -ResourceGroupName "${{ env.SERVICE_NAME }}-rg" -Name "${{ env.SERVICE_NAME }}-azfunc"
$profile = $profile.Replace("`r", "").Replace("`n", "")
Write-Output "::add-mask::$profile"
Write-Output "::set-output name=pubprofile::$profile"
Remove-Variable profile
azPSVersion: "latest"
- name: Deploy
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.SERVICE_NAME }}
package: "./func"
publish-profile: ${{ steps.profilefetch.outputs.pubprofile }}