Compare commits

...
Author SHA1 Message Date
Andreas Zerbst 736a01a604 Added files for docker 2025-03-25 09:31:18 +01:00
9 changed files with 236 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
DB_PASSWORD=Password1234
ADMIN_EMAIL=admin@admin.admin
ADMIN_PASSWORD=admin@admin.admin
+21
View File
@@ -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" ]
+11
View File
@@ -0,0 +1,11 @@
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
+10
View File
@@ -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
View File
@@ -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 "$@"
+50
View File
@@ -0,0 +1,50 @@
# Base
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
# Build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY . .
RUN dotnet restore "src/Umbraco.Web.UI/Umbraco.Web.UI.csproj"
WORKDIR "src/Umbraco.Web.UI"
RUN dotnet build "Umbraco.Web.UI.csproj" --no-restore -c $BUILD_CONFIGURATION -o /app/build
# Publish
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Umbraco.Web.UI.csproj" --no-build -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# Final
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
# COPY healthcheck.sh /
COPY healthcheck.sh .
# We need to make sure that the user running the app has write access to the umbraco folder, in order to write logs and other files.
# Since these are volumes they are created as root by the docker daemon.
USER root
RUN mkdir umbraco/Logs
RUN mkdir wwwroot/media
RUN mkdir wwwroot/css
RUN mkdir wwwroot/Views
RUN mkdir wwwroot/js
# Gives the user permissions for these folder and their children
RUN chown $APP_UID umbraco --recursive
RUN chown $APP_UID wwwroot --recursive
RUN chown $APP_UID Views --recursive
# Install necessary tools
RUN apt-get update && apt-get install -y \
curl && apt-get install -y \
jq
CMD /bin/bash
USER $APP_UID
ENTRYPOINT ["dotnet", "Umbraco.Web.UI.dll"]
+102
View File
@@ -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 4to run the healthcheck again.
umbraco_image1:
image: umbraco_image
environment:
- SA_PASSWORD=${DB_PASSWORD}
- ASPNETCORE_ENVIRONMENT=Development
- ConnectionStrings__umbracoDbDSN=Server=umb_database;Database=umbracoDb;User Id=sa;Password=${DB_PASSWORD};TrustServerCertificate=true;
- ConnectionStrings__umbracoDbDSN_ProviderName=Microsoft.Data.SqlClient
- UMBRACO__CMS__UNATTENDED__UNATTENDEDUSEREMAIL=${ADMIN_EMAIL}
- UMBRACO__CMS__UNATTENDED__INSTALLUNATTENDED=true
- UMBRACO__CMS__UNATTENDED__UNATTENDEDUSERNAME=${ADMIN_EMAIL}
- UMBRACO__CMS__UNATTENDED__UNATTENDEDUSERPASSWORD=${ADMIN_PASSWORD}
- UMBRACO__CMS__SECURITY__ALLOWCONCURRENTLOGINS=True
- UMBRACO__CMS__WEBROUTING__UMBRACOAPPLICATIONNAME=http://localhost:44371/
build:
context: .
dockerfile: ./DockerFile
args:
- BUILD_CONFIGURATION=Debug
restart: always
networks:
- umbnet
depends_on:
umb_database:
condition: service_healthy
ports:
- "44371:8080"
volumes:
- media:/app/wwwroot/media
- scripts:/app/wwwroot/scripts
- css:/app/wwwroot/css
- views:/app/Views
- logs:/app/umbraco/Logs
- data:/app/umbraco
healthcheck:
# This healthcheck is to make sure that the unattended install step has finished in the first umbraco_image.
test: ./healthcheck.sh
interval: 1m
timeout: 5s
retries: 5
start_period: 30s # 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_image2:
depends_on:
umbraco_image1:
condition: service_healthy
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
- UMBRACO__CMS__SECURITY__ALLOWCONCURRENTLOGINS=True
- UMBRACO__CMS__WEBROUTING__UMBRACOAPPLICATIONNAME=http://localhost:44372/
restart: always
networks:
- umbnet
ports:
- "44372:8080"
volumes:
- media:/app/wwwroot/media
- scripts:/app/wwwroot/scripts
- css:/app/wwwroot/css
- views:/app/Views
- logs:/app/umbraco/Logs
- data:/app/umbraco
volumes:
umb_database:
media:
scripts:
css:
views:
logs:
data:
networks:
umbnet:
driver: bridge
+10
View File
@@ -0,0 +1,10 @@
value="$(curl -fs http://localhost:8080/umbraco/management/api/v1/server/status | jq -e '.serverStatus == "Run"' || exit 1)"
# This checks for any non-zero length string, and $value will be empty when the database is not installed.
if [ "$value" ]; then
echo "INSTALLED"
exit 0 # In shell scripts, exit 0 means success
else
echo "INSTALLING"
exit 1 # And exit 1 means unhealthy
fi
+6
View File
@@ -0,0 +1,6 @@
postLogoutRedirectUris='["http://localhost:8080/umbraco/oauth_complete","http://localhost:8080/umbraco/logout","http://localhost:44371/umbraco/oauth_complete","http://localhost:44371/umbraco/logout","http://localhost:44372/umbraco/oauth_complete","http://localhost:44372/umbraco/logout"]'
redirectUris='["http://localhost:8080/umbraco/oauth_complete","http://localhost:44371/umbraco/oauth_complete","http://localhost:44372/umbraco/oauth_complete"]'
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d "umbracoDb" -Q "UPDATE [dbo].[umbracoOpenIddictApplication] SET PostLogoutRedirectUris=${postLogoutRedirectUris} WHERE ClientId ='umbraco-back-office'"
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d "umbracoDb" -Q "UPDATE [dbo].[umbracoOpenIddictApplication] SET RedirectUris=${redirectUris} WHERE ClientId='umbraco-back-office'"