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

Added devcontainer for spec writers #24622

Merged
merged 4 commits into from
Jul 7, 2023
Merged
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
21 changes: 21 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04

RUN apt-get -y update && apt upgrade -y && apt install curl -y
RUN apt-get -y install git

# install node and npm
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt -y install nodejs
RUN npm install -g npm@9.5.0

# install oav tool
RUN npm install -g oav@latest

# install powershell
RUN apt-get update && apt-get install -y wget
RUN wget -q https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN apt-get update
RUN apt-get install -y powershell

ENTRYPOINT ["/bin/bash"]
12 changes: 12 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "TypeSpec Dev Container",
"build": {
"dockerfile": "Dockerfile"
},
"remoteUser": "root"
/*,
update below source folder to your local sdk-repos folder
"mounts": [
"source=/home/rc/repos/tmp/sdk-repos,target=/workspaces/sdk-repos,type=bind,consistency=cached"
]*/
}
76 changes: 73 additions & 3 deletions eng/scripts/TypeSpec-Generate-Sdk.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
###
# Conventient usage:
# 1) generate specific language sdk based on current typespec folder
# ./TypeSpec-Generate-Sdk.ps1 -SdkLanguage {language}
# e.g. ./TypeSpec-Generate-Sdk.ps1 -SdkLanguage dotnet
# The pre-requisite is the sdk repos path in local machine follows below convention:
# 1). "azure-rest-api-specs" and "sdk-repos" are peer folder under same parent folder
# 2). each sdk language repo is under "sdk-repos" folder, i.e.
# sdk-repos/azure-sdk-for-net
# sdk-repos/azure-sdk-for-java
# sdk-repos/azure-sdk-for-python
# sdk-repos/azure-sdk-for-js
###

[CmdletBinding()]
param (
[Parameter(Position = 0)]
Expand All @@ -8,11 +22,67 @@ param (
[Parameter(Position = 2)]
[string] $CommitHash,
[Parameter(Position = 3)]
[string] $RepoUrl
[string] $RepoUrl,
[string] $SdkLanguage
)

if ($TypeSpecProjectDirectory -contains ".") {
$TypeSpecProjectDirectory = Resolve-Path $TypeSpecProjectDirectory
$TypeSpecProjectDirectory = (Resolve-Path $TypeSpecProjectDirectory).Path

if ($SdkLanguage) {
# example value of TypeSpecProjectDirectory: /workspaces/azure-rest-api-specs/specification/contosowidgetmanager/Contoso.WidgetManager
$index = $TypeSpecProjectDirectory.IndexOf("specification")
if ($index -eq -1) {
Write-Error "The input TypeSpecProjectDirectory parameter doesn't have 'specification' folder in its path: $TypeSpecProjectDirectory"
exit 1
}
$specFolderPath = $TypeSpecProjectDirectory.Substring(0, $index - 1)
$rootPath = Split-Path $specFolderPath -Parent
$sdkRepoRoot = Join-Path $rootPath "sdk-repos"
if (!(Test-Path $sdkRepoRoot)) {
Write-Error "sdk repos root folder doesn't eixst: $sdkRepoRoot"
exit 1
}

# trying to locate the default sdk repo folder under 'sdk-repos' folder by language value
switch ($SdkLanguage) {
"dotnet" {
Write-Host "Generating dotnet sdk code ..."
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-net"
if (!(Test-Path $sdkRepoPath)) {
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
exit 1
}
}
"java" {
Write-Host "Generating java sdk code ..."
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-java"
if (!(Test-Path $sdkRepoPath)) {
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
exit 1
}
}
"python" {
Write-Host "Generating python sdk code ..."
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-python"
if (!(Test-Path $sdkRepoPath)) {
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
exit 1
}
}
"js" {
Write-Host "Generating js sdk code ..."
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-js"
if (!(Test-Path $sdkRepoPath)) {
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
exit 1
}
}
default {
Write-Error "The input SdkLanguage parameter should be one of this values: dotnet, java, python, js"
exit 1
}
}
$SdkRepoRootDirectory = $sdkRepoPath
}

try {
Expand Down