-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
feat (codespaces) - Add initial support for codespaces #27483
Changes from all commits
4b3eb8e
cbe6d99
8b4e731
e23e916
4d12507
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# [Choice] .NET version: 6.0-focal, 5.0-focal, 3.1-focal | ||
ARG VARIANT="6.0-focal" | ||
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} | ||
|
||
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 | ||
ARG NODE_VERSION="none" | ||
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi | ||
|
||
# Install SQL Tools: SQLPackage and sqlcmd | ||
COPY mssql/installSQLtools.sh installSQLtools.sh | ||
RUN bash ./installSQLtools.sh \ | ||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.222.0/containers/dotnet-mssql | ||
{ | ||
"name": "C# (.NET) and MS SQL", | ||
"dockerComposeFile": "docker-compose.yml", | ||
"service": "app", | ||
"workspaceFolder": "/workspace", | ||
"settings": { | ||
"mssql.connections": [ | ||
{ | ||
"server": "localhost,1433", | ||
"database": "master", | ||
"authenticationType": "SqlLogin", | ||
"user": "sa", | ||
"password": "Pass@word", | ||
"emptyPasswordInput": false, | ||
"savePassword": true, | ||
"profileName": "mssql-container", | ||
"trustServerCertificate": true | ||
} | ||
], | ||
"omnisharp.enableRoslynAnalyzers": true, | ||
"omnisharp.enableEditorConfigSupport": true, | ||
"omnisharp.enableImportCompletion": true, | ||
"omnisharp.useModernNet": true, | ||
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. Oooh! Interesting. I think we probably want to enable this in the aspnetcore repo too. 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. You mean the last option right? |
||
"omnisharp.enableMsBuildLoadProjectsOnDemand": true | ||
}, | ||
"extensions": [ | ||
"ms-dotnettools.csharp", | ||
"ms-mssql.mssql", | ||
"EditorConfig.EditorConfig", | ||
"k--kato.docomment", | ||
], | ||
"remoteEnv": { | ||
"PATH": "${containerWorkspaceFolder}/.dotnet:${containerEnv:PATH}", | ||
"DOTNET_MULTILEVEL_LOOKUP": "0", | ||
"TARGET": "net7.0", | ||
"DOTNET_WATCH_SUPPRESS_LAUNCH_BROWSER": "true", | ||
"Test__SqlServer__DefaultConnection ": "Server=localhost;Database=master;User Id=sa;password=Pass@word;Trusted_Connection=False;MultipleActiveResultSets=true;" | ||
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. Is space at the end of env var correct? While repo will build/test fine if SqlServer is not running, need to see if SqlServer tests actually ran. 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. Yes, before creating this PR, I run all tests with the script which is at the root of the repo, not even a single test case failed! |
||
}, | ||
"postCreateCommand": "bash .devcontainer/mssql/postCreateCommand.sh 'Pass@word' './bin/Debug/' './.devcontainer/mssql/'", | ||
"features": { | ||
"powershell": "latest" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: '3' | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
# Update 'VARIANT' to pick a version of .NET: 3.1-focal, 5.0-focal, 6.0-focal | ||
VARIANT: "6.0-focal" | ||
# Optional version of Node.js | ||
NODE_VERSION: "none" | ||
|
||
volumes: | ||
- ..:/workspace:cached | ||
|
||
# Overrides default command so things don't shut down after the process ends. | ||
command: sleep infinity | ||
|
||
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. | ||
network_mode: service:db | ||
# Uncomment the next line to use a non-root user for all processes. | ||
# user: vscode | ||
|
||
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) | ||
|
||
db: | ||
image: mcr.microsoft.com/mssql/server:2019-latest | ||
restart: unless-stopped | ||
environment: | ||
SA_PASSWORD: Pass@word | ||
ACCEPT_EULA: Y | ||
# Add "forwardPorts": ["1433"] to **devcontainer.json** to forward MSSQL locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
echo "Installing mssql-tools" | ||
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) | ||
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]') | ||
CODENAME=$(lsb_release -cs) | ||
echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-${DISTRO}-${CODENAME}-prod ${CODENAME} main" > /etc/apt/sources.list.d/microsoft.list | ||
apt-get update | ||
ACCEPT_EULA=Y apt-get -y install unixodbc-dev msodbcsql17 libunwind8 mssql-tools | ||
|
||
echo "Installing sqlpackage" | ||
curl -sSL -o sqlpackage.zip "https://aka.ms/sqlpackage-linux" | ||
mkdir /opt/sqlpackage | ||
unzip sqlpackage.zip -d /opt/sqlpackage | ||
rm sqlpackage.zip | ||
chmod a+x /opt/sqlpackage/sqlpackage |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
#!/bin/bash | ||||||
dacpac="false" | ||||||
sqlfiles="false" | ||||||
SApassword=$1 | ||||||
dacpath=$2 | ||||||
sqlpath=$3 | ||||||
|
||||||
echo "SELECT * FROM SYS.DATABASES" | dd of=testsqlconnection.sql | ||||||
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. Any reason not to simplify to:
Suggested change
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 script was automatically created when we asked codespaces to include support for SQL Server. So I didn't touch. |
||||||
for i in {1..60}; | ||||||
do | ||||||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SApassword -d master -i testsqlconnection.sql > /dev/null | ||||||
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. Or even better: sqlcmd supports providing a query on the cmdline with -Q, can use that instead of a temp file 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. the script was created by codespaces itself. I didn't write this! If we can improve it by any means, I am ok with it! :) |
||||||
if [ $? -eq 0 ] | ||||||
then | ||||||
echo "SQL server ready" | ||||||
break | ||||||
else | ||||||
echo "Not ready yet..." | ||||||
sleep 1 | ||||||
fi | ||||||
done | ||||||
rm testsqlconnection.sql | ||||||
|
||||||
for f in $dacpath/* | ||||||
do | ||||||
if [ $f == $dacpath/*".dacpac" ] | ||||||
then | ||||||
dacpac="true" | ||||||
echo "Found dacpac $f" | ||||||
fi | ||||||
done | ||||||
|
||||||
for f in $sqlpath/* | ||||||
do | ||||||
if [ $f == $sqlpath/*".sql" ] | ||||||
then | ||||||
sqlfiles="true" | ||||||
echo "Found SQL file $f" | ||||||
fi | ||||||
done | ||||||
|
||||||
if [ $sqlfiles == "true" ] | ||||||
then | ||||||
for f in $sqlpath/* | ||||||
do | ||||||
if [ $f == $sqlpath/*".sql" ] | ||||||
then | ||||||
echo "Executing $f" | ||||||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SApassword -d master -i $f | ||||||
fi | ||||||
done | ||||||
fi | ||||||
|
||||||
if [ $dacpac == "true" ] | ||||||
then | ||||||
for f in $dacpath/* | ||||||
do | ||||||
if [ $f == $dacpath/*".dacpac" ] | ||||||
then | ||||||
dbname=$(basename $f ".dacpac") | ||||||
echo "Deploying dacpac $f" | ||||||
/opt/sqlpackage/sqlpackage /Action:Publish /SourceFile:$f /TargetServerName:localhost /TargetDatabaseName:$dbname /TargetUser:sa /TargetPassword:$SApassword | ||||||
fi | ||||||
done | ||||||
fi | ||||||
|
||||||
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc | ||||||
source ~/.bashrc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Restore projects", | ||
"type": "shell", | ||
"command": "./restore.sh", | ||
"windows": { | ||
"command": ".\\restore.cmd" | ||
}, | ||
"group": "build", | ||
"presentation": { | ||
"reveal": "always", | ||
"panel": "new" | ||
} | ||
}, | ||
{ | ||
"label": "Build entire repository", | ||
"type": "shell", | ||
"command": "./build.sh", | ||
"windows": { | ||
"command": ".\\build.cmd" | ||
}, | ||
"group": "build", | ||
"presentation": { | ||
"reveal": "always", | ||
"panel": "new" | ||
} | ||
}, | ||
{ | ||
"label": "Build and run all tests", | ||
"type": "shell", | ||
"command": "/test.sh -test", | ||
"windows": { | ||
"command": ".\\test.cmd -test" | ||
}, | ||
"group": "test", | ||
"presentation": { | ||
"reveal": "always", | ||
"panel": "new" | ||
} | ||
}, | ||
{ | ||
"label": "Pack assets", | ||
"type": "shell", | ||
"command": "./eng/build.sh --pack", | ||
"windows": { | ||
"command": ".\\eng\\build.cmd -pack" | ||
}, | ||
"presentation": { | ||
"reveal": "always", | ||
"panel": "new" | ||
} | ||
} | ||
] | ||
} |
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.
I assume this is here so the SQL extension can automatically connect to the dev database from VS Code?
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.
Yes, interestingly, I can able to run tests from the efcore repo directly against this DB!
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.
Test__SqlServer__DefaultConnection
below makes it happen.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.
Yes, exactly I did that based on docs on repo!