From 523aa6c12e19163747b9f479451eaa10680bc617 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Tue, 23 Aug 2022 13:12:45 +0100 Subject: [PATCH] V10 Fixup GitHub CodeSpaces / VSCode Remote Container (#12882) * Remove SQL Server part of the CodeSpace - we have SQLite to use * Update to use .NET 6 and simplified docker stuff https://github.com/microsoft/vscode-dev-containers/ * Need to set the SQLite Connection string env variable * Path to SLN has changed to the root of the repo * Fix up launch and VSCode tasks --- .devcontainer/Dockerfile | 39 +++-------- .devcontainer/devcontainer.json | 30 ++------- .devcontainer/docker-compose.yml | 25 ++------ .devcontainer/library-scripts/azcli-debian.sh | 33 ---------- .devcontainer/mssql/BlankDb.sql | 11 ---- .devcontainer/mssql/installSQLtools.sh | 16 ----- .devcontainer/mssql/postCreateCommand.sh | 64 ------------------- .vscode/launch.json | 5 +- .vscode/tasks.json | 3 +- 9 files changed, 23 insertions(+), 203 deletions(-) delete mode 100644 .devcontainer/library-scripts/azcli-debian.sh delete mode 100644 .devcontainer/mssql/BlankDb.sql delete mode 100644 .devcontainer/mssql/installSQLtools.sh delete mode 100644 .devcontainer/mssql/postCreateCommand.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0f5a12b34b..a6303468cc 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,36 +1,15 @@ -# [Choice] .NET Core version: 5.0, 3.1, 2.1 -ARG VARIANT=3.1 -FROM mcr.microsoft.com/vscode/devcontainers/dotnetcore:0-${VARIANT} +# [Choice] .NET version: 6.0, 3.1, 6.0-bullseye, 3.1-bullseye, 6.0-focal, 3.1-focal +ARG VARIANT=6.0-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} -# [Option] Install Node.js -ARG INSTALL_NODE="true" -ARG NODE_VERSION="lts/*" -RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi - -# [Option] Install Azure CLI -ARG INSTALL_AZURE_CLI="false" -COPY library-scripts/azcli-debian.sh /tmp/library-scripts/ -RUN if [ "$INSTALL_AZURE_CLI" = "true" ]; then bash /tmp/library-scripts/azcli-debian.sh; fi \ - && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts - -# 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 - -# 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; fi +# [Choice] Node.js version: none, lts/*, 18, 16, 14 +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 # [Optional] Uncomment this section to install additional OS packages. -# Following added by Warren... -# Needed to add as Gifsicle used by gulp-imagemin does not ship a Linux binary and has to be compiled from source -# And this Linux package is needed in order to build it -# https://github.com/imagemin/imagemin-gifsicle/issues/40#issuecomment-616487214 -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends dh-autoreconf chromium-browser +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends # [Optional] Uncomment this line to install global node packages. # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 @@ -42,7 +21,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # Needing to set unsafe-perm as root is the user setup # https://docs.npmjs.com/cli/v6/using-npm/config#unsafe-perm # Default: false if running as root, true otherwise (we are ROOT) -RUN npm -g config set user vscode && npm -g config set unsafe-perm +#RUN npm -g config set user vscode && npm -g config set unsafe-perm # Generate and trust a local developer certificate for Kestrel # This is needed for Kestrel to bind on https diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index dfda3a4f94..4b1f593281 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,26 +1,13 @@ // 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.158.0/containers/dotnet-mssql +// https://github.com/microsoft/vscode-dev-containers/tree/main/containers/dotnet { - "name": "C# (.NET) and MS SQL", + "name": "C# (.NET) Umbraco & SMTP4Dev", "dockerComposeFile": "docker-compose.yml", "service": "app", "workspaceFolder": "/workspace", - + // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.shell.linux": "/bin/bash", - "mssql.connections": [ - { - "server": "localhost,1433", - "database": "", - "authenticationType": "SqlLogin", - "user": "sa", - "password": "P@ssw0rd", - "emptyPasswordInput": false, - "savePassword": false, - "profileName": "mssql-container" - } - ], + "settings": { "omnisharp.defaultLaunchSolution": "umbraco.sln", "omnisharp.enableDecompilationSupport": true, "omnisharp.enableRoslynAnalyzers": true @@ -28,14 +15,11 @@ // Add the IDs of extensions you want installed when the container is created. "extensions": [ - "ms-dotnettools.csharp", - "ms-mssql.mssql" + "ms-dotnettools.csharp" ], // Use 'forwardPorts' to make a list of ports inside the container available locally. - // 1433 for SQL if you want to connect from local into the one running inside the container - // Can connect to the SQL Server running in the image on local with 'host.docker.internal' as hostname - "forwardPorts": [1433, 9000, 5000, 25], + "forwardPorts": [9000, 5000, 25] // [Optional] To reuse of your local HTTPS dev cert: // @@ -56,6 +40,4 @@ // 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" - // 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/'" } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index e88327b779..a071d3a1b8 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -6,15 +6,10 @@ services: context: . dockerfile: Dockerfile args: - # [Choice] Update 'VARIANT' to pick a .NET Core version: 2.1, 3.1, 5.0 - VARIANT: 5.0 + # [Choice] .NET version: 6.0, 3.1, 6.0-bullseye, 3.1-bullseye, 6.0-focal, 3.1-focal + VARIANT: 6.0-bullseye # Options - INSTALL_NODE: "true" NODE_VERSION: "lts/*" - INSTALL_AZURE_CLI: "false" - # On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000. - USER_UID: 1000 - USER_GID: 1000 volumes: - ..:/workspace:cached @@ -22,9 +17,6 @@ services: # 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 @@ -34,7 +26,8 @@ services: # DotNetCore ENV Variables # https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-5.0#environment-variables environment: - - ConnectionStrings__umbracoDbDSN=server=localhost;database=UmbracoUnicore;user id=sa;password='P@ssw0rd' + - ConnectionStrings__umbracoDbDSN=Data Source=|DataDirectory|/Umbraco.sqlite.db;Cache=Shared;Foreign Keys=True;Pooling=True + - ConnectionStrings__umbracoDbDSN_ProviderName=Microsoft.Data.Sqlite - Umbraco__CMS__Unattended__InstallUnattended=true - Umbraco__CMS__Unattended__UnattendedUserName=Admin - Umbraco__CMS__Unattended__UnattendedUserEmail=test@umbraco.com @@ -43,16 +36,6 @@ services: - Umbraco__CMS__Global__Smtp__Port=25 - Umbraco__CMS__Global__Smtp__From=noreply@umbraco.test - 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.) - smtp4dev: image: rnwood/smtp4dev:v3 restart: always diff --git a/.devcontainer/library-scripts/azcli-debian.sh b/.devcontainer/library-scripts/azcli-debian.sh deleted file mode 100644 index b03dcb0f04..0000000000 --- a/.devcontainer/library-scripts/azcli-debian.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -#------------------------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. -#------------------------------------------------------------------------------------------------------------- -# -# Docs: https://github.com/microsoft/vscode-dev-containers/blob/master/script-library/docs/azcli.md -# -# Syntax: ./azcli-debian.sh - -set -e - -if [ "$(id -u)" -ne 0 ]; then - echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' - exit 1 -fi - -export DEBIAN_FRONTEND=noninteractive - -# Install curl, apt-transport-https, lsb-release, or gpg if missing -if ! dpkg -s apt-transport-https curl ca-certificates lsb-release > /dev/null 2>&1 || ! type gpg > /dev/null 2>&1; then - if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then - apt-get update - fi - apt-get -y install --no-install-recommends apt-transport-https curl ca-certificates lsb-release gnupg2 -fi - -# Install the Azure CLI -echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list -curl -sL https://packages.microsoft.com/keys/microsoft.asc | (OUT=$(apt-key add - 2>&1) || echo $OUT) -apt-get update -apt-get install -y azure-cli -echo "Done!" \ No newline at end of file diff --git a/.devcontainer/mssql/BlankDb.sql b/.devcontainer/mssql/BlankDb.sql deleted file mode 100644 index 44546efebf..0000000000 --- a/.devcontainer/mssql/BlankDb.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* - This will generate a blank database when the container is spun up - that you can use to connect to for the SQL configuration in the web installer flow - - ---- NOTE ---- - Any .sql files in this folder will be executed - Along with any .dacpac will be restored as databases - See postCreateCommand.sh for specifics -*/ -CREATE DATABASE UmbracoUnicore; -GO \ No newline at end of file diff --git a/.devcontainer/mssql/installSQLtools.sh b/.devcontainer/mssql/installSQLtools.sh deleted file mode 100644 index 3fa6a67a09..0000000000 --- a/.devcontainer/mssql/installSQLtools.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/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 diff --git a/.devcontainer/mssql/postCreateCommand.sh b/.devcontainer/mssql/postCreateCommand.sh deleted file mode 100644 index e25583e0ff..0000000000 --- a/.devcontainer/mssql/postCreateCommand.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/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/.vscode/launch.json b/.vscode/launch.json index ab97269d1f..65a3d08583 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,9 +9,8 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "Dotnet build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/Umbraco.Web.UI/bin/Debug/net5.0/Umbraco.Web.UI.dll", - "args": [], + "program": "dotnet", + "args": ["run"], "cwd": "${workspaceFolder}/src/Umbraco.Web.UI", "stopAtEntry": false, "requireExactSource": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 99876bc77e..b8f058c18a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -54,7 +54,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/src/umbraco.sln", + "${workspaceFolder}/umbraco.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], @@ -69,6 +69,7 @@ "args": [ "watch", "run", + "--project", "${workspaceFolder}/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary"