Skip to content

Commit 699c38e

Browse files
authored
Added devcontainer for spec writers (Azure#24622)
* Added devcontainer for spec authors * Adding dockerfile * Adding comment * Adding convenient usage and conventions of the sdk repo path
1 parent 310a010 commit 699c38e

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

.devcontainer/Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04
2+
3+
RUN apt-get -y update && apt upgrade -y && apt install curl -y
4+
RUN apt-get -y install git
5+
6+
# install node and npm
7+
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
8+
RUN apt -y install nodejs
9+
RUN npm install -g [email protected]
10+
11+
# install oav tool
12+
RUN npm install -g oav@latest
13+
14+
# install powershell
15+
RUN apt-get update && apt-get install -y wget
16+
RUN wget -q https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
17+
RUN dpkg -i packages-microsoft-prod.deb
18+
RUN apt-get update
19+
RUN apt-get install -y powershell
20+
21+
ENTRYPOINT ["/bin/bash"]

.devcontainer/devcontainer.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "TypeSpec Dev Container",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"remoteUser": "root"
7+
/*,
8+
update below source folder to your local sdk-repos folder
9+
"mounts": [
10+
"source=/home/rc/repos/tmp/sdk-repos,target=/workspaces/sdk-repos,type=bind,consistency=cached"
11+
]*/
12+
}

eng/scripts/TypeSpec-Generate-Sdk.ps1

+73-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
###
2+
# Conventient usage:
3+
# 1) generate specific language sdk based on current typespec folder
4+
# ./TypeSpec-Generate-Sdk.ps1 -SdkLanguage {language}
5+
# e.g. ./TypeSpec-Generate-Sdk.ps1 -SdkLanguage dotnet
6+
# The pre-requisite is the sdk repos path in local machine follows below convention:
7+
# 1). "azure-rest-api-specs" and "sdk-repos" are peer folder under same parent folder
8+
# 2). each sdk language repo is under "sdk-repos" folder, i.e.
9+
# sdk-repos/azure-sdk-for-net
10+
# sdk-repos/azure-sdk-for-java
11+
# sdk-repos/azure-sdk-for-python
12+
# sdk-repos/azure-sdk-for-js
13+
###
14+
115
[CmdletBinding()]
216
param (
317
[Parameter(Position = 0)]
@@ -8,11 +22,67 @@ param (
822
[Parameter(Position = 2)]
923
[string] $CommitHash,
1024
[Parameter(Position = 3)]
11-
[string] $RepoUrl
25+
[string] $RepoUrl,
26+
[string] $SdkLanguage
1227
)
1328

14-
if ($TypeSpecProjectDirectory -contains ".") {
15-
$TypeSpecProjectDirectory = Resolve-Path $TypeSpecProjectDirectory
29+
$TypeSpecProjectDirectory = (Resolve-Path $TypeSpecProjectDirectory).Path
30+
31+
if ($SdkLanguage) {
32+
# example value of TypeSpecProjectDirectory: /workspaces/azure-rest-api-specs/specification/contosowidgetmanager/Contoso.WidgetManager
33+
$index = $TypeSpecProjectDirectory.IndexOf("specification")
34+
if ($index -eq -1) {
35+
Write-Error "The input TypeSpecProjectDirectory parameter doesn't have 'specification' folder in its path: $TypeSpecProjectDirectory"
36+
exit 1
37+
}
38+
$specFolderPath = $TypeSpecProjectDirectory.Substring(0, $index - 1)
39+
$rootPath = Split-Path $specFolderPath -Parent
40+
$sdkRepoRoot = Join-Path $rootPath "sdk-repos"
41+
if (!(Test-Path $sdkRepoRoot)) {
42+
Write-Error "sdk repos root folder doesn't eixst: $sdkRepoRoot"
43+
exit 1
44+
}
45+
46+
# trying to locate the default sdk repo folder under 'sdk-repos' folder by language value
47+
switch ($SdkLanguage) {
48+
"dotnet" {
49+
Write-Host "Generating dotnet sdk code ..."
50+
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-net"
51+
if (!(Test-Path $sdkRepoPath)) {
52+
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
53+
exit 1
54+
}
55+
}
56+
"java" {
57+
Write-Host "Generating java sdk code ..."
58+
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-java"
59+
if (!(Test-Path $sdkRepoPath)) {
60+
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
61+
exit 1
62+
}
63+
}
64+
"python" {
65+
Write-Host "Generating python sdk code ..."
66+
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-python"
67+
if (!(Test-Path $sdkRepoPath)) {
68+
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
69+
exit 1
70+
}
71+
}
72+
"js" {
73+
Write-Host "Generating js sdk code ..."
74+
$sdkRepoPath = Join-Path $sdkRepoRoot "azure-sdk-for-js"
75+
if (!(Test-Path $sdkRepoPath)) {
76+
Write-Error "sdk repo doesn't exist: $sdkRepoPath"
77+
exit 1
78+
}
79+
}
80+
default {
81+
Write-Error "The input SdkLanguage parameter should be one of this values: dotnet, java, python, js"
82+
exit 1
83+
}
84+
}
85+
$SdkRepoRootDirectory = $sdkRepoPath
1686
}
1787

1888
try {

0 commit comments

Comments
 (0)