add openhack files

This commit is contained in:
Ryan Peters
2022-11-03 16:41:13 -04:00
commit b2c9f7e29f
920 changed files with 118861 additions and 0 deletions

111
.github/workflows/iac-deployment.yml vendored Normal file
View File

@ -0,0 +1,111 @@
# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file
# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run
# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events
# to the "main" branch, `terraform apply` will be executed.
#
# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform
#
# To use this workflow, you will need to complete the following setup steps.
#
# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined.
# Example `main.tf`:
# # The configuration for the `remote` backend.
# terraform {
# backend "remote" {
# # The name of your Terraform Cloud organization.
# organization = "example-organization"
#
# # The name of the Terraform Cloud workspace to store Terraform state files in.
# workspaces {
# name = "example-workspace"
# }
# }
# }
#
# # An example resource that does nothing.
# resource "null_resource" "example" {
# triggers = {
# value = "A example resource that does nothing!"
# }
# }
#
#
# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository.
# Documentation:
# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html
# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
#
# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action.
# Example:
# - name: Setup Terraform
# uses: hashicorp/setup-terraform@v1
# with:
# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
name: 'IaC - Deployment'
# this is triggered when there is a pull request on the below path, where the PR type is opened or reopened
on: workflow_dispatch
#on:
# push:
# branches:
# - main
# paths:
# - 'iac/terraform/**'
#permissions:
# contents: read
defaults:
run:
shell: bash
working-directory: ./iac/terraform
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{secrets.ARM_CLIENT_SECRET}}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
jobs:
Terraform-Plan:
name: 'Plan_Job'
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init -lock=false -backend-config=storage_account_name="${{secrets.TFSTATE_STORAGE_ACCOUNT_NAME}}" -backend-config=container_name="${{secrets.TFSTATE_STORAGE_CONTAINER_NAME}}" -backend-config=key="${{secrets.TFSTATE_KEY}}" -backend-config=resource_group_name="${{secrets.TFSTATE_RESOURCES_GROUP_NAME}}"
- name: Terraform Plan
run: terraform plan -lock=false -var="location=${{secrets.LOCATION}}"
Terraform-Apply:
name: 'Deploy_Job'
runs-on: ubuntu-latest
needs: Terraform-Plan
environment: production
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init -lock=false -backend-config=storage_account_name="${{secrets.TFSTATE_STORAGE_ACCOUNT_NAME}}" -backend-config=container_name="${{secrets.TFSTATE_STORAGE_CONTAINER_NAME}}" -backend-config=key="${{secrets.TFSTATE_KEY}}" -backend-config=resource_group_name="${{secrets.TFSTATE_RESOURCES_GROUP_NAME}}"
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Terraform Apply
run: terraform apply --auto-approve -var="location=${{secrets.LOCATION}}"

87
.github/workflows/iac-validation.yml vendored Normal file
View File

@ -0,0 +1,87 @@
# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file
# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run
# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events
# to the "main" branch, `terraform apply` will be executed.
#
# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform
#
# To use this workflow, you will need to complete the following setup steps.
#
# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined.
# Example `main.tf`:
# # The configuration for the `remote` backend.
# terraform {
# backend "remote" {
# # The name of your Terraform Cloud organization.
# organization = "example-organization"
#
# # The name of the Terraform Cloud workspace to store Terraform state files in.
# workspaces {
# name = "example-workspace"
# }
# }
# }
#
# # An example resource that does nothing.
# resource "null_resource" "example" {
# triggers = {
# value = "A example resource that does nothing!"
# }
# }
#
#
# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository.
# Documentation:
# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html
# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
#
# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action.
# Example:
# - name: Setup Terraform
# uses: hashicorp/setup-terraform@v1
# with:
# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
name: 'IaC - Validation/Plan'
# this is triggered when there is a pull request on the below path, where the PR type is opened or reopened
on:
pull_request:
paths:
- 'iac/terraform/**'
types: [opened, reopened]
#permissions:
# contents: read
jobs:
terraform:
name: 'Initiate_Job'
runs-on: ubuntu-latest
environment: production
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./iac/terraform
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
# Init
- name: Terraform Init
run: terraform init -backend=false
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
run: terraform fmt -check
# Validate
- name: Terraform Validate
run: terraform validate

77
.github/workflows/poi-deploy.yml vendored Normal file
View File

@ -0,0 +1,77 @@
name: 'POI API - Deployment'
# this is triggered when there is a pull request on the below path, where the PR type is opened or reopened
on:
push:
branches:
- main
paths:
- 'apis/poi/**'
workflow_dispatch:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#permissions:
# contents: read
defaults:
run:
shell: bash
working-directory: ./apis/poi/web
jobs:
Build:
name: 'Docker_Build_Deploy'
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: "Azure Login"
uses: Azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Build Docker Image
run:
az acr build
--image devopsoh/api-poi:${{ github.run_id }}
--registry devopsoh41379cr
--build-arg build_version=${{ github.run_id }}
--file Dockerfile .
- name: Update_App_Service_Image_For_Staging_Slot
run:
az webapp config container set
--name devopsoh41379poi
--resource-group devopsoh41379rg
--slot staging
--docker-custom-image-name devopsoh41379cr.azurecr.io/devopsoh/api-poi:${{ github.run_id }}
--docker-registry-server-url https://devopsoh41379cr.azurecr.io
- name: Stage Health Check
uses: jtalk/url-health-check-action@v2
with:
# Check the following URLs one by one sequentially
url: https://devopsoh41379poi-staging.azurewebsites.net/api/version/poi
# Follow redirects, or just report success on 3xx status codes
follow-redirect: false # Optional, defaults to "false"
# Fail this action after this many failed attempts
max-attempts: 3 # Optional, defaults to 1
# Delay between retries
retry-delay: 5s # Optional, only applicable to max-attempts > 1
# Retry all errors, including 404. This option might trigger curl upgrade.
retry-all: false # Optional, defaults to "false"
- name: Swap into production
run:
az webapp deployment slot swap
--name devopsoh41379poi
--resource-group devopsoh41379rg
--action swap
--slot staging
--target-slot production

75
.github/workflows/poi-tests.yml vendored Normal file
View File

@ -0,0 +1,75 @@
name: 'POI API - Unit Tests'
# this is triggered when there is a pull request on the below path, where the PR type is opened or reopened
on:
pull_request:
types: [opened, reopened]
branches:
- main
paths:
- 'apis/poi/**'
workflow_dispatch:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#permissions:
# contents: read
defaults:
run:
shell: bash
working-directory: ./apis/poi/tests/UnitTests
jobs:
Build:
name: 'Build'
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET Core SDK 3.1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 3.1.x
- name: Build
run: dotnet build
- name: Run UnitTest
run: dotnet test --filter "FullyQualifiedName~UnitTest" --logger "trx;LogFileName=UnitTestResults.trx" --results-directory ./TestResults
- name: Create Issue
if: failure() && github.event_name != 'pull_request'
run: |
body='### Unit Test `failure`
<details>
<summary>Workflow details</summary>
Workflow name: `${{ github.workflow }}`
Action: `${{ github.event_name }}`
Job: `${{ github.job }}`
</details>
Test details: [Run #${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
Pusher: @${{ github.actor }}'
title='Unit Tests failure'
gh issue create --title "${title}" --body "${body}" --label bug --assignee ${{ github.actor }}
- name: "Create a PR comment"
if: failure() && github.event_name == 'pull_request'
run: |
body='### Unit Test `failure`
<details>
<summary>Workflow details</summary>
Workflow name: `${{ github.workflow }}`
Action: `${{ github.event_name }}`
Job: `${{ github.job }}`
PR: #${{ github.event.number }}
</details>
Test details: [Run #${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
Pusher: @${{ github.actor }}'
gh pr comment ${{ github.event.number }} --body "${body}"