Rename dotnetcore-mssql to dotnet-mssql, misc tweaks
This commit is contained in:
Родитель
76455a3e4b
Коммит
32e8097806
|
@ -1,4 +1,4 @@
|
|||
# [Choice] .NET Core version: 3.1, 2.1
|
||||
# [Choice] .NET Core version: 5.0, 3.1, 2.1
|
||||
ARG VARIANT=3.1
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/dotnetcore:${VARIANT}
|
||||
|
||||
|
@ -15,7 +15,18 @@ RUN if [ "$INSTALL_AZURE_CLI" = "true" ]; then bash /tmp/library-scripts/azcli-d
|
|||
|
||||
# Install SQL Tools: SQLPackage and sqlcmd
|
||||
COPY mssql/installSQLtools.sh installSQLtools.sh
|
||||
RUN bash ./installSQLtools.sh
|
||||
RUN bash ./installSQLtools.sh \
|
||||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
|
||||
|
||||
# Update args in docker-compose.yaml to set the UID/GID of the "vscode" user.
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=$USER_UID
|
||||
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
|
||||
groupmod --gid $USER_GID vscode \
|
||||
&& usermod --uid $USER_UID --gid $USER_GID vscode \
|
||||
&& chown -R $USER_UID:$USER_GID /home/vscode \
|
||||
&& chown -R $USER_UID:root /usr/local/share/nvm /usr/local/share/npm-global; \
|
||||
fi
|
||||
|
||||
# [Optional] Uncomment this section to install additional OS packages.
|
||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "C# (.NET Core) and MS SQL",
|
||||
"name": "C# (.NET) and MS SQL",
|
||||
"dockerComposeFile": "docker-compose.yml",
|
||||
"service": "app",
|
||||
"workspaceFolder": "/workspace",
|
||||
|
@ -44,16 +44,11 @@
|
|||
// "ASPNETCORE_Kestrel__Certificates__Default__Path": "/home/vscode/.aspnet/https/aspnetapp.pfx",
|
||||
// },
|
||||
//
|
||||
// 3. Do one of the following depending on your scenario:
|
||||
// * When using GitHub Codespaces and/or Remote - Containers:
|
||||
// 3. Next, copy your certificate into the container:
|
||||
// 1. Start the container
|
||||
// 2. Drag ~/.aspnet/https/aspnetapp.pfx into the root of the file explorer
|
||||
// 3. Open a terminal in VS Code and run "mkdir -p /home/vscode/.aspnet/https && mv aspnetapp.pfx /home/vscode/.aspnet/https"
|
||||
//
|
||||
// * If only using Remote - Containers with a local container, uncomment this line instead:
|
||||
// "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// postCreateCommand.sh parameters: $1=SA password, $2=dacpac path, $3=sql script(s) path
|
||||
"postCreateCommand": "bash .devcontainer/mssql/postCreateCommand.sh 'P@ssw0rd' './bin/Debug/' './.devcontainer/mssql/'"
|
||||
|
|
@ -6,7 +6,7 @@ services:
|
|||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
# [Choice] Update 'VARIANT' to pick a .NET Core version: 2.1, 3.1
|
||||
# [Choice] Update 'VARIANT' to pick a .NET Core version: 2.1, 3.1, 5.0
|
||||
VARIANT: 3.1
|
||||
# Options
|
||||
INSTALL_NODE: "false"
|
||||
|
@ -23,10 +23,10 @@ services:
|
|||
command: sleep infinity
|
||||
|
||||
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
|
||||
network_mode: host
|
||||
network_mode: service:db
|
||||
|
||||
# Uncomment the next line to use a non-root user for all processes.
|
||||
# user: node
|
||||
# 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.)
|
||||
|
@ -37,7 +37,6 @@ services:
|
|||
environment:
|
||||
SA_PASSWORD: P@ssw0rd
|
||||
ACCEPT_EULA: Y
|
||||
network_mode: host
|
||||
|
||||
# Add "forwardPorts": ["1433"] to **devcontainer.json** to forward MSSQL locally.
|
||||
# (Adding the "ports" property to this file will not forward from a Codespace.)
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
set -echo
|
||||
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
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/bash
|
||||
dacpac="false"
|
||||
sqlfiles="false"
|
||||
SApassword=$1
|
||||
|
@ -7,13 +8,13 @@ sqlpath=$3
|
|||
echo "SELECT * FROM SYS.DATABASES" | dd of=testsqlconnection.sql
|
||||
for i in {1..60};
|
||||
do
|
||||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SApassword -d master -i testsqlconnection.sql
|
||||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SApassword -d master -i testsqlconnection.sql > /dev/null
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "sql server ready"
|
||||
echo "SQL server ready"
|
||||
break
|
||||
else
|
||||
echo "not ready yet..."
|
||||
echo "Not ready yet..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
@ -24,7 +25,7 @@ do
|
|||
if [ $f == $dacpath/*".dacpac" ]
|
||||
then
|
||||
dacpac="true"
|
||||
echo "found dacpac $f"
|
||||
echo "Found dacpac $f"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -33,7 +34,7 @@ do
|
|||
if [ $f == $sqlpath/*".sql" ]
|
||||
then
|
||||
sqlfiles="true"
|
||||
echo "found sql file $f"
|
||||
echo "Found SQL file $f"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -43,7 +44,7 @@ then
|
|||
do
|
||||
if [ $f == $sqlpath/*".sql" ]
|
||||
then
|
||||
echo "executing $f"
|
||||
echo "Executing $f"
|
||||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SApassword -d master -i $f
|
||||
fi
|
||||
done
|
||||
|
@ -56,7 +57,7 @@ then
|
|||
if [ $f == $dacpath/*".dacpac" ]
|
||||
then
|
||||
dbname=$(basename $f ".dacpac")
|
||||
echo "deploying dacpac $f"
|
||||
echo "Deploying dacpac $f"
|
||||
/opt/sqlpackage/sqlpackage /Action:Publish /SourceFile:$f /TargetServerName:localhost /TargetDatabaseName:$dbname /TargetUser:sa /TargetPassword:$SApassword
|
||||
fi
|
||||
done
|
|
@ -0,0 +1,6 @@
|
|||
README.md
|
||||
test-project
|
||||
.devcontainer/library-scripts/README.md
|
||||
.devcontainer/mssql/setup.sql
|
||||
.vscode
|
||||
.npmignore
|
|
@ -6,28 +6,27 @@
|
|||
|
||||
| Metadata | Value |
|
||||
|----------|-------|
|
||||
| *Contributors* | The VS Code and Azure Data Teams |
|
||||
| *Contributors* | The Azure Data Team |
|
||||
| *Definition type* | Docker Compose |
|
||||
| *Published images* | mcr.microsoft.com/vscode/devcontainers/dotnetcore |
|
||||
| *Available image variants* | 2.1, 3.1 |
|
||||
| *Published image architecture(s)* | x86-64 |
|
||||
| *Available image variants* | 2.1, 3.1, 5.0 |
|
||||
| *Works in Codespaces* | Yes |
|
||||
| *Container host OS support* | Linux, macOS, Windows |
|
||||
| *Container OS* | Ubuntu |
|
||||
| *Languages, platforms* | .NET Core, C#, Microsoft SQL |
|
||||
| *Languages, platforms* | .NET, .NET Core, C#, Microsoft SQL |
|
||||
|
||||
## Description
|
||||
This definition creates two containers, one for C# (.NET Core) and one for Microsoft SQL. VS Code will attach to the .NET Core container, and from within that container the Microsoft SQL container will be available on **`localhost`** port 1433. By default, the `sa` user password is `P@ssw0rd`. For more on the configuration of MS SQL, see the section [MS SQL Configuration](#MS-SQL-Configuration)
|
||||
|
||||
## Using this definition with an existing folder
|
||||
|
||||
While this definition should work unmodified, you can select the version of .NET Core the container uses by updating the `VARIANT` arg in the included `devcontainer.json` (and rebuilding if you've already created the container).
|
||||
While this definition should work unmodified, you can select the version of .NET Core the container uses by updating the `VARIANT` arg in the included `docker-compose.yml` (and rebuilding if you've already created the container).
|
||||
|
||||
```json
|
||||
"args": { "VARIANT": "3.1" }
|
||||
```yaml
|
||||
args:
|
||||
VARIANT: "3.1"
|
||||
```
|
||||
|
||||
|
||||
### Debug Configuration
|
||||
|
||||
Only the integrated terminal is supported by the Remote - Containers extension. You may need to modify your `.vscode/launch.json` configurations to include the following:
|
||||
|
@ -77,8 +76,6 @@ To enable HTTPS in ASP.NET, you can mount an exported copy of your local dev cer
|
|||
|
||||
3. Finally, make the certificate available in the container as follows:
|
||||
|
||||
**If using GitHub Codespaces and/or Remote - Containers**
|
||||
|
||||
1. Start the container/codespace
|
||||
2. Drag `~/.aspnet/https/aspnetapp.pfx` from your local machine into the root of the File Explorer in VS Code.
|
||||
3. Open a terminal in VS Code and run:
|
||||
|
@ -86,42 +83,43 @@ To enable HTTPS in ASP.NET, you can mount an exported copy of your local dev cer
|
|||
mkdir -p /home/vscode/.aspnet/https && mv aspnetapp.pfx /home/vscode/.aspnet/https
|
||||
```
|
||||
|
||||
**If using only Remote - Containers with a local container**
|
||||
|
||||
Add the following to `.devcontainer/devcontainer.json`:
|
||||
|
||||
```json
|
||||
"mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ]
|
||||
```
|
||||
|
||||
If you've already opened your folder in a container, rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) so the settings take effect.
|
||||
|
||||
### Installing Node.js or the Azure CLI
|
||||
|
||||
Given how frequently ASP.NET applications use Node.js for front end code, this container also includes Node.js. You can change the version of Node.js installed or disable its installation by updating the `args` property in `.devcontainer/devcontainer.json`.
|
||||
Given how frequently ASP.NET applications use Node.js for front end code, this container also includes Node.js. You can change the version of Node.js installed or disable its installation by updating the `args` property in `.devcontainer/docker-compose.yml`.
|
||||
|
||||
```json
|
||||
"args": {
|
||||
"VARIANT": "3.1",
|
||||
"INSTALL_NODE": "true",
|
||||
"NODE_VERSION": "10",
|
||||
}
|
||||
```yaml
|
||||
args:
|
||||
VARIANT: "3.1"
|
||||
INSTALL_NODE: "true"
|
||||
NODE_VERSION: "10"
|
||||
```
|
||||
|
||||
If you would like to install the Azure CLI update you can set the `INSTALL_AZURE_CLI` argument line in `.devcontainer/devcontainer.json`:
|
||||
If you would like to install the Azure CLI update you can set the `INSTALL_AZURE_CLI` argument line in `.devcontainer/docker-compose.yml`:
|
||||
|
||||
```Dockerfile
|
||||
"args": {
|
||||
"VARIANT": "3.1",
|
||||
"INSTALL_NODE": "true",
|
||||
"NODE_VERSION": "10",
|
||||
"INSTALL_AZURE_CLI": "true"
|
||||
}
|
||||
```yaml
|
||||
args:
|
||||
VARIANT: "3.1"
|
||||
INSTALL_NODE: "true"
|
||||
NODE_VERSION: "10"
|
||||
INSTALL_AZURE_CLI: "true"
|
||||
```
|
||||
|
||||
If you've already opened your folder in a container, rebuild the container using the **Remote-Containers: Rebuild Container** command from the Command Palette (<kbd>F1</kbd>) so the settings take effect.
|
||||
|
||||
### Adding the definition to your folder
|
||||
## MS SQL Configuration
|
||||
A secondary container for MS SQL is defined in `devcontainer.json` with the Dockerfile and supporting scripts in the `mssql` folder. This container is deployed from the latest developer edition of Microsoft SQL 2019. The database(s) are made available directly in the Codespace/VS Code through the MSSQL extension with a connection labeled "mssql-container". The default `sa` user password is set to `P@ssw0rd`. The default SQL port is mapped to port `1433` in `docker-compose.yml`.
|
||||
|
||||
### Changing the sa password
|
||||
To change the `sa` user password, change the value in `docker-compose.yml` and `devcontainer.json`.
|
||||
|
||||
### Database deployment
|
||||
By default, a blank user database is created titled "ApplicationDB". To add additional database objects or data through T-SQL during Codespace configuration, edit the file `.devcontainer/mssql/setup.sql` or place additional `.sql` files in the `.devcontainer/mssql/` folder. *Large numbers of scripts may take a few minutes following container creation to complete, even when the SQL server is available the database(s) may not be available yet.*
|
||||
|
||||
Alternatively, .dacpac files placed in the `./bin/Debug` folder will be published as databases in the container during Codespace configuration. [SqlPackage](https://docs.microsoft.com/sql/tools/sqlpackage) is used to deploy a database schema from a data-tier application file (dacpac), allowing you to bring your application's database structures into the dev container easily. *The publish process may take a few minutes following container creation to complete, even when the server is available the database(s) may not be available yet.*
|
||||
|
||||
## Adding the definition to your folder
|
||||
|
||||
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
|
||||
|
||||
|
@ -139,17 +137,6 @@ If you've already opened your folder in a container, rebuild the container using
|
|||
|
||||
5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition.
|
||||
|
||||
## MS SQL Configuration
|
||||
A secondary container for MS SQL is defined in `devcontainer.json` with the Dockerfile and supporting scripts in the `mssql` folder. This container is deployed from the latest developer edition of Microsoft SQL 2019. The database(s) are made available directly in the Codespace/VS Code through the MSSQL extension with a connection labeled "mssql-container". The default `sa` user password is set to `P@ssw0rd`. The default SQL port is mapped to port `1433` in `docker-compose.yml`.
|
||||
|
||||
### Changing the sa password
|
||||
To change the `sa` user password, change the value in `docker-compose.yml` and `devcontainer.json`.
|
||||
|
||||
### Database deployment
|
||||
By default, a blank user database is created titled "ApplicationDB". To add additional database objects or data through T-SQL during Codespace configuration, edit the file `.devcontainer/mssql/setup.sql` or place additional `.sql` files in the `.devcontainer/mssql/` folder. *Large numbers of scripts may take a few minutes following container creation to complete, even when the SQL server is available the database(s) may not be available yet.*
|
||||
|
||||
Alternatively, .dacpac files placed in the `./bin/Debug` folder will be published as databases in the container during Codespace configuration. [SqlPackage](https://docs.microsoft.com/sql/tools/sqlpackage) is used to deploy a database schema from a data-tier application file (dacpac), allowing you to bring your application's database structures into the dev container easily. *The publish process may take a few minutes following container creation to complete, even when the server is available the database(s) may not be available yet.*
|
||||
|
||||
## Testing the definition
|
||||
|
||||
This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:
|
|
@ -1,20 +0,0 @@
|
|||
echo "installing mssql-tools"
|
||||
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
|
||||
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
|
||||
apt-get -y install unixodbc-dev
|
||||
ACCEPT_EULA=Y apt-get -y install msodbcsql17
|
||||
ACCEPT_EULA=Y apt-get -y install mssql-tools
|
||||
|
||||
echo "installing sqlpackage"
|
||||
apt-get -y install wget
|
||||
apt-get -y install libunwind8
|
||||
apt-get -y install libicu60
|
||||
apt-get -y install unzip
|
||||
wget -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
|
|
@ -1,7 +0,0 @@
|
|||
README.md
|
||||
test-project
|
||||
.devcontainer/library-scripts/README.md
|
||||
.devcontainer/library-scripts/common-debian.sh
|
||||
.devcontainer/library-scripts/node-debian.sh
|
||||
.vscode
|
||||
.npmignore
|
Загрузка…
Ссылка в новой задаче