Skip to content

Commit 15704cc

Browse files
authored
Merge pull request #78 from Azure-Samples/8.0
8.0
2 parents ea91fc1 + 974362e commit 15704cc

File tree

114 files changed

+3938
-2720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+3938
-2720
lines changed

.devcontainer/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM mcr.microsoft.com/devcontainers/dotnet:1-8.0-bookworm
2+
3+
# Install SQL Tools: SQLPackage and sqlcmd
4+
COPY mssql/installSQLtools.sh installSQLtools.sh
5+
RUN bash ./installSQLtools.sh \
6+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
7+
8+
# [Optional] Uncomment this section to install additional OS packages.
9+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
10+
# && apt-get -y install --no-install-recommends <your-package-list-here>
11+
12+
# [Optional] Uncomment this line to install global node packages.
13+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

.devcontainer/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# .devcontainer directory
2+
3+
This `.devcontainer` directory contains the configuration for a [dev container](https://docs.github.com/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers) and isn't used by the sample application.
4+
5+
The dev container configuration lets you open the repository in a [GitHub codespace](https://docs.github.com/codespaces/overview) or a dev container in Visual Studio Code. For your convenience, the dev container is configured with the following:
6+
7+
- .NET 8
8+
- SQL Server
9+
- [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) (so you can run `azd` commands directly).
10+
- GitHub Copilot
11+
- SQL Server extension (uncomment code in [devcontainer.json](devcontainer.json)).

.devcontainer/devcontainer.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet-mssql
3+
{
4+
"name": "C# (.NET) and MS SQL",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
9+
"features": {
10+
"ghcr.io/azure/azure-dev/azd:latest": {}
11+
},
12+
13+
"customizations": {
14+
"vscode": {
15+
// "settings": {
16+
// // Default connection settings for the SQL Server (mssql) extension
17+
// "mssql.connections": [
18+
// {
19+
// "server": "localhost,1433",
20+
// "database": "",
21+
// "authenticationType": "SqlLogin",
22+
// "user": "sa",
23+
// "password": "P@ssw0rd",
24+
// "emptyPasswordInput": false,
25+
// "savePassword": true,
26+
// "profileName": "mssql-container",
27+
// "trustServerCertificate": true
28+
// }
29+
// ]
30+
// },
31+
32+
"extensions": [
33+
// To use the SQL Server (mssql) extension, uncomment the connection settings above too
34+
// "ms-mssql.mssql",
35+
"GitHub.copilot"
36+
]
37+
}
38+
},
39+
40+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
41+
// "forwardPorts": [5000, 5001],
42+
// "portsAttributes": {
43+
// "5001": {
44+
// "protocol": "https"
45+
// }
46+
// }
47+
48+
// postCreateCommand.sh parameters: $1=SA password, $2=dacpac path, $3=sql script(s) path
49+
"postCreateCommand": "bash .devcontainer/mssql/postCreateCommand.sh 'P@ssw0rd' './bin/Debug/' './.devcontainer/mssql/'"
50+
51+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
52+
// "remoteUser": "root"
53+
}

.devcontainer/docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
9+
volumes:
10+
- ../..:/workspaces:cached
11+
12+
# Overrides default command so things don't shut down after the process ends.
13+
command: sleep infinity
14+
15+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
16+
network_mode: service:db
17+
18+
# Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
19+
# user: root
20+
21+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
22+
# (Adding the "ports" property to this file will not forward from a Codespace.)
23+
24+
db:
25+
image: mcr.microsoft.com/mssql/server:2019-latest
26+
restart: unless-stopped
27+
environment:
28+
SA_PASSWORD: P@ssw0rd
29+
ACCEPT_EULA: Y
30+
31+
# Add "forwardPorts": ["db:1433"] to **devcontainer.json** to forward MSSQL locally.
32+
# (Adding the "ports" property to this file will not forward from a Codespace.)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
echo "Installing mssql-tools"
3+
curl -sSL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT)
4+
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
5+
CODENAME=$(lsb_release -cs)
6+
echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-${DISTRO}-${CODENAME}-prod ${CODENAME} main" > /etc/apt/sources.list.d/microsoft.list
7+
apt-get update
8+
ACCEPT_EULA=Y apt-get -y install unixodbc-dev msodbcsql17 libunwind8 mssql-tools
9+
10+
echo "Installing sqlpackage"
11+
curl -sSL -o sqlpackage.zip "https://aka.ms/sqlpackage-linux"
12+
mkdir /opt/sqlpackage
13+
unzip sqlpackage.zip -d /opt/sqlpackage
14+
rm sqlpackage.zip
15+
chmod a+x /opt/sqlpackage/sqlpackage
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
dacpac="false"
3+
sqlfiles="false"
4+
SApassword=$1
5+
dacpath=$2
6+
sqlpath=$3
7+
8+
echo "SELECT * FROM SYS.DATABASES" | dd of=testsqlconnection.sql
9+
for i in {1..60};
10+
do
11+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SApassword -d master -i testsqlconnection.sql > /dev/null
12+
if [ $? -eq 0 ]
13+
then
14+
echo "SQL server ready"
15+
break
16+
else
17+
echo "Not ready yet..."
18+
sleep 1
19+
fi
20+
done
21+
rm testsqlconnection.sql
22+
23+
for f in $dacpath/*
24+
do
25+
if [ $f == $dacpath/*".dacpac" ]
26+
then
27+
dacpac="true"
28+
echo "Found dacpac $f"
29+
fi
30+
done
31+
32+
for f in $sqlpath/*
33+
do
34+
if [ $f == $sqlpath/*".sql" ]
35+
then
36+
sqlfiles="true"
37+
echo "Found SQL file $f"
38+
fi
39+
done
40+
41+
if [ $sqlfiles == "true" ]
42+
then
43+
for f in $sqlpath/*
44+
do
45+
if [ $f == $sqlpath/*".sql" ]
46+
then
47+
echo "Executing $f"
48+
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SApassword -d master -i $f
49+
fi
50+
done
51+
fi
52+
53+
if [ $dacpac == "true" ]
54+
then
55+
for f in $dacpath/*
56+
do
57+
if [ $f == $dacpath/*".dacpac" ]
58+
then
59+
dbname=$(basename $f ".dacpac")
60+
echo "Deploying dacpac $f"
61+
/opt/sqlpackage/sqlpackage /Action:Publish /SourceFile:$f /TargetTrustServerCertificate:True /TargetServerName:db /TargetDatabaseName:$dbname /TargetUser:sa /TargetPassword:$SApassword
62+
fi
63+
done
64+
fi
65+
66+
dotnet tool install --global dotnet-ef --version 8.*

.devcontainer/mssql/setup.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE DATABASE ApplicationDB;
2+
GO

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

0 commit comments

Comments
 (0)