Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .devcontainer/EXAMPLES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Example: Using Azure Login Action in Dev Containers

This example demonstrates how to use the Azure Login action in a GitHub Actions workflow
with dev containers for testing.

## Basic Workflow with Dev Container

```yaml
name: Test in Dev Container

on: [push, pull_request]

jobs:
test-in-devcontainer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build and run dev container
uses: devcontainers/ci@v0.3
with:
runCmd: |
# The dev container has Azure CLI and PowerShell pre-installed
az version
pwsh -Command '$PSVersionTable'

# Run the build and test
npm run build
npm test

azure-login-test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

steps:
- name: Azure Login with OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Run Azure CLI commands
run: |
az account show
az group list
```

## Dev Container Testing Workflow

```yaml
name: Dev Container Validation

on:
push:
paths:
- '.devcontainer/**'
- 'src/**'
pull_request:

jobs:
validate-devcontainer:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Test Dev Container
uses: devcontainers/ci@v0.3
with:
runCmd: |
# Verify all tools are available
node --version
npm --version
az version
pwsh --version
gh --version

# Run development workflow
.devcontainer/dev.sh check
.devcontainer/dev.sh dev
```

## Local Development

For local development, use the dev container directly:

1. Open repository in VS Code
2. Install the "Dev Containers" extension
3. Click "Reopen in Container"
4. Run commands:
```bash
# Quick development workflow
.devcontainer/dev.sh dev

# Or manually
npm install
npm run build
npm test
```

## Benefits

- **Consistent Environment**: Same tools across all developers and CI
- **Pre-configured Azure Tools**: Azure CLI and PowerShell ready to use
- **GNU Utilities**: Full Unix toolchain for scripting
- **Fast Setup**: No manual installation required
146 changes: 146 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Azure Login Action Dev Container

This development container provides a pre-configured environment for developing and testing the Azure Login GitHub Action.

## What's Included

- **Node.js 20** - JavaScript/TypeScript runtime
- **Azure CLI** - Command-line tools for Azure
- **PowerShell** - Cross-platform PowerShell for Azure PowerShell module

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Consider using the plural "modules" for Azure PowerShell here.

This keeps the terminology consistent with your later reference to "Azure PowerShell modules."

Suggested change
- **PowerShell** - Cross-platform PowerShell for Azure PowerShell module
- **PowerShell** - Cross-platform PowerShell for Azure PowerShell modules

- **GitHub CLI** - Command-line tools for GitHub
- **GNU Core Utilities** - Standard Unix tools (bash, grep, sed, etc.)
- **VS Code Extensions** - Azure and development tools

## Quick Start

### Using VS Code

1. Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
2. Open this repository in VS Code
3. Click "Reopen in Container" when prompted (or use Command Palette: `Dev Containers: Reopen in Container`)
4. Wait for the container to build and start

### Using GitHub Codespaces

1. Click the "Code" button on the GitHub repository
2. Select "Codespaces" tab
3. Click "Create codespace on main" (or your branch)

## Features

### Pre-installed Tools

- Azure CLI configured and ready to use
- PowerShell with support for Azure PowerShell modules
- All npm dependencies installed automatically
- GNU utilities for shell scripting and automation

### Optimized for Development

- **Persistent Azure credentials** (optional): You can mount your `~/.azure` folder by adding this to `.devcontainer/devcontainer.json`:
```json
"mounts": [
"source=${localEnv:HOME}/.azure,target=/home/node/.azure,type=bind,consistency=cached"
]
```
Note: This requires the `HOME` environment variable on your host system (Linux/Mac). Windows users should use `${localEnv:USERPROFILE}/.azure` instead.
- **Auto-install dependencies**: `npm install` runs automatically on container creation
- **Consistent environment**: Everyone uses the same tool versions

### Environment Variables

- `AZURE_CORE_NO_COLOR=true` - Disables colored output for easier log parsing

## Building and Testing

### Using the Development Helper Script

The dev container includes a helper script that streamlines common tasks:

```bash
# Run environment checks
.devcontainer/dev.sh check

# Quick development workflow (build + test)
.devcontainer/dev.sh dev

# Full setup (install dependencies + build)
.devcontainer/dev.sh setup

# Validate Azure configuration
.devcontainer/dev.sh validate

# View all available commands
.devcontainer/dev.sh help
```

### Manual Commands

#### Build the Action

```bash
npm run build
```

#### Run Tests

```bash
npm test
```

#### Test Azure CLI

```bash
az version
az login # If needed
az account show
```

#### Test PowerShell

```bash
pwsh
# In PowerShell:
$PSVersionTable
Get-Command Connect-AzAccount
```

## Streamlined Workflow

This dev container streamlines the development process by:

1. **Eliminating setup time** - No need to install Azure CLI, PowerShell, or Node.js manually
2. **Ensuring consistency** - All developers use the same tool versions
3. **Simplifying Azure testing** - Azure CLI and PowerShell are pre-configured
4. **Supporting GNU tools** - Full suite of Unix utilities for scripting and automation

## Customization

To add more features, edit `.devcontainer/devcontainer.json` and add features from:
- [Dev Container Features](https://containers.dev/features)
- [Microsoft Features](https://github.com/devcontainers/features)

## Troubleshooting

### Azure credentials not persisting

By default, Azure credentials are not persisted between container rebuilds. To persist credentials:

1. Add a mount configuration to `.devcontainer/devcontainer.json`:
- **Linux/Mac**: `"source=${localEnv:HOME}/.azure,target=/home/node/.azure,type=bind,consistency=cached"`
- **Windows**: `"source=${localEnv:USERPROFILE}/.azure,target=/home/node/.azure,type=bind,consistency=cached"`
2. Make sure the `.azure` folder exists on your host machine before starting the container
3. Rebuild the container

### Container build fails

Try rebuilding without cache:
- VS Code: Command Palette → `Dev Containers: Rebuild Container Without Cache`
- CLI: `docker build --no-cache`

### npm install fails

The container automatically runs `npm install` on creation. If it fails:
1. Check your internet connection
2. Rebuild the container
3. Manually run `npm install` in the container terminal
Loading
Loading