Welcome! This is my personal blog about Web technologies, software development, open source and other related topics
The ideas and opinions expressed here are solely mine and don't represent those of others, either individuals or companies.The code snippets or references to software products or analogous are to be used without any warranty of any kind. If you enjoy the content, feel free to share it and re-use it as long as you provide a link to the original post.
Working on Linux system after been worked on Windows for 2 decades is always fun.
This blog post is to setup the Sitecore OrderCloud Headstart on Ubuntu the Docker way. As all the images used for the Headstart is are Linux based, this I didn’t find major difference how this is been setup in Windows system apart from few changes while installing Storage Explorer and few other erros which I have noted in this blog post.
Note – use sudo for each command or “sudo i”to run as root.
Lets start composing and solve errros that might come ourr way-
sudo docker-compose up -d
npm needs TLS1.2
npm notice Beginning October 4, 2021, all connections to the npm registry – including for package installation – must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/ npm WARN @ordercloud/headstart-sdk@0.0.0 No repository field.
Once you have followed and applied the settings mentioned in the blog, should be able to see the translation files in local storage and able to access the file.
We also have to set CQRS for blob container – lets do this later.
Middleware exited with errors-
Error –
See the resolution to this issue here – section – Unable to start Middleware container due to erros
Error – Connection refused (127.0.0.1:8081)
System.AggregateException: One or more errors occurred. (Connection refused (127.0.0.1:8081))
---> System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:8081)
See the resolution to this issue here – section – Connection to Comos DB is failing
Error- Unsupported platform
0 18.52 npm ERR! code EBADPLATFORM
#0 18.53 npm ERR! notsup Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
#0 18.53 npm ERR! notsup Valid OS: darwin
#0 18.53 npm ERR! notsup Valid Arch: any
#0 18.53 npm ERR! notsup Actual OS: linux
#0 18.53 npm ERR! notsup Actual Arch: x64
Error 2- Package installation must use TLS 1.2 or higher and Cannot read properties of null (reading ‘pickAlgorithm’)
0 47.60 npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
0 114.7 npm ERR! Cannot read properties of null (reading 'pickAlgorithm')
#0 2.885 Node.js version v12.20.0 detected.
#0 2.885 The Angular CLI requires a minimum Node.js version of either v14.15, or v16.10.
> [headstart-buyer:local-linux builder 9/9] RUN cd /build/APP && npm run build --prod:
#0 0.954 npm WARN config production Use `--omit=dev` instead.
#0 0.983
#0 0.983 > headstart@0.0.0 build
#0 0.983 > ng build --configuration=deploy && node scripts/hash-css-files && node scripts/move-release-scripts && node scripts/copy-main-js && node scripts/copy-index-html
#0 0.983
#0 11.70 - Generating browser application bundles (phase: setup)...
#0 16.88 Processing legacy "View Engine" libraries:
#0 17.75 - @ngx-translate/http-loader [es2015/esm2015] (git+https://github.com/ngx-translate/http-loader.git)
#0 18.98 - ngx-forms-typed [es2015/esm2015] (https://github.com/gparlakov/forms-typed)
#0 21.65 Encourage the library authors to publish an Ivy distribution.
#0 109.2 Killed
------
failed to solve: executor failed running [/bin/sh -c cd /build/APP && npm run build --prod]: exit code: 137
Not sure why this error but I ran following command instead-
docker-compose build --no-cache
Error 4 –
cannot write C:\Users\sande\AppData\Local\Temp\tmppxl_v0jp because server did not provide an image ID
ERROR: Service 'buyer' failed to build : Build failed
Solution-
Set the latest nginx alpine base image in the Dockerfile as nginx:1.23.3-alpine. See the latest availabel bae image here – https://hub.docker.com/_/nginx
Change Dockerfile in this location headstart\docker\build\UI
Update nodejs-npm to just npm in the Dockerfile
Dockerfile should look like this-
Sometimes you may have to restart Docker Desktop
Error 5-
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:80 -> 0.0.0.0:0: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its
The said port might be in use. This is mostly when IIS is running. Stop IIS.
Once you get thhrough these errors, should have following images downloaded and containers created-
Here you can see the warnings compalining few env variable values not set. This is next we are going to setup.
For any environment changes use “docker compose down” and then “docker compose up -d”
Compile/Build the Headstart.sln
In the ServiceCollectionExtensions.cs file in OrderCloud.Integrations.EnvironmentSeed project
remove the condition for checking the BlobPrimaryEndpoint as it is not used and hence not required.
Same way if you are not using ExchangeRates, Tax Provider, payment Provider etc remove the values from .env file to avoid such errors. Following I have removed, you can add this later as and when required. Make the values for this variables empty
Recreate the middleware and container again. Delete the middleware image as the code is changes. We dont have the volume mounted hence for setup this way 🙂
docker rmi <<middleware image id>>
docker compose up -d
More errors-
Connection to Comos DB is failing-
2023-03-17 18:16:43 Application startup exception: System.AggregateException: One or more errors occurred. (Connection refused (127.0.0.1:8081))
2023-03-17 18:16:43 ---> System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:8081)
2023-03-17 18:16:43 ---> System.Net.Sockets.SocketException (111): Connection refused
Change CosmosSettings_EndpointUri in .env from “http://127.0.0.1:8081” to use localhost i.e.- change to –
Address not available (localhost:8081) – Cosmos DB address not available
2023-03-17 18:22:34 Application startup exception: System.AggregateException: One or more errors occurred. (Address not available (localhost:8081))
2023-03-17 18:22:34 ---> System.Net.Http.HttpRequestException: Address not available (localhost:8081)
2023-03-17 18:22:34 ---> System.Net.Sockets.SocketException (99): Address not available
Solution-
Change following in entrypoing.sh file located at – headstart\docker\build\middleware
i.e. instead of using $CosmosSettings_EndpointUri use $CosmosEndpointURI
this varaible contains the IP address of the comos db hosted. This can change everytime the container is created.
Change this -
-e "this['CosmosSettings:EndpointUri']='$CosmosSettings_EndpointUri'"
to
-e "this['CosmosSettings:EndpointUri']='$CosmosEndpointURI'"
Error- “Message”: “Could not find a part of the path ‘/app/wwwroot\\i18n’.”,
Tried to debug this and seems some how the path is not correctly formed to upload the translations from /app/wwwroot\\i18n folder in container. Changed this to /app/wwwroot/i18n and the files are now uploaded to storage.
Create a Blob Container – ngx-translate and create new Virtual Directory i18n
Blob Container and folder name can be any other name. You need to configure this correctly in UI config.See this in later steps
Upload the translation file(optional)
Translation file should be created by Headstart Api while seeding the marketplace further in this blog. This is a test to check if the resource is available. I have attached en.json file here.
Copy URL of the file and check if this is accessible-
Looks like cannot access.
To resolve this error set public access level on Blob container “ngx-translate”
Select Public read access for container and blobs-
Now the resource should be accessible.
Similarly upload resources for fr and jp language.
The resource file should be available in following location – headstart\src\Middleware\src\Headstart.API\wwwroot\i18n
0 2.885 The Angular CLI requires a minimum Node.js version of either v14.15, or v16.10.
It looks like in docker compose file for buyer and seller node version configured are old.
Update the following in docker-compose.yml. At the time of writing this blog the node version is 18.13.0. See here for latest- https://hub.docker.com/_/node
3. Search Category with newly created extended property i.e. DisplayType
First search all categories with Catalog Id “0001”. Following results will be shown-
Now lets try and search with extended properties i.e. Catalog Id “0001” and DisplayType as Text. For this use “Add Filter” option and key as “xp.DisplayType” and Filter Value as “Text”.
This request wont show any results and hence Xp Indices needs to created for Category
4. Create XP Indices
Navigate to Seller => Xp Indices
Indexable resources Catagory “Add Index” => “xp.DisplayType” and Save Changes
Now search the Catagories same as in Step 3 with Filter option and this time you should be able to see the results-
Step 4 – Setup the App Configuration either using appSettings or Azure App Configuration
Setup a App Configuration using appSettings.json
Use/Download the template here provided by Sitecore to setup the configuration
Create a json file on your local machine by copying the content in the template. In my case I have created OCHeadstartConfig.json. The template looks as below- Highlighted values are the minimum configuration required for Headstart project. Few of the configuration will come from the Seed step explained in Part-2 – Step 4 – Populate Ordercloud Markeplace with the seed request
Following configuration(highlighted) needs to be updated minimum to get the Headstart project working-
Get the StorageAccount.Settings.ConnectionString from Storage Explorer-
Create appSettings.json file and copy the above configuration in the file.
appSettings.json file should be in Headstart.API project-
IMP – Check if the middleware applicaiton is running and listening to localhsot 5001 port. If not you should run the Headstart.Api before running UI application.
Setup a App Configuration using Azure App Configuration
Get the configuration connection string
Goto the Access Keys – Read-only keys tab and copy the connection string
Add a new Environment Variable named – APP_CONFIG_CONNECTION and copy the connection string in the Value.
Run the middleware application with the Demo profile.
IMP – If you see compiler error’s whilst running the application. See this blog for the resolution.
Step 5 – Run the Seller UI application
Now that we have all the required configuration checked and changed, time to run the Seller UI application
RUN – from the visual studio terminal or powershell
npm install
npm run start
Now we have Seller application runing on localhost:4200 port
Provide Admin Username and Password as noted in Part -1 of the blog Step 3- Prepare Seed Request
After successful login-
Also we can see the Seller Admin-
Hope you enjoyed setting Sitecore Ordercloud Headstart 🙂
Create a new maketplace e.g.- OrderCloudHeadstart in Us-West region
IMP– At the time this blog was written looks like only Us-West region is supported when a seed request is sent. This may change in future but connect to OrderCloud team is you want this to be in region other than Us-West
Note the newly created Marketplace ID – in my case it is – OrderCloudHeadstart
If you havent provided the Marketplace ID whilst creating the OrederCloud will create once for you. You can find the same in the Marketplace.
Navigate to API Console and Get the Admin User, as you see there are no Admin users. You may also check other endpoints.
PortalUsername – enter the portal username you used to create a marketplace
PortalPassword – enter the portal password you used to create a marketplace
InitialAdminUsername – this request will create a admin user. Enter the admin username you wish to create
InitialAdminPassword – enter the admin password you want to set
MiddlewareBaseUrl – this is not required for local build
MarketplaceID – Enter the Marketplace ID you created in Step 1
Marketplace.Region– enter this to be sandbox in this case. For the other environments you might want to user different values for Staging and Production
WebhookHashKey – Set the webhook haskey to secure your webhook request.
Postman request should look like this –
STEP 4 – Setup a App Configuration using appSettings.json
Use/Download the template here provided by Sitecore to setup the configuration
Create a json file on your local machine by copying the content in the template. In my case I have created OCHeadstartConfig.json. The template looks as below- Highlighted values are the minimum configuration required for Headstart project.
Following configuration(highlighted) needs to be updated minimum to send the seed request working-
Get the StorageAccount.Settings.ConnectionString from Storage Explorer-
Create appSettings.json file and copy the above configuration in the file.
appSettings.json file should be in Headstart.API project-
IMP – Check if the middleware applicaiton is running and listening to localhsot 5001 port. If not you should run the Headstart.Api before running UI application.
Step 5 – Send the seed request to Ordercloud Markeplace
Ensure the Headstart Api is running and listening to 5001 port as mentioned in Step 2
Send the seed request
You can see the same in application that is listening to 5001 port the request was sent to-
If you have set the request correctly you should receive the success response-
IMP – Note the below response and the request that was sent specifically Admin Username and Password as this will be required later when configuring the UI application
{
"Comments": "Success! Your environment is now seeded. The following clientIDs & secrets should be used to finalize the configuration of your application. The initial admin username and password can be used to sign into your admin application",
"MarketplaceName": "ocdockertest",
"MarketplaceID": "ocdockertest",
"OrderCloudEnvironment": "Sandbox",
"ApiClients": {
"Middleware": {
"ClientID": "1141E496-8517-4953-809B-XXXXXXXXX",
"ClientSecret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"Seller": {
"ClientID": "6E98D7A1-35E9-4156-B60B-XXXXXXXXXX"
},
"Buyer": {
"ClientID": "E1EBE13C-CC74-4021-B4A9-XXXXXXXXXX"
}
},
"Success": true,
"Exception": null
}
Comments – seed response comments
MarketplaceName – gets the Marketplace name that was configured in Step 1
MarketplaceID – UniqueId that was sent as part of request and the data seeded in this Marketplace
OrderCloudEnvironment – Environment where the request was sent
ApiClients.Middleware.ClientID – Note down Middleware ClientID
ApiClients.Middleware. ClientSecret – Note down Middleware ClientSecret
ApiClients.Seller.ClientID – Note down the Seller ClientID
ApiClients.Buyer.ClientID – Note down the Buyer ClientID
Step 5- Check the Marketplace for the data been puplated
In Step 1- we saw there was not admin user created. After the seed request you can see the Admin User is created with the name mentioned in request.
Admin User
InitialAdminUser with the username provided in request is created
Also the MiddlewareIntegrationsUser is created
Buyer User
Buyer User is created-
Api Clients
Api clients created and the same was sent as response. This is used so each client have a different Id’s that helps any application to connect.
Errors-
Ensure the StorageAccountSettings:HostUrl and ConnectionString is configured correctly.
Thats it in this blog. Hope you are enjoying setting your Ordercloud Headstart project.
Since we will be now setup a backend application (i.e. admin etc) the Client IDs and Client Secret that was create in Step 5 needs to be secured. This can be condifured in Azure App Configuration. See the link on how to setup this.
Use/Download the template here provided by Sitecore to setup the configuration
Create a json file on your local machine by copying the content in the template. In my case I have created OCHeadstartConfig.json. The template looks as below-
Provide the Resource name in this case I have used OrderCloudHeadStartConfig
Select Location and Pricing tier.
Once the resource is created in the Import/Export option select –
Source service – Configuration file
For language – Other
File type- Json
Source file – *.json (auto selected)
Select the folder icon in Source file option and click Apply to import the configuration.
After the config file is imported navigate to “Configuration Explorer”. There are 63 config key values are imported but in template there are 64.
“SendgridSettings:OrderApprovalTemplateID”: “”, is not imported for due to some reason. Create a new manually if required. For the Demo this is not required.
Click on the values to see the values of the key that was imported-
Set the following values by Right clicking the keys. Copy this from Step 4 where the response was received from seed request-
OrderCloudSettings:MiddlewareClientID
OrderCloudSettings:MiddlewareClientSecret
OrderCloudSettings:MarketplaceID
OrderCloudSettings:MarketplaceName
Continue updating config in next section for Storage Account.
Step 2- Create a Azure Storage Account (if you already don’t have)
Create a Azure Storage Account
Follow the steps and set the configuration as per your requirements
Copy the storage account name and Storage connection string
Set StorageAccountSettings:BlobPrimaryEndpoint – https://yourstorageaccount.blob.core.windows.net/occontainer
Set StorageAccountSettings:ConnectionString
Thats in in this blog. In next blog will cover setting up the UI project.
Hope you are enjoying setting your Ordercloud Headstart project.