diff --git a/Ozym.sln b/Ozym.sln index de96eec3..bb3efe72 100644 --- a/Ozym.sln +++ b/Ozym.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.32112.339 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{48E6F909-E1C0-4187-A79B-BD2019FDF31B}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "repo-items", "repo-items", "{48E6F909-E1C0-4187-A79B-BD2019FDF31B}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitignore = .gitignore @@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ozym.Web", "Ozym.Web\Ozym.W EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ozym.Web.Test", "Ozym.Web.Test\Ozym.Web.Test.csproj", "{2AAD1729-E635-4A53-9F58-914A2A81220A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildScripts", "BuildScripts", "{4BFBE020-17A3-4116-B9E7-E0A23D93CD74}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{4BFBE020-17A3-4116-B9E7-E0A23D93CD74}" ProjectSection(SolutionItems) = preProject Add-Migration-OzymIdentity.bat = Add-Migration-OzymIdentity.bat Add-Migration-OzymWorks.bat = Add-Migration-OzymWorks.bat @@ -42,6 +42,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildScripts", "BuildScript EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{5769EFBB-8250-451A-9587-9FA738ED4167}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "installers", "installers", "{8A2F0D97-F6C1-4799-822D-6B33F5270534}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docker", "docker", "{2E76284E-D3D2-4B70-8E33-20012369A6A8}" + ProjectSection(SolutionItems) = preProject + installers\docker-compose.yml = installers\docker-compose.yml + installers\init-ozym-db.sql = installers\init-ozym-db.sql + installers\ozym-docker-installer.sh = installers\ozym-docker-installer.sh + installers\README.md = installers\README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -88,6 +98,9 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {2E76284E-D3D2-4B70-8E33-20012369A6A8} = {8A2F0D97-F6C1-4799-822D-6B33F5270534} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3C6E1D3C-5606-4AC9-88DC-2007F80638AD} EndGlobalSection diff --git a/installers/README.md b/installers/README.md new file mode 100644 index 00000000..c922db02 --- /dev/null +++ b/installers/README.md @@ -0,0 +1,40 @@ +## Ozym Docker Setup + +### Overview +Use this guide to download the latest version of the app and spin up a local instance using Docker Desktop. This process allows a user to: +* Set the passwords for the SQL accounts used by the ozym. +* Apply data migrations to provide sample data to work with. + +This process uses the latest images published under the repository's packages. + +### Prerequisites +- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed on your system. +- [winpty](https://github.com/rprichard/winpty/) installed on your system. +- Downloaded the installer zip file from [ozym-docker-installer.zip](https://github.com/hoeyi/Ozym/releases). + +### Steps + +#### 1. Unpack the installation files +Unzip the `ozym-docker-installer.zip` file to the desired directory. + +```sh +unzip ozym-docker-installer.zip -d +``` + +#### 2. Start Docker Desktop +Ensure Docker Desktop is running. If it is not, start Docker Desktop from your applications menu. + +#### 3. Run the installation script +This step will pull the required Docker images, spin up a container network, initialize the database with user passwords and roles, then add sample data to play with. You will be prompted for two passwords: +1. For the **[sa]** account. +2. For app database user. + +```sh +cd PATH_TO_EXTRACT_DIRECTORY +./install-ozym-docker-win.sh +``` + +#### 4. Access the application +Find the application by navigating to the mapped port for `ozym-web`. Open your web browser and go to `http://localhost:`, where **** corresponds to the mapped host port in the `docker-compose.yml` file or the port auto-selected by Docker Desktop. You may also wish to explore the API Swagger documentation, which can be found at `http://localhost:/swagger`, where **** corresponds to the setting in the `docker-compose.yml` file. The API root can be accessed at `http://localhost:/api/v1`. + +You can alter the **host:container** port mapping for the installation in the `docker-compose` file, if desired. \ No newline at end of file diff --git a/installers/docker-compose.yml b/installers/docker-compose.yml new file mode 100644 index 00000000..6793d189 --- /dev/null +++ b/installers/docker-compose.yml @@ -0,0 +1,45 @@ +name: ozym +services: + ozymweb: + container_name: ozym-web + image: "ghcr.io/hoeyi/ozymweb:latest" + depends_on: + - ozymdb + environment: + OZYM_APP_PASSWORD: ${OZYM_APP_PASSWORD} + ASPNETCORE_ENVIRONMENT: Development + ASPNETCORE_URLS: http://+:80 + ports: + - "80" + + ozymapi: + container_name: ozym-api + image: "ghcr.io/hoeyi/ozymapi:latest" + depends_on: + - ozymdb + environment: + OZYM_APP_PASSWORD: ${OZYM_APP_PASSWORD} + ASPNETCORE_ENVIRONMENT: Development + ASPNETCORE_URLS: http://+:80 + ports: + - "5001:80" + + ozymdb: + container_name: ozym-db + image: mcr.microsoft.com/mssql/server + environment: + ACCEPT_EULA: "Y" + MSSQL_SA_PASSWORD: ${MSSQL_SA_PASSWORD} + OZYM_APP_PASSWORD: ${OZYM_APP_PASSWORD} + # mssql server image isn't available for arm64 architecture, so we use azure-sql instead + # image: mcr.microsoft.com/azure-sql-edge:1.0.4 + # If you really want to use MS SQL Server, uncomment the following line + restart: always + healthcheck: + test: ["CMD-SHELL", "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${MSSQL_SA_PASSWORD} -Q 'SELECT 1' || exit 1"] + interval: 10s + retries: 10 + start_period: 10s + timeout: 3s + volumes: + - ./init-ozym-db.sql:/init-ozym-db.sql \ No newline at end of file diff --git a/installers/init-ozym-db.sql b/installers/init-ozym-db.sql new file mode 100644 index 00000000..0fb95375 --- /dev/null +++ b/installers/init-ozym-db.sql @@ -0,0 +1,33 @@ +-- Create the application server login. +PRINT('Initializing SQL server...') +CREATE LOGIN [OzymAppUser] + WITH PASSWORD=N'$(OZYM_APP_PASSWORD)', + CHECK_EXPIRATION=OFF, + CHECK_POLICY=ON +print('...created login for application user') +GO +-- Create the databases. +CREATE DATABASE [OzymWorks] +CREATE DATABASE [OzymIdentity] +DECLARE @msg nvarchar(72) +SELECT + @msg = STRING_AGG('[' + [name] + ']', ', ') +FROM sys.databases +WHERE [name] LIKE 'Ozym%' +PRINT(FORMATMESSAGE('...created databases: %s.', @msg)) +GO +-- Create database-level users mapped from the server login. Assign both to the +-- db_datareader and db_datawriter roles. +USE [OzymWorks] +CREATE USER [OzymAppUser] FOR LOGIN [OzymAppUser] WITH DEFAULT_SCHEMA=[dbo] +ALTER ROLE db_datareader ADD MEMBER [OzymAppUser] +ALTER ROLE db_datawriter ADD MEMBER [OzymAppUser] +PRINT(FORMATMESSAGE('...created [OzymAppUser] in [%s].', DB_NAME())) +GO +USE [OzymIdentity] +CREATE USER [OzymAppUser] FOR LOGIN [OzymAppUser] WITH DEFAULT_SCHEMA=[dbo] +ALTER ROLE db_datareader ADD MEMBER [OzymAppUser] +ALTER ROLE db_datawriter ADD MEMBER [OzymAppUser] +PRINT(FORMATMESSAGE('...created [OzymAppUser] in [%s].', DB_NAME())) +PRINT('Initialization complete.') +GO diff --git a/installers/install-ozym-docker-win.sh b/installers/install-ozym-docker-win.sh new file mode 100644 index 00000000..48709e1b --- /dev/null +++ b/installers/install-ozym-docker-win.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# Installation script for the Docker build of Ozym. +echo -e \ +'Welcome to the Ozym Docker installer!\n +This script starts a Docker network composed of Blazor, REST API, and database +containers. You will be prompted for initial passwords for both the SQL Server [sa] account, +and the web/api database login/user [OzymAppUser]. These passwords will be +set as environment variables in their respective containers.\n' + +# Prompt the user on whether to proceed with installation. +CONTINUE_INSTALL='' + +echo $CONTINUE_INSTALL + +while [ "$CONTINUE_INSTALL" = '' ] +do + read -p 'Continue with installation? (y/N): ' USER_INPUT + echo + if [ "${USER_INPUT^^}" = "Y" ] || [ "${USER_INPUT^^}" = "N" ]; then + CONTINUE_INSTALL="${USER_INPUT^^}" + fi +done + +if [ "$CONTINUE_INSTALL" = "N" ]; then + echo -e '\nInstallation cancelled.' + exit +else + echo -e "\nStarting installation...\n" + read -p 'Enter password for SQL [sa] login: ' -s MSSQL_SA_PASSWORD + echo + read -p 'Enter password for SQL [OzymAppUser] login: ' -s OZYM_APP_PASSWORD + echo + + export MSSQL_SA_PASSWORD="$MSSQL_SA_PASSWORD" + export OZYM_APP_PASSWORD="$OZYM_APP_PASSWORD" + + echo 'Starting Docker network...' + docker compose up -d + + echo 'Starting SQL Server...' + # Wait for the SQL engine to fully initialize to avoid connection error. + sleep 10 + + echo 'Setting up initial database login/user configuration...' + winpty docker exec ozym-db //opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $MSSQL_SA_PASSWORD -i init-ozym-db.sql -v OZYM_APP_PASSWORD="$OZYM_APP_PASSWORD" + + echo 'Configurating sample database and applying data migrations...' + winpty docker exec ozym-web //app/ozymworksbundle \ + --connection "Server=ozymdb;Database=OzymWorks;User Id=sa;Password=$MSSQL_SA_PASSWORD;TrustServerCertificate=true" + + echo 'Configurating sample identity database...' + winpty docker exec ozym-web //app/ozymidentitybundle \ + --connection "Server=ozymdb;Database=OzymIdentity;User Id=sa;Password=$MSSQL_SA_PASSWORD;TrustServerCertificate=true" + + echo 'Restarting ozym-web container...' + docker restart ozym-web + + # Clean up variables. + unset MSSQL_SA_PASSWORD + unset OZYM_APP_PASSWORD + + echo -e '\nInitialization complete!' +fi