diff --git a/.github/workflows/api.yaml b/.github/workflows/api.yaml new file mode 100644 index 0000000..0c7d58d --- /dev/null +++ b/.github/workflows/api.yaml @@ -0,0 +1,36 @@ +name: 'API Build and Deploy' +on: + workflow_call: + inputs: + calling_workflow: + required: true + type: string + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + environment: ${{ inputs.calling_workflow }} + steps: + - name: 'Checkout' + uses: action/checkout@v4 + + - name: 'Setup Node' + uses: actions/setup-node@v4 + with: + node-version: ${{ vars.NODE_VERSION }} + + - name: Install + run: | + npm install + + - name: Build + shell: bash + run: | + npm run build -w api + + - name: Deploy + uses: Azure/functions-action@v1 + with: + app-name: ${{ vars.API_FUNCTION_APP_NAME }} + package: ${{ vars.API_FUNCTION_APP_PACKAGE_PATH }} + publish-profile: ${{ secrets.API_FUNCTION_APP_PUBLISH_PROFILE }} diff --git a/.github/workflows/app.yaml b/.github/workflows/app.yaml new file mode 100644 index 0000000..1ec073b --- /dev/null +++ b/.github/workflows/app.yaml @@ -0,0 +1,47 @@ +name: 'App Build and Deploy' +on: + workflow_call: + inputs: + calling_workflow: + required: true + type: string + deployment_environment: + required: true + type: string + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + environment: ${{ inputs.calling_workflow }} + env: + VITE_CLIENT_ID: ${{ secrets.VITE_CLIENT_ID }} + VITE_TENANT_ID: ${{ secrets.VITE_TENANT_ID }} + VITE_REDIRECT_URL: ${{ secrets.VITE_REDIRECT_URL }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: 'Setup Node' + uses: actions/setup-node@v4 + with: + node-version: ${{ vars.NODE_VERSION }} + + - name: Install + run: | + npm install + + - name: Build + run: | + npm run build -w app + + - name: Deploy + id: builddeploy + uses: Azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} + repo_token: ${{ secrets.GITHUB_TOKEN }} + action: 'upload' + skip_app_build: true + app_location: ${{ vars.APP_LOCATION }} + deployment_environment: ${{ inputs.deployment_environment }} diff --git a/.github/workflows/dev.yaml b/.github/workflows/dev.yaml new file mode 100644 index 0000000..70a4073 --- /dev/null +++ b/.github/workflows/dev.yaml @@ -0,0 +1,21 @@ +name: Dev +on: + push: + branches: + - feature/** + +jobs: + build-deploy-api: + name: build-deploy-api + uses: ./.github/workflows/api.yaml + with: + calling_workflow: dev + secrets: inherit + + build-deploy-app: + name: build-deploy-app + uses: ./.github/workflows/app.yaml + with: + calling_workflow: dev + deployment_environment: development + secrets: inherit diff --git a/.github/workflows/feature.yml b/.github/workflows/feature.yml deleted file mode 100644 index c818001..0000000 --- a/.github/workflows/feature.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Feature - -on: - push: - branches: - - feature/** - -env: - VITE_CLIENT_ID: ${{ vars.VITE_CLIENT_ID }} - VITE_TENANT_ID: ${{ vars.VITE_TENANT_ID }} - VITE_REDIRECT_URL: ${{ vars.VITE_REDIRECT_URL }} - -jobs: - build_and_deploy_job: - runs-on: ubuntu-latest - name: Build and Deploy Job - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Install - run: | - npm install - - - name: Build API - run: | - npm run build -w api - - - name: Build and Deploy - id: builddeploy - uses: Azure/static-web-apps-deploy@v1 - with: - azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} - repo_token: ${{ secrets.GITHUB_TOKEN }} - action: 'upload' - app_build_command: ${{ vars.APP_BUILD_COMMAND }} - app_location: ${{ vars.APP_LOCATION }} - # api_build_command: ${{ vars.API_BUILD_COMMAND }} - api_location: ${{ vars.API_LOCATION }} - output_location: ${{ vars.OUTPUT_LOCATION }} - deployment_environment: 'development' - skip_api_build: true diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 0000000..6afc62f --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,37 @@ +name: Pull Request + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + branches: + - main + +jobs: + build-deploy-api: + if: github.event_name == 'pull_request' && github.event.action != 'closed' + name: build-deploy-api + uses: ./.github/workflows/api.yaml + with: + calling_workflow: dev + secrets: inherit + + build-deploy-app: + if: github.event_name == 'pull_request' && github.event.action != 'closed' + name: build-deploy-app + uses: ./.github/workflows/app.yaml + with: + calling_workflow: dev + deployment_environment: staging + secrets: inherit + + close-pull-request-job: + if: github.event_name == 'pull_request' && github.event.action == 'closed' + runs-on: ubuntu-latest + name: Close Pull Request Job + steps: + - name: Close Pull Request + id: closepullrequest + uses: Azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} + action: 'close' diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml deleted file mode 100644 index 7940875..0000000 --- a/.github/workflows/pull_request.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Pull Request - -on: - pull_request: - types: [opened, synchronize, reopened, closed] - branches: - - main - -jobs: - build_and_deploy_job: - if: github.event_name == 'pull_request' && github.event.action != 'closed' - runs-on: ubuntu-latest - name: Build and Deploy Job - steps: - - uses: actions/checkout@v4 - with: - submodules: true - lfs: false - - name: Build And Deploy - id: builddeploy - uses: Azure/static-web-apps-deploy@v1 - with: - azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} - repo_token: ${{ secrets.GITHUB_TOKEN }} - action: 'upload' - app_build_command: ${{ vars.APP_BUILD_COMMAND }} - app_location: ${{ vars.APP_LOCATION }} - api_build_command: ${{ vars.API_BUILD_COMMAND }} - api_location: ${{ vars.API_LOCATION}} - output_location: ${{ vars.OUTPUT_LOCATION }} - deployment_environment: 'staging' - - close_pull_request_job: - if: github.event_name == 'pull_request' && github.event.action == 'closed' - runs-on: ubuntu-latest - name: Close Pull Request Job - steps: - - name: Close Pull Request - id: closepullrequest - uses: Azure/static-web-apps-deploy@v1 - with: - azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} - action: 'close' \ No newline at end of file diff --git a/infrastructure/api.tf b/infrastructure/api.tf new file mode 100644 index 0000000..85191e2 --- /dev/null +++ b/infrastructure/api.tf @@ -0,0 +1,47 @@ +resource "azurerm_service_plan" "service_plan" { + name = "noahspan-flying-api-service-plan" + resource_group_name = data.azurerm_resource_group.resource_group.name + location = data.azurerm_resource_group.resource_group.location + os_type = "Linux" + sku_name = "Y1" +} + +resource "azurerm_linux_function_app" "function_app_dev" { + name = "noahspanflyingapidev" + resource_group_name = data.azurerm_resource_group.resource_group.name + location = data.azurerm_resource_group.resource_group.location + service_plan_id = azurerm_service_plan.service_plan.id + storage_account_name = azurerm_storage_account.storage_account_dev.name + storage_account_access_key = azurerm_storage_account.storage_account_dev.primary_access_key + + app_settings = { + "CLIENT_ID" = "${var.CLIENT_ID}" + "CLIENT_SECRET" = "${var.CLIENT_SECRET}" + "TENANT_ID" = "${var.TENANT_ID}" + "AZURE_STORAGE_ACCOUNT_NAME" = azurerm_storage_account.storage_account_dev.name + "AZURE_STORAGE_ACCOUNT_KEY" = azurerm_storage_account.storage_account_dev.primary_access_key + "AZURE_STORAGE_ACCOUNT_URL" = azurerm_storage_account.storage_account_dev.primary_table_host + } + + auth_settings_v2 { + active_directory_v2 { + client_id = var.CLIENT_ID + tenant_auth_endpoint = "https://login.microsoftonline.com/${var.TENANT_ID}/v2.0/" + client_secret_setting_name = "CLIENT_SECRET" + } + + login { + + } + } + + site_config { + application_stack { + node_version = 20 + } + + cors { + allowed_origins = [ azurerm_static_web_app.static_web_app.default_host_name ] + } + } +} \ No newline at end of file diff --git a/infrastructure/main.tf b/infrastructure/main.tf index a5537ee..e517c24 100644 --- a/infrastructure/main.tf +++ b/infrastructure/main.tf @@ -1,17 +1,9 @@ -# module "static_web_app" { -# source = "github.com/noahspannbauer/noahspan-root/infrastructure/modules/static_web_app" -# region = var.REGION -# resource_group_name = data.azurerm_resource_group.resource_group.name -# static_web_app_name = var.STATIC_WEB_APP_NAME -# custom_domain_name_count = var.CUSTOM_DOMAIN_NAME_COUNT -# domain_name = var.DOMAIN_NAME -# subdomain_name = var.SUBDOMAIN_NAME -# } - resource "azurerm_static_web_app" "static_web_app" { name = var.STATIC_WEB_APP_NAME resource_group_name = data.azurerm_resource_group.resource_group.name location = var.REGION + sku_size = "Free" + sku_tier = "Free" } resource "azurerm_dns_cname_record" "dns_cname_record" { diff --git a/infrastructure/variables.tf b/infrastructure/variables.tf index 51039da..04765a9 100644 --- a/infrastructure/variables.tf +++ b/infrastructure/variables.tf @@ -26,3 +26,16 @@ variable "STORAGE_ACCOUNT_NAME" { type = string } +variable "CLIENT_ID" { + type = string +} + +variable "CLIENT_SECRET" { + type = string + sensitive = true +} + +variable "TENANT_ID" { + type = string +} +