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

dotnet 9.0 migration #4

Merged
merged 4 commits into from
Dec 30, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# [Choice] .NET version: 9.0
FROM mcr.microsoft.com/devcontainers/dotnet:9.0

# Add .NET global tools path
ENV PATH $PATH:/home/vscode/.dotnet:/home/vscode/.dotnet/tools

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends software-properties-common

# Install SQL Tools: SQLPackage and sqlcmd
COPY sql/installSQLtools.sh installSQLtools.sh
RUN bash ./installSQLtools.sh \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts

RUN dotnet tool install -g dotnet-ef
67 changes: 67 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// For format details, see https://aka.ms/devcontainer.json.
// For config options, see the README at: https://github.com/microsoft/azuresql-devcontainers/tree/main/src/dotnet
{
"name": ".NET and Azure SQL",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"mssql.connections": [
{
"server": "localhost,1433",
"database": "master",
"authenticationType": "SqlLogin",
"user": "sa",
"password": "${env:MSSQL_SA_PASSWORD}",
"savePassword": true,
"profileName": "LocalDev",
"trustServerCertificate": true
}
],
"sqlDatabaseProjects.dotnetSDK Location": "/usr/share/dotnet"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-dotnettools.csdevkit",
"ms-dotnettools.csharp",
"ms-azuretools.vscode-bicep",
"ms-mssql.mssql",
"ms-azuretools.vscode-docker",
"github.copilot",
"github.codespaces"
],
"remoteEnv": {
"MSSQL_SA_PASSWORD": "${env:MSSQL_SA_PASSWORD}"
}
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [5000, 5001, 8000, 1433],

// Post create commands to run after the container is created.
"postCreateCommand": "bash .devcontainer/sql/postCreateCommand.sh 'database/Library/bin/Debug'",

// Post start commands to run after the container is started.

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {
"installBicep": true,
"installUsingPython": true,
"version": "latest"
},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"version": "latest"
},
"ghcr.io/azure/azure-dev/azd:latest": {
"version": "latest"
}
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
39 changes: 39 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3'

services:
app:
build:
context: .
dockerfile: Dockerfile

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/azure-sql-edge
hostname: sql-library-db
container_name: sql-library-db
restart: unless-stopped
environment:
ACCEPT_EULA: Y
SA_PASSWORD: "${MSSQL_SA_PASSWORD}"
env_file:
- .env
deploy:
resources:
limits:
cpus: '1'
memory: 2048M
# Add "forwardPorts": ["1433"] to **devcontainer.json** to forward MSSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
15 changes: 15 additions & 0 deletions .devcontainer/sql/installSQLtools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

echo "Installing Go-SQLCmd ..."
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/prod.list)"
sudo apt-get update
sudo apt-get install -y sqlcmd
echo "Go-SQLCmd installed."

echo "Installing Sqlpackage ..."
curl -sSL -o sqlpackage.zip "https://aka.ms/sqlpackage-linux"
mkdir -p /opt/sqlpackage
unzip sqlpackage.zip -d /opt/sqlpackage && rm sqlpackage.zip
chmod a+x /opt/sqlpackage/sqlpackage
echo "Sqlpackage installed."
56 changes: 56 additions & 0 deletions .devcontainer/sql/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Setting variables
dacpac="false"

# Load SA_PASSWORD from .env file
export $(grep -v '^#' .devcontainer/.env | xargs)
SApassword=$MSSQL_SA_PASSWORD

# Parameters
dacpath=$1

# Extract the project directory from the dacpath
projectDir=$(echo $dacpath | cut -d'/' -f1-2)

echo "SELECT * FROM SYS.DATABASES" | dd of=testsqlconnection.sql
for i in {1..30};
do
sqlcmd -S localhost -U sa -P $SApassword -d master -i testsqlconnection.sql > /dev/null
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

if [ $dacpac == "true" ]
then
# Build the SQL Database project
echo "Building SQL Database project at $projectDir..."
dotnet build $projectDir

for f in $dacpath/*
do
if [ $f == $dacpath/*".dacpac" ]
then
dbname=$(basename $f ".dacpac")
# Deploy the dacpac
echo "Deploying dacpac $f"
/opt/sqlpackage/sqlpackage /Action:Publish /SourceFile:$f /TargetServerName:localhost /TargetDatabaseName:$dbname /TargetUser:sa /TargetPassword:$SApassword /TargetTrustServerCertificate:True
fi
done
fi
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI - Build and Test

on:
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 9.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore --configuration Release

- name: Test
run: dotnet test --no-build --configuration Release
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,6 @@ healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

# End of https://www.gitignore.io/api/linux,macos,windows,visualstudio,visualstudiocode
# End of https://www.gitignore.io/api/linux,macos,windows,visualstudio,visualstudiocode

.env
39 changes: 39 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/TinyPlants/bin/Debug/net9.0/TinyPlants.dll",
"args": [],
"cwd": "${workspaceFolder}/src/TinyPlants",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
"name": "Docker .NET Launch",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"netCore": {
"appProject": "${workspaceFolder}/src/TinyPlants/TinyPlants.csproj"
}
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "1. Verify database schema and data",
"type": "shell",
"command": "code",
"args": [
"--goto",
"${workspaceFolder}/scripts/verifyDatabase.sql"
],
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "2. Build SQL Database project",
"type": "shell",
"command": "dotnet build",
"options": {
"cwd": "${workspaceFolder}/database/Library"
}
},
{
"label": "3. Publish SQL Database project",
"type": "shell",
"command": "bash",
"args": [
".devcontainer/sql/postCreateCommand.sh",
"database/Library/bin/Debug"
]
},
{
"label": "4. Trust .NET HTTPS certificate",
"type": "shell",
"command": "dotnet dev-certs https --trust"
}
]
}
27 changes: 27 additions & 0 deletions TinyPlants.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D600E920-8966-4794-9E1F-6CB7CDA297B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TinyPlants", "src\TinyPlants\TinyPlants.csproj", "{94E186EB-2D74-483D-9794-37971C9608A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{94E186EB-2D74-483D-9794-37971C9608A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94E186EB-2D74-483D-9794-37971C9608A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94E186EB-2D74-483D-9794-37971C9608A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94E186EB-2D74-483D-9794-37971C9608A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{94E186EB-2D74-483D-9794-37971C9608A2} = {D600E920-8966-4794-9E1F-6CB7CDA297B0}
EndGlobalSection
EndGlobal
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/vscode-azure-sql-devcontainers-tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Loading
Loading