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

Improve dotnet templates #16815

Merged
merged 49 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
33c3c59
Add delivery api toggle
nikolajlauridsen Jun 18, 2024
29ba76a
Add Dockerfile
nikolajlauridsen Jul 10, 2024
1c80b14
Merge branch 'refs/heads/v14/dev' into v14/feature/update-template
nikolajlauridsen Jul 11, 2024
73f49a2
add docker compose template
nikolajlauridsen Jul 11, 2024
833fad1
Ensure no duplicate database containers
nikolajlauridsen Jul 11, 2024
eb1364b
Remove wwwroot/umbraco permission check
nikolajlauridsen Jul 12, 2024
42fb84f
Provide environment variables from dokcer-compose
nikolajlauridsen Jul 16, 2024
3ba60cf
Merge branch 'refs/heads/v14/dev' into v14/feature/update-template
nikolajlauridsen Jul 16, 2024
049b640
Build as debug from compose
nikolajlauridsen Jul 16, 2024
3d57fe4
Don't store password in docker files
nikolajlauridsen Jul 16, 2024
46ebe37
Add additional template files
nikolajlauridsen Jul 16, 2024
1ffaaaf
Add docker ignore file
nikolajlauridsen Jul 16, 2024
fd59784
Enable delivery API in settings too
nikolajlauridsen Jul 17, 2024
97cf270
Enable models builder mode toggle
nikolajlauridsen Jul 17, 2024
a3a5373
Add WIP for umbraco release option
nikolajlauridsen Jul 18, 2024
511a0f7
Add starterkit option
nikolajlauridsen Jul 19, 2024
fa7bef8
Add option to chose LTS or latest
nikolajlauridsen Jul 22, 2024
c364428
Add development mode option
nikolajlauridsen Jul 22, 2024
8836482
Add descriptions
nikolajlauridsen Jul 22, 2024
4b08ffc
Add display names
nikolajlauridsen Jul 22, 2024
186811c
Add backoffice development at explicit default
nikolajlauridsen Jul 22, 2024
7b1341b
Rearrange DevelopmentMode before ModelsBuilderMode
nikolajlauridsen Jul 22, 2024
dfa8ff6
Allow specifying a port for the compose file
nikolajlauridsen Jul 22, 2024
55a5b78
Add some notes
nikolajlauridsen Jul 23, 2024
3b5653d
Move starterkits into its own template
nikolajlauridsen Jul 24, 2024
3ba6edc
Don't update version
nikolajlauridsen Jul 24, 2024
47cdc17
Remove test configuration from Dockerfile
nikolajlauridsen Jul 24, 2024
50335ff
Add default modelsbuilder option
nikolajlauridsen Jul 25, 2024
1967152
Update descriptions
nikolajlauridsen Jul 25, 2024
a5adb81
overwrite default values in IDE development
nikolajlauridsen Jul 25, 2024
2fd6372
Remove obsolete runtime minification
nikolajlauridsen Jul 25, 2024
4329314
Try and fix healthcheck
nikolajlauridsen Jul 25, 2024
b081e77
Don't use post action for starterkit
nikolajlauridsen Jul 25, 2024
f709118
Move UmbracoVersion above FinalVersion
nikolajlauridsen Jul 25, 2024
dbc91f2
Fix healthcheck
nikolajlauridsen Jul 25, 2024
8c36813
Use else instead of second if for modelsbuilder
nikolajlauridsen Jul 26, 2024
791d25f
Obsolete UmbracoVersion
nikolajlauridsen Jul 26, 2024
df7ffe9
Remove custom release option
nikolajlauridsen Jul 26, 2024
a6a82a6
Use forward slashes for volumes
nikolajlauridsen Jul 26, 2024
819588c
Add MSSQL_SA_PASSWORD env variable
nikolajlauridsen Jul 26, 2024
f7a865e
Merge remote-tracking branch 'origin/release/14.2' into v14/feature/u…
nikolajlauridsen Aug 20, 2024
0e97c54
Temporarily limit acceptance tests so it works
nikolajlauridsen Aug 20, 2024
eba5362
Try again
nikolajlauridsen Aug 20, 2024
784b13f
Disable SQLServer integration tests
nikolajlauridsen Aug 21, 2024
61082c0
Set UseHttps to false in appsettings.Development.json
nikolajlauridsen Aug 21, 2024
0366a45
Fix LTS version
nikolajlauridsen Aug 21, 2024
82707c0
Update permissions of wwwroot/umbraco for v13 sites
nikolajlauridsen Aug 23, 2024
6a94e69
Fix conditional in Program.cs
nikolajlauridsen Aug 23, 2024
60e1dce
Undo pipeline shenanigans
nikolajlauridsen Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Umbraco.Infrastructure/Install/FilePermissionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public FilePermissionHelper(IOptions<GlobalSettings> globalSettings, IIOHelper i
{
hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Bin),
hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Umbraco),
hostingEnvironment.MapPathWebRoot(_globalSettings.UmbracoPath),
hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.Packages),
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/Umbraco.Web.UI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
#if UseDeliveryApi
.AddDeliveryApi()
#endif
.AddComposers()
.Build();

Expand All @@ -23,6 +25,9 @@
})
.WithEndpoints(u =>
{
/*#if (UmbracoRelease = 'LTS')
u.UseInstallerEndpoints();
#endif */
u.UseBackOfficeEndpoints();
u.UseWebsiteEndpoints();
});
Expand Down
3 changes: 2 additions & 1 deletion templates/Umbraco.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Content Include="UmbracoPackage\**" Exclude="bin;obj" />
<Content Include="UmbracoPackageRcl\**" Exclude="bin;obj" />
<Content Include="UmbracoProject\**" Exclude="bin;obj" />
<Content Include="UmbracoDockerCompose\**" Exclude="bin;obj"/>
<Content Include="..\src\Umbraco.Web.UI\Views\Partials\blocklist\**">
<Link>UmbracoProject\Views\Partials\blocklist\%(RecursiveDir)%(Filename)%(Extension)</Link>
<PackagePath>UmbracoProject\Views\Partials\blocklist</PackagePath>
Expand Down Expand Up @@ -47,7 +48,7 @@
</_TemplateJsonFiles>
</ItemGroup>
<Copy SourceFiles="@(_TemplateJsonFiles)" DestinationFiles="%(DestinationFile)" />
<JsonPathUpdateValue JsonFile="%(_TemplateJsonFiles.DestinationFile)" Path="$.symbols.UmbracoVersion.defaultValue" Value="&quot;$(PackageVersion)&quot;" />
<JsonPathUpdateValue JsonFile="%(_TemplateJsonFiles.DestinationFile)" Path="$.symbols.FinalVersion.parameters.cases.[0].value" Value="&quot;$(PackageVersion)&quot;" />
<ItemGroup>
<_PackageFiles Include="%(_TemplateJsonFiles.DestinationFile)">
<PackagePath>%(_TemplateJsonFiles.RelativeDir)</PackagePath>
Expand Down
1 change: 1 addition & 0 deletions templates/UmbracoDockerCompose/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DB_PASSWORD=Password1234
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/dotnetcli.host.json",
"symbolInfo": {
"ProjectName": {
"longName": "ProjectName",
"shortName": "P"
},
"DatabasePassword": {
"longName": "DatabasePassword",
"shortName": "dbpw"
},
"Port":
{
"longName": "Port",
"shortName": "p"
}
},
"usageExamples": [
"dotnet new umbraco-compose -P MyProject",
"dotnet new umbraco-compose --ProjectName MyProject",
"dotnet new umbraco-compose -P -MyProject -dbpw MyStr0ngP@ssword",
"dotnet new umbraco-compose -P -MyProject --DatabasePassword MyStr0ngP@ssword"
]
}
23 changes: 23 additions & 0 deletions templates/UmbracoDockerCompose/.template.config/ide.host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/ide.host.json",
"order": 0,
"icon": "../../icon.png",
"description": {
"id": "UmbracoDockerCompose",
"text": "Umbraco Docker Compose - Docker compose for Umbraco CMS and associated database"
},
"symbolInfo": [
{
"id": "ProjectName",
"isVisible": true
},
{
"id": "DatabasePassword",
"isVisible": true
},
{
"id": "Port",
"isVisible": true
}
]
}
49 changes: 49 additions & 0 deletions templates/UmbracoDockerCompose/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "https://json.schemastore.org/template.json",
"author": "Umbraco HQ",
"classifications": [
"Web",
"CMS",
"Umbraco"
],
"name": "Umbraco Docker Compose",
"description": "Creates the prerequisites for developing Umbraco in Docker containers",
"groupIdentity": "Umbraco.Templates.UmbracoDockerCompose",
"identity": "Umbraco.Templates.UmbracoDockerCompose",
"shortName": "umbraco-compose",
"tags": {
"type": "item"
},
"symbols": {
"ProjectName": {
"type": "parameter",
"description": "The name of the project the Docker Compose file will be created for",
"datatype": "string",
"replaces": "UmbracoProject",
"isRequired": true
},
"DatabasePassword": {
"type": "parameter",
"description": "The password to the database, will be stored in .env file",
"datatype": "string",
"replaces": "Password1234",
"defaultValue": "Password1234"
},
"Port": {
"type": "parameter",
"description": "The port forward on the docker container, this is the port you use to access the site",
"datatype": "string",
"replaces": "TEMPLATE_PORT",
"defaultValue": "44372"
},
"ImageName": {
"type": "generated",
"generator": "casing",
"parameters": {
"source": "ProjectName",
"toLower": true
},
"replaces": "umbraco_image"
}
}
}
21 changes: 21 additions & 0 deletions templates/UmbracoDockerCompose/Database/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/azure-sql-edge:latest

ENV ACCEPT_EULA=Y

USER root

RUN mkdir /var/opt/sqlserver

RUN chown mssql /var/opt/sqlserver

ENV MSSQL_BACKUP_DIR="/var/opt/mssql"
ENV MSSQL_DATA_DIR="/var/opt/mssql/data"
ENV MSSQL_LOG_DIR="/var/opt/mssql/log"

EXPOSE 1433/tcp
COPY setup.sql /
COPY startup.sh /
COPY healthcheck.sh /

ENTRYPOINT [ "/bin/bash", "startup.sh" ]
CMD [ "/opt/mssql/bin/sqlservr" ]
15 changes: 15 additions & 0 deletions templates/UmbracoDockerCompose/Database/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
value="$(/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d master -Q "SELECT state_desc FROM sys.databases WHERE name = 'umbracoDb'" | awk 'NR==3')"

# This checks for any non-zero length string, and $value will be empty when the database does not exist.
if [ -n "$value" ]
then
echo "ONLINE"
return 0 # With docker 0 = success
else
echo "OFFLINE"
return 1 # And 1 = unhealthy
fi

# This is useful for debugging
# echo "Value is:"
# echo "$value"
10 changes: 10 additions & 0 deletions templates/UmbracoDockerCompose/Database/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
USE [master]
GO

IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'UmbracoDb')
BEGIN
CREATE DATABASE [umbracoDb]
END;
GO

USE UmbracoDb;
23 changes: 23 additions & 0 deletions templates/UmbracoDockerCompose/Database/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

# Taken from: https://github.com/CarlSargunar/Umbraco-Docker-Workshop
if [ "$1" = '/opt/mssql/bin/sqlservr' ]; then
# If this is the container's first run, initialize the application database
if [ ! -f /tmp/app-initialized ]; then
# Initialize the application database asynchronously in a background process. This allows a) the SQL Server process to be the main process in the container, which allows graceful shutdown and other goodies, and b) us to only start the SQL Server process once, as opposed to starting, stopping, then starting it again.
function initialize_app_database() {
# Wait a bit for SQL Server to start. SQL Server's process doesn't provide a clever way to check if it's up or not, and it needs to be up before we can import the application database
sleep 15s

#run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d master -i setup.sql

# Note that the container has been initialized so future starts won't wipe changes to the data
touch /tmp/app-initialized
}
initialize_app_database &
fi
fi

exec "$@"
102 changes: 102 additions & 0 deletions templates/UmbracoDockerCompose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
services:
umb_database:
container_name: umbraco_image_database
build:
context: ./Database
environment:
SA_PASSWORD: ${DB_PASSWORD}
MSSQL_SA_PASSWORD: ${DB_PASSWORD}
ports:
- "1433:1433"
- "1434:1434"
volumes:
- umb_database:/var/opt/mssql
networks:
- umbnet
healthcheck:
# This healthcheck is to make sure that the database is up and running before the umbraco container starts.
# It works by querying the database for the state of the umbracoDb database, ensuring it exists.
test: ./healthcheck.sh
interval: 5m
timeout: 5s
retries: 3
start_period: 15s # Bootstrap duration, for this duration failures does not count towards max retries.
start_interval: 5s # How long after the health check has started to run the healthcheck again.

umbraco_image:
image: umbraco_image
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ConnectionStrings__umbracoDbDSN=Server=umb_database;Database=umbracoDb;User Id=sa;Password=${DB_PASSWORD};TrustServerCertificate=true;
- ConnectionStrings__umbracoDbDSN_ProviderName=Microsoft.Data.SqlClient
volumes:
- umb_media:/app/wwwroot/media
- umb_scripts:/app/wwwroot/scripts
- umb_styles:/app/wwwroot/css
- umb_logs:/app/umbraco/Logs
- umb_views:/app/Views
- umb_data:/app/umbraco
- umb_models:/app/umbraco/models
build:
context: .
dockerfile: UmbracoProject/Dockerfile
args:
- BUILD_CONFIGURATION=Debug

depends_on:
umb_database:
condition: service_healthy
restart: always
ports:
- "TEMPLATE_PORT:8080"
networks:
- umbnet
develop:
# This allows you to run docker compose watch, after doing so the container will rebuild when the models are changed.
# Once a restart only feature is implemented (https://github.com/docker/compose/issues/11446)
# It would be really nice to add a restart only watch to \Views, since the file watchers for recompilation of Razor views does not work with docker.
watch:
- path: ./UmbracoProject/umbraco/models
action: rebuild

# These volumes are all made as bind mounts, meaning that they are bound to the host machine's file system.
# This is to better facilitate local development in the IDE, so the views, models, etc... are available in the IDE.
# This can be changed by removing the driver and driver_opts from the volumes.
volumes:
umb_media:
driver: local
driver_opts:
type: none
device: ./UmbracoProject/wwwroot/media
o: bind
umb_scripts:
driver: local
driver_opts:
type: none
device: ./UmbracoProject/wwwroot/scripts
o: bind
umb_styles:
driver: local
driver_opts:
type: none
device: ./UmbracoProject/wwwroot/css
o: bind
umb_logs:
umb_views:
driver: local
driver_opts:
type: none
device: ./UmbracoProject/Views
o: bind
umb_data:
umb_models:
driver: local
driver_opts:
type: none
device: ./UmbracoProject/umbraco/models
o: bind
umb_database:

networks:
umbnet:
driver: bridge
25 changes: 25 additions & 0 deletions templates/UmbracoProject/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
27 changes: 26 additions & 1 deletion templates/UmbracoProject/.template.config/dotnetcli.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@
},
"UmbracoVersion": {
"longName": "version",
"shortName": "v"
"shortName": "v",
"isHidden": true
},
"UmbracoRelease": {
"longName": "release",
"shortName": "r"
},
"UseHttpsRedirect": {
"longName": "use-https-redirect",
"shortName": ""
},
"UseDeliveryApi": {
"longName": "use-delivery-api",
"shortName": "da"
},
"Docker": {
"longName": "add-docker",
"shortName": ""
},
"SkipRestore": {
"longName": "no-restore",
"shortName": ""
Expand Down Expand Up @@ -58,6 +71,18 @@
"longName": "PackageTestSiteName",
"shortName": "p",
"isHidden": true
},
"ModelsBuilderMode": {
"longName": "models-mode",
"shortName": "mm"
},
"StarterKit": {
"longName": "starter-kit",
"shortName": "sk"
},
"DevelopmentMode": {
"longName": "development-mode",
"shortName": "dm"
}
},
"usageExamples": [
Expand Down
Loading
Loading