diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..29742583 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,10 @@ +FROM mcr.microsoft.com/devcontainers/dotnet:0-6.0 + +# 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 + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..bf468390 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,68 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet-mssql +{ + "name": "C# (.NET) and MS SQL", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Configure tool-specific properties. + "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": "", + "authenticationType": "SqlLogin", + "user": "sa", + "password": "P@ssw0rd", + "emptyPasswordInput": false, + "savePassword": false, + "profileName": "mssql-container" + } + ] + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-dotnettools.csharp", + "ms-mssql.mssql", + "ms-dotnettools.csdevkit" + ] + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 1433, + 5000, + 5001 + ], + "portsAttributes": { + "5001": { + "protocol": "https" + } + }, + // 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/'", + "features": { + "ghcr.io/devcontainers/features/azure-cli:1": { + "installBicep": true, + "version": "latest" + }, + "ghcr.io/devcontainers/features/dotnet:1": { + "installUsingApt": true, + "version": "6" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "installDirectlyFromGitHubRelease": true, + "version": "latest" + }, + "ghcr.io/rchaganti/vsc-devcontainer-features/azurebicep:1": {}, + "ghcr.io/stuartleeks/dev-container-features/azure-cli-persistence:0": {} + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..e8c1dfd0 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3' + +services: + app: + build: + context: . + dockerfile: Dockerfile + + volumes: + - ../..:/workspaces: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 to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + # user: root + + # 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: P@ssw0rd + 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.) diff --git a/.devcontainer/mssql/installSQLtools.sh b/.devcontainer/mssql/installSQLtools.sh new file mode 100644 index 00000000..d45e44b2 --- /dev/null +++ b/.devcontainer/mssql/installSQLtools.sh @@ -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 diff --git a/.devcontainer/mssql/postCreateCommand.sh b/.devcontainer/mssql/postCreateCommand.sh new file mode 100644 index 00000000..08539f92 --- /dev/null +++ b/.devcontainer/mssql/postCreateCommand.sh @@ -0,0 +1,65 @@ +#!/bin/bash +dacpac="false" +sqlfiles="false" +SApassword=$1 +dacpath=$2 +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 > /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 + +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 \ No newline at end of file diff --git a/.devcontainer/mssql/setup.sql b/.devcontainer/mssql/setup.sql new file mode 100644 index 00000000..e108026a --- /dev/null +++ b/.devcontainer/mssql/setup.sql @@ -0,0 +1,2 @@ +CREATE DATABASE ApplicationDB; +GO \ No newline at end of file diff --git a/coffeecard/.vscode/launch.json b/coffeecard/.vscode/launch.json new file mode 100644 index 00000000..f561964c --- /dev/null +++ b/coffeecard/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Core API", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/CoffeeCard.WebApi/bin/Debug/net6.0/CoffeeCard.WebApi.dll", + "args": [], + "cwd": "${workspaceFolder}/CoffeeCard.WebApi", + "stopAtEntry": false, + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": "Attach .NET debugger", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/coffeecard/.vscode/tasks.json b/coffeecard/.vscode/tasks.json new file mode 100644 index 00000000..b1d0a525 --- /dev/null +++ b/coffeecard/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/CoffeeCardAPI.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/CoffeeCardAPI.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/CoffeeCardAPI.sln" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.WebApi/appsettings.json b/coffeecard/CoffeeCard.WebApi/appsettings.json index a5aaf876..10e2c4f5 100644 --- a/coffeecard/CoffeeCard.WebApi/appsettings.json +++ b/coffeecard/CoffeeCard.WebApi/appsettings.json @@ -9,7 +9,7 @@ "DeploymentUrl": "https://localhost:8080/" }, "DatabaseSettings": { - "ConnectionString": "Server=mssql;Initial Catalog=master;User=sa;Password=Your_password123;TrustServerCertificate=True;", + "ConnectionString": "Server=localhost;Initial Catalog=master;User=sa;Password=P@ssw0rd;TrustServerCertificate=True;", "SchemaName": "dbo" }, "IdentitySettings": { diff --git a/coffeecard/docker-compose.yml b/coffeecard/docker-compose.yml index ab267636..11e41409 100644 --- a/coffeecard/docker-compose.yml +++ b/coffeecard/docker-compose.yml @@ -6,7 +6,7 @@ services: container_name: mssql hostname: mssql environment: - SA_PASSWORD: "Your_password123" + SA_PASSWORD: "P@ssw0rd" ACCEPT_EULA: "Y" restart: unless-stopped ports: