Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make env optional for azd package #2857

Open
vhvb1989 opened this issue Oct 11, 2023 · 3 comments
Open

make env optional for azd package #2857

vhvb1989 opened this issue Oct 11, 2023 · 3 comments

Comments

@vhvb1989
Copy link
Member

          > why does azd package require an environment?

That's a good question!.
The azd-environment can help you to se set different packaging modes. For example, creating a package for Production might require different settings than a Development package.
When you are on CI, all the settings are coming from ENV-VARS, and you can use the GitHub environments to have your group of settings for each mode.
Azd uses the .env from the .azure folder in a similar way, allowing you to switch modes easily (when you are not on CI).

I'll check with the team if we can make the azd-env optional.

Originally posted by @vhvb1989 in #2848 (comment)

@jasontaylordev
Copy link

For further context, the reason for making azd-env optional would be in support of the build once, deploy many principal. I would not want a custom package per environment. As part of CI/CD, I will package the application independently of any specific environment, store that package, and then deploy it to relevant environments - e.g. dev, stg, prd.

@jasontaylordev
Copy link

This is an example CI/CD built with GitHub Actions.

azure-dev.yml

on:
  workflow_dispatch:
  push:
    branches:
      - main

permissions:
  id-token: write
  contents: read
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
      AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
      AZURE_DEV_COLLECT_TELEMETRY: no
    steps:
        - name: Checkout
          uses: actions/checkout@v3

        - name: Install AZD
          uses: Azure/setup-azd@v0.1.0

        - name: Install .NET
          uses: actions/setup-dotnet@v3

        - name: Package Application
          run: azd package web --output-path ./dist/web.zip --environment NoEnvironment --no-prompt
          working-directory: ./

        - name: Upload website artifact (website)
          uses: actions/upload-artifact@v3
          with:
            name: package
            path: ./dist/web.zip
            if-no-files-found: error

  development:
    uses: ./.github/workflows/up.yml
    secrets: inherit
    needs: [build]
    with:
      AZURE_ENV_NAME: WebDev

  staging:
    uses: ./.github/workflows/up.yml
    secrets: inherit
    needs: [development]
    with:
      AZURE_ENV_NAME: WebStg

  production:
    uses: ./.github/workflows/up.yml
    secrets: inherit
    needs: [staging]
    with:
      AZURE_ENV_NAME: WebPrd

up.yml

name: Deploy

on:
  workflow_call:
    inputs:
      AZURE_ENV_NAME:
        required: true
        type: string

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: ${{ inputs.AZURE_ENV_NAME }}
    env:
      AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
      AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
      AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
      AZURE_ENV_NAME: ${{ inputs.AZURE_ENV_NAME }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install .NET
        uses: actions/setup-dotnet@v3

      - name: Install AZD
        uses: Azure/setup-azd@v0.1.0

      - name: Log into Azure
        run: |
          azd auth login `
            --client-id "$Env:AZURE_CLIENT_ID" `
            --federated-credential-provider "github" `
            --tenant-id "$Env:AZURE_TENANT_ID"
        shell: pwsh

      - name: Provision Infrastructure
        run: azd provision --no-prompt

      - name: Download Package
        uses: actions/download-artifact@v3

      - name: Deploy Application
        run: azd deploy web --from-package ./package/web.zip --no-prompt

With this approach I'm using GitHub Environments, let me know if further information is required.

@wbreza
Copy link
Contributor

wbreza commented Oct 25, 2023

@jasontaylordev Thanks for the context. I agree that this is a valid use case but unfortunately it is not an easy fix at the moment as many of our internal components take a dependency on the existence of an environment. Looks like you have a workaround in place right now where you are setting --environment NoEnvironment.

We will keep this on the backlog for the future.

cc @rajeshkamal5050

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants