Create rockpal tenant (#83) #76
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Instance - deploy prod" | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
build-api: | |
uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main | |
with: | |
solution_file: "src/Api/Company.Api.sln" | |
project_file: "src/Api/Company.Api/Company.Api.csproj" | |
dotnet_version: 8.0.203 | |
dockerfile_name: "src/Api/Company.Api/dockerfile" | |
image_name: "onlinestore-api" | |
secrets: inherit | |
build-website: | |
uses: benchiverton/OnlineStore/.github/workflows/workflow-build-test-publish-dotnet.yml@main | |
with: | |
solution_file: "src/Website/Company.Website.sln" | |
project_file: "src/Website/Company.Website/Company.Website.csproj" | |
dotnet_version: 8.0.203 | |
dockerfile_name: "src/Website/Company.Website/dockerfile" | |
image_name: "onlinestore-website" | |
secrets: inherit | |
deploy-terraform-prod: | |
needs: [build-api, build-website] | |
environment: prod | |
env: | |
ARM_CLIENT_ID: ${{ secrets.TF_VAR_AGENT_CLIENT_ID }} | |
ARM_CLIENT_SECRET: ${{ secrets.TF_VAR_AGENT_CLIENT_SECRET }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.TF_VAR_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ secrets.TF_VAR_TENANT_ID }} | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: "./terraform" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_wrapper: false | |
- name: Login via Azure CLI | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Terraform Format | |
id: fmt | |
run: terraform -chdir=instance fmt | |
- name: Terraform Init | |
id: init | |
run: terraform -chdir=instance init -backend-config="container_name=onlinestoretfstate-prod" | |
- name: Terraform Validate | |
id: validate | |
run: terraform -chdir=instance validate -no-color | |
- name: Terraform Plan | |
id: plan | |
run: terraform -chdir=instance plan -no-color | |
env: | |
TF_VAR_location: "East US" | |
TF_VAR_environment: prod | |
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }} | |
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }} | |
TF_VAR_website_dns_subdomain: www | |
TF_VAR_api_dns_subdomain: api | |
TF_VAR_monitoring_dns_subdomain: monitoring | |
- name: Terraform Apply | |
id: apply | |
run: terraform -chdir=instance apply -auto-approve | |
env: | |
TF_VAR_location: "East US" | |
TF_VAR_environment: prod | |
TF_VAR_acr_username: ${{ secrets.ACR_USERNAME }} | |
TF_VAR_acr_password: ${{ secrets.ACR_TOKEN }} | |
TF_VAR_website_dns_subdomain: www | |
TF_VAR_api_dns_subdomain: api | |
TF_VAR_monitoring_dns_subdomain: monitoring | |
- name: Save terraform outputs | |
shell: bash | |
run: | | |
mkdir terraform-outputs | |
terraform -chdir=instance output -raw resource_group_name > terraform-outputs/resource_group_name.txt | |
- name: Upload terraform outputs for deploy job | |
uses: actions/upload-artifact@v3 | |
with: | |
name: terraform-outputs | |
path: terraform/terraform-outputs/ | |
deploy-app-prod: | |
needs: [deploy-terraform-prod] | |
environment: prod | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Download terraform outputs | |
uses: actions/download-artifact@v3 | |
with: | |
name: terraform-outputs | |
- name: Set terraform outputs as env variables | |
id: vars | |
shell: bash | |
run: | | |
echo "resource_group_name=$(cat resource_group_name.txt)" >> $GITHUB_ENV | |
- name: Login via Azure CLI | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Deploy api | |
uses: azure/container-apps-deploy-action@v1 | |
with: | |
acrName: onlinestorecontainerregistry | |
acrUsername: ${{ secrets.ACR_USERNAME }} | |
acrPassword: ${{ secrets.ACR_TOKEN }} | |
containerAppName: prod-onlinestore-api | |
imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-api:${{ github.sha }} | |
location: 'East US' | |
resourceGroup: onlinestore-shared-rg | |
targetPort: 8080 | |
environmentVariables: OTEL_EXPORTER_OTLP_ENDPOINT=http://prod-onlinestore-monitoring:18889 | |
- name: Deploy website | |
uses: azure/container-apps-deploy-action@v1 | |
with: | |
acrName: onlinestorecontainerregistry | |
acrUsername: ${{ secrets.ACR_USERNAME }} | |
acrPassword: ${{ secrets.ACR_TOKEN }} | |
containerAppName: prod-onlinestore-website | |
imageToDeploy: onlinestorecontainerregistry.azurecr.io/onlinestore-website:${{ github.sha }} | |
location: 'East US' | |
resourceGroup: onlinestore-shared-rg | |
targetPort: 80 | |
environmentVariables: "API__BASEPATH=https://api.rockpal.co.uk" |