-
Notifications
You must be signed in to change notification settings - Fork 270
Add Azure App Service extension with swap command #6687
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
Open
Copilot
wants to merge
12
commits into
main
Choose a base branch
from
copilot/add-service-tasks-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
34dd41b
Initial plan
Copilot 8540a1d
Implement service-tasks command with swap task for App Service
Copilot 9846728
Add tests and update snapshots for service-tasks command
Copilot 012d6b3
Format code: remove trailing whitespace
Copilot fc4bcb8
Address code review feedback: fix swap API usage and improve variable…
Copilot cb02fd1
Clarify function documentation
Copilot d77d7e7
handle @main param
vhvb1989 afd4047
handle args
vhvb1989 b4a021f
switch to extension
vhvb1989 ca55033
Merge branch 'main' of https://github.com/Azure/azure-dev into copilo…
vhvb1989 7da3851
azd fetch the resource - extension does swap
vhvb1989 2abbfb0
progress
vhvb1989 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Build output | ||
| bin/ | ||
| *.exe | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| .vscode/ | ||
| *.swp | ||
| *.swo | ||
|
|
||
| # Go | ||
| *.test |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Changelog | ||
|
|
||
| ## 0.1.0 | ||
|
|
||
| - Initial release with `swap` command for swapping App Service deployment slots. |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Azure App Service Extension | ||
|
|
||
| This extension provides commands for managing Azure App Service resources. | ||
|
|
||
| ## Commands | ||
|
|
||
| ### swap | ||
|
|
||
| Swap deployment slots for an Azure App Service. | ||
|
|
||
| ```bash | ||
| azd appservice swap --service <service-name> --src <source-slot> --dst <destination-slot> | ||
| ``` | ||
|
|
||
| **Flags:** | ||
|
|
||
| - `--service` - The name of the service to swap slots for (optional if there's only one App Service) | ||
| - `--src` - The source slot name. Use `@main` for production | ||
| - `--dst` - The destination slot name. Use `@main` for production | ||
|
|
||
| **Examples:** | ||
|
|
||
| ```bash | ||
| # Swap the staging slot to production | ||
| azd appservice swap --service myapp --src staging --dst @main | ||
|
|
||
| # Interactive mode - prompts for service and slots | ||
| azd appservice swap | ||
|
|
||
| # Swap with production as source | ||
| azd appservice swap --src @main --dst staging | ||
| ``` |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed |
Binary file not shown.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Ensure script fails on any error | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| # Get the directory of the script | ||
| $EXTENSION_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
|
|
||
| # Change to the script directory | ||
| Set-Location -Path $EXTENSION_DIR | ||
|
|
||
| # Create a safe version of EXTENSION_ID replacing dots with dashes | ||
| $EXTENSION_ID_SAFE = $env:EXTENSION_ID -replace '\.', '-' | ||
|
|
||
| # Define output directory | ||
| $OUTPUT_DIR = if ($env:OUTPUT_DIR) { $env:OUTPUT_DIR } else { Join-Path $EXTENSION_DIR "bin" } | ||
|
|
||
| # Create output directory if it doesn't exist | ||
| if (-not (Test-Path -Path $OUTPUT_DIR)) { | ||
| New-Item -ItemType Directory -Path $OUTPUT_DIR | Out-Null | ||
| } | ||
|
|
||
| # Get Git commit hash and build date | ||
| $COMMIT = git rev-parse HEAD | ||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Host "Error: Failed to get git commit hash" | ||
| exit 1 | ||
| } | ||
| $BUILD_DATE = (Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ") | ||
|
|
||
| # List of OS and architecture combinations | ||
| if ($env:EXTENSION_PLATFORM) { | ||
| $PLATFORMS = @($env:EXTENSION_PLATFORM) | ||
| } | ||
| else { | ||
| $PLATFORMS = @( | ||
| "windows/amd64", | ||
| "windows/arm64", | ||
| "darwin/amd64", | ||
| "darwin/arm64", | ||
| "linux/amd64", | ||
| "linux/arm64" | ||
| ) | ||
| } | ||
|
|
||
| $APP_PATH = "$env:EXTENSION_ID/internal/cmd" | ||
|
|
||
| # Loop through platforms and build | ||
| foreach ($PLATFORM in $PLATFORMS) { | ||
| $OS, $ARCH = $PLATFORM -split '/' | ||
|
|
||
| $OUTPUT_NAME = Join-Path $OUTPUT_DIR "$EXTENSION_ID_SAFE-$OS-$ARCH" | ||
|
|
||
| if ($OS -eq "windows") { | ||
| $OUTPUT_NAME += ".exe" | ||
| } | ||
|
|
||
| Write-Host "Building for $OS/$ARCH..." | ||
|
|
||
| # Delete the output file if it already exists | ||
| if (Test-Path -Path $OUTPUT_NAME) { | ||
| Remove-Item -Path $OUTPUT_NAME -Force | ||
| } | ||
|
|
||
| # Set environment variables for Go build | ||
| $env:GOOS = $OS | ||
| $env:GOARCH = $ARCH | ||
|
|
||
| go build ` | ||
| -ldflags="-X '$APP_PATH.Version=$env:EXTENSION_VERSION' -X '$APP_PATH.Commit=$COMMIT' -X '$APP_PATH.BuildDate=$BUILD_DATE'" ` | ||
| -o $OUTPUT_NAME | ||
|
|
||
| if ($LASTEXITCODE -ne 0) { | ||
| Write-Host "An error occurred while building for $OS/$ARCH" | ||
| exit 1 | ||
| } | ||
| } | ||
|
|
||
| Write-Host "Build completed successfully!" | ||
| Write-Host "Binaries are located in the $OUTPUT_DIR directory." |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Get the directory of the script | ||
| EXTENSION_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
|
|
||
| # Change to the script directory | ||
| cd "$EXTENSION_DIR" || exit | ||
|
|
||
| # Create a safe version of EXTENSION_ID replacing dots with dashes | ||
| EXTENSION_ID_SAFE="${EXTENSION_ID//./-}" | ||
|
|
||
| # Define output directory | ||
| OUTPUT_DIR="${OUTPUT_DIR:-$EXTENSION_DIR/bin}" | ||
|
|
||
| # Create output and target directories if they don't exist | ||
| mkdir -p "$OUTPUT_DIR" | ||
|
|
||
| # Get Git commit hash and build date | ||
| COMMIT=$(git rev-parse HEAD) | ||
| BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) | ||
|
|
||
| # List of OS and architecture combinations | ||
| if [ -n "$EXTENSION_PLATFORM" ]; then | ||
| PLATFORMS=("$EXTENSION_PLATFORM") | ||
| else | ||
| PLATFORMS=( | ||
| "windows/amd64" | ||
| "windows/arm64" | ||
| "darwin/amd64" | ||
| "darwin/arm64" | ||
| "linux/amd64" | ||
| "linux/arm64" | ||
| ) | ||
| fi | ||
|
|
||
| APP_PATH="$EXTENSION_ID/internal/cmd" | ||
|
|
||
| # Loop through platforms and build | ||
| for PLATFORM in "${PLATFORMS[@]}"; do | ||
| OS=$(echo "$PLATFORM" | cut -d'/' -f1) | ||
| ARCH=$(echo "$PLATFORM" | cut -d'/' -f2) | ||
|
|
||
| OUTPUT_NAME="$OUTPUT_DIR/$EXTENSION_ID_SAFE-$OS-$ARCH" | ||
|
|
||
| if [ "$OS" = "windows" ]; then | ||
| OUTPUT_NAME+='.exe' | ||
| fi | ||
|
|
||
| echo "Building for $OS/$ARCH..." | ||
|
|
||
| # Delete the output file if it already exists | ||
| [ -f "$OUTPUT_NAME" ] && rm -f "$OUTPUT_NAME" | ||
|
|
||
| # Set environment variables for Go build | ||
| GOOS=$OS GOARCH=$ARCH go build \ | ||
| -ldflags="-X '$APP_PATH.Version=$EXTENSION_VERSION' -X '$APP_PATH.Commit=$COMMIT' -X '$APP_PATH.BuildDate=$BUILD_DATE'" \ | ||
| -o "$OUTPUT_NAME" | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "An error occurred while building for $OS/$ARCH" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| echo "Build completed successfully!" | ||
| echo "Binaries are located in the $OUTPUT_DIR directory." |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # yaml-language-server: $schema=../extension.schema.json | ||
| id: azure.appservice | ||
| namespace: appservice | ||
| displayName: Azure App Service | ||
| description: Extension for managing Azure App Service resources. | ||
| usage: azd appservice <command> [options] | ||
| # NOTE: Make sure version.txt is in sync with this version. | ||
| version: 0.1.0 | ||
| language: go | ||
| capabilities: | ||
| - custom-commands | ||
| examples: | ||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to add the metadata capability for more detailed tracing, etc. |
||
| - name: swap | ||
| description: Swap deployment slots for an App Service. | ||
| usage: azd appservice swap --service <service-name> --src <source-slot> --dst <destination-slot> | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| module azure.appservice | ||
|
|
||
| go 1.25 | ||
|
|
||
| require ( | ||
| github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0 | ||
| github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1 | ||
| github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2 v2.3.0 | ||
| github.com/azure/azure-dev/cli/azd v0.0.0-20260122173819-89795b295491 | ||
| github.com/fatih/color v1.18.0 | ||
| github.com/spf13/cobra v1.10.1 | ||
| ) | ||
|
|
||
| require ( | ||
| dario.cat/mergo v1.0.2 // indirect | ||
| github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect | ||
| github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 // indirect | ||
| github.com/Masterminds/semver/v3 v3.4.0 // indirect | ||
| github.com/alecthomas/chroma/v2 v2.20.0 // indirect | ||
| github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | ||
| github.com/aymerick/douceur v0.2.0 // indirect | ||
| github.com/bahlo/generic-list-go v0.2.0 // indirect | ||
| github.com/blang/semver/v4 v4.0.0 // indirect | ||
| github.com/braydonk/yaml v0.9.0 // indirect | ||
| github.com/buger/jsonparser v1.1.1 // indirect | ||
| github.com/charmbracelet/colorprofile v0.3.2 // indirect | ||
| github.com/charmbracelet/glamour v0.10.0 // indirect | ||
| github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 // indirect | ||
| github.com/charmbracelet/x/ansi v0.10.2 // indirect | ||
| github.com/charmbracelet/x/cellbuf v0.0.13 // indirect | ||
| github.com/charmbracelet/x/exp/slice v0.0.0-20251008171431-5d3777519489 // indirect | ||
| github.com/charmbracelet/x/term v0.2.1 // indirect | ||
| github.com/clipperhouse/uax29/v2 v2.2.0 // indirect | ||
| github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
| github.com/dlclark/regexp2 v1.11.5 // indirect | ||
| github.com/drone/envsubst v1.0.3 // indirect | ||
| github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 // indirect | ||
| github.com/go-logr/logr v1.4.3 // indirect | ||
| github.com/go-logr/stdr v1.2.2 // indirect | ||
| github.com/golang-jwt/jwt/v5 v5.3.0 // indirect | ||
| github.com/golobby/container/v3 v3.3.2 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/gorilla/css v1.0.1 // indirect | ||
| github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| github.com/invopop/jsonschema v0.13.0 // indirect | ||
| github.com/jmespath-community/go-jmespath v1.1.1 // indirect | ||
| github.com/joho/godotenv v1.5.1 // indirect | ||
| github.com/kylelemons/godebug v1.1.0 // indirect | ||
| github.com/lucasb-eyer/go-colorful v1.3.0 // indirect | ||
| github.com/mailru/easyjson v0.9.1 // indirect | ||
| github.com/mattn/go-colorable v0.1.14 // indirect | ||
| github.com/mattn/go-isatty v0.0.20 // indirect | ||
| github.com/mattn/go-runewidth v0.0.19 // indirect | ||
| github.com/microcosm-cc/bluemonday v1.0.27 // indirect | ||
| github.com/microsoft/ApplicationInsights-Go v0.4.4 // indirect | ||
| github.com/microsoft/go-deviceid v1.0.0 // indirect | ||
| github.com/muesli/reflow v0.3.0 // indirect | ||
| github.com/muesli/termenv v0.16.0 // indirect | ||
| github.com/nathan-fiscaletti/consolesize-go v0.0.0-20220204101620-317176b6684d // indirect | ||
| github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect | ||
| github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | ||
| github.com/rivo/uniseg v0.4.7 // indirect | ||
| github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect | ||
| github.com/sethvargo/go-retry v0.3.0 // indirect | ||
| github.com/spf13/pflag v1.0.10 // indirect | ||
| github.com/stretchr/testify v1.11.1 // indirect | ||
| github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect | ||
| github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | ||
| github.com/yuin/goldmark v1.7.13 // indirect | ||
| github.com/yuin/goldmark-emoji v1.0.6 // indirect | ||
| go.opentelemetry.io/auto/sdk v1.2.1 // indirect | ||
| go.opentelemetry.io/otel v1.38.0 // indirect | ||
| go.opentelemetry.io/otel/metric v1.38.0 // indirect | ||
| go.opentelemetry.io/otel/sdk v1.38.0 // indirect | ||
| go.opentelemetry.io/otel/trace v1.38.0 // indirect | ||
| go.uber.org/atomic v1.11.0 // indirect | ||
| golang.org/x/crypto v0.46.0 // indirect | ||
| golang.org/x/exp v0.0.0-20250911091902-df9299821621 // indirect | ||
| golang.org/x/net v0.48.0 // indirect | ||
| golang.org/x/sys v0.39.0 // indirect | ||
| golang.org/x/term v0.38.0 // indirect | ||
| golang.org/x/text v0.32.0 // indirect | ||
| google.golang.org/genproto/googleapis/rpc v0.0.0-20251007200510-49b9836ed3ff // indirect | ||
| google.golang.org/grpc v1.76.0 // indirect | ||
| google.golang.org/protobuf v1.36.10 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) | ||
|
|
||
| replace github.com/azure/azure-dev/cli/azd => ../.. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
azure-appservice?