Running Sitecore Publishing Service in Docker

08/02/2017 Leave a comment

In this mini series of running Sitecore in docker containers, it is now time to have a look at a container for running Sitecore publishing Service.  This container will setting up the service following the manual process found in the installation guide at dev.sitecore.net. The recommendation specifies that service should be hosted on an IIS so as an base image I will be using the Microsoft/IIS from docker hub.  Over the base image there will be installed dotnetcore hosting using https://chocolatey.org/. Be aware that this docker image will be using windows containers, and you can’t combine linux and windows continer in docker yet. SO !

STOP REMEMBER TO SWITCH TO WINDOWS CONTAINERS

It is important to note that this container is not being packed with the Publishing Service zip file, but instead a voluome should be created with the publishing service files found in the zip. To be clear this means that you will still have to download and extract the publishing service from dev.sitecore.net

To help configurering the container a couple of support files is created. First a small powershell script for manipaluting the connectionstrings into the templates file ”sc.global.xml”  which is then copied into to the configuration.

And yes I know the powershell could be written more crisp sorry..

dont.gif

$user = $env:user
$password = $env:password
$server = $env:server
$coredb = $env:coredb
$masterdb = $env:masterdb
$webdb = $env:webdb
$core = '<core>user id='+$user+';password='+$password +';Data Source='+$server+';Database='+$coredb+';MultipleActiveResultSets=True;</core>'
$master = '<master>user id='+$user+';password='+$password +';Data Source='+$server+';Database='+$masterdb+';MultipleActiveResultSets=True;</master>'
$web = '<web>user id='+$user+';password='+$password +';Data Source='+$server+';Database='+$webdb+';MultipleActiveResultSets=True;</web>'</pre>
(Get-Content C:\resources\sc.global.xml) -replace('{CORE}',$core) | Set-Content C:\resources\sc.global.xml
(Get-Content C:\resources\sc.global.xml) -replace('{MASTER}',$master) | Set-Content C:\resources\sc.global.xml
(Get-Content C:\resources\sc.global.xml) -replace('{WEB}',$web) | Set-Content C:\resources\sc.global.xml

Copy-Item C:\resources\sc.global.xml c:\publishing\config\global\

(Get-IISAppPool "DefaultAppPool" ).ManagedRuntimeVersion = ""

c:\publishing\./Sitecore.Framework.Publishing.Host schema upgrade --force

C:\ServiceMonitor.exe w3svc

And the template xml file

<Settings>
<Sitecore>
<Publishing>
<!--
Overriding & controlling the log level for different parts of the system
-->
<Logging>
<Filters>
<Sitecore>Information</Sitecore>
<Sitecore.Framework.Publishing.DataPromotion>Debug</Sitecore.Framework.Publishing.DataPromotion>
<Sitecore.Framework.Publishing.ManifestCalculation>Trace</Sitecore.Framework.Publishing.ManifestCalculation>
</Filters>
</Logging>
<ConnectionStrings>
{CORE}
{MASTER}
{WEB}
</ConnectionStrings>
</Publishing>
</Sitecore>
</Settings>

 

With the two helper files, all that is left is the Dockerfile


FROM microsoft/aspnet

RUN mkdir C:\publishing
ADD /resources /resources
RUN powershell -NoProfile -Command \
Import-module IISAdministration; \
New-IISSite -Name "publishing" -PhysicalPath C:\publishing -BindingInformation "*:80:"; \
Remove-IISSite -Name 'Default Web Site' -Confirm:$false;

RUN powershell -Command (Get-IISAppPool "DefaultAppPool" ).ManagedRuntimeVersion = ''

RUN powershell -Command Invoke-Expression ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN powershell -Command Install-PackageProvider -Name chocolatey -Force
RUN powershell -Command choco install -y --params="Quiet" dotnetcore-windowshosting
EXPOSE 80

ENTRYPOINT powershell.exe -Command c:\Resources\configure.ps1

 

Once build you should be able to run it.
docker build . -t sitecorepublisging

Remember to mount a volumen pointing to the folder where you extracted the publishingservice.zip file. The volumen needs to point to “c:\\publishing” inside the container. And also supply relevant information for environment variables ie. your sql user name,password and adresse and  Sitecore names for the master web and core so it could looking something like this J

docker run -it -p 80:80 -v d:\\websites\\publishing:c:\\publishing -e “user=sa” -e “password=Sitecore+Docker=Socker!” -e “server=172.29.31.21” -e “coredb=Sitecore_Core” -e “webdb=Sitecore_Web” -e “masterdb=Sitecore_Master” –name demop sitecorpublishingservise

DID YOU REMEMBER TO SWITCH TO WINDOWS CONTAINERS  ?

You can’t use localhost because of some windows natting with docker issues sorrym this is comming in the near future.

Once the container is up and running inspect the container to get the ip.

Docker inspect {containername}

With the ip verify the service is running

http://{CONTAINERIP}/api/publishing/operations/status

you should see a status 0

Once you installed the sitecore package enabling publishing service inside Sitecore. you can copy the the container ip into your configuration found in /App_Config/Include/Sitecore.Publishing.Service.config and update the setting

<setting name="PublishingServiceUrlRoot">http://CONTAINERIP/</setting>

And that’s all. Now you are using the new publishing service with IIS hosted in docker.

lego awesome.gif

Congrats. So test it by publish your entire site i Sitecore 🙂 and be amazed be the publishing service speed.

Once i get around to it i will publish the image to docker hub.  In this blog post i only gave one way to run the publishing service there are of course others. And also the image can be optimised.

Sitecore Docker Solr on windows container

02/11/2016 Leave a comment

Lately I’ve been working on getting Sitecore up and running in docker containers. Which now is possible with windows containers, you can read pbering blog post about here http://invokecommand.net/posts/sitecore-and-docker-today. In my last blog post I showed how to use Solr with Docker and Sitecore, unfortunately you can’t run windows container a long side with Linux containers yet. So in the following I’ve created a windows solr container you can use. Remember this will only work if you  install docker beta.

Simply run

docker run –d –p 8983:8983 istern/windows-solr54 –name mysolr

Since there are some minor bugs on windows container you can’t reference in on localhost so you will have to inspect the container to get the ip.

docker inspect mysolr

paste the ip into your solr host in Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config  in your environment. And you’re now done.

Categories: Docker, Sitecore 8, Solr Tags: , ,

Solr docker container for Sitecore 8.2

04/10/2016 Leave a comment

For some time, I’ve wanted to work with Docker. So I took on the task of creating a Solr container for Sitecore, a container you can turn on and have all the required Solr Cores configured and preinstalled, so it just works with Sitecore. This post is not a detailed introduction to Docker if you want a detailed introduction I suggest looking at their website https://www.docker.com. This post is only meant to be a simple demo to shown how you could combine Docker with Sitecore. Dont use this container for more than testing, it is not suposed to be used in production.

First I found a  suitable  Docker container image to start from , my choice : the Solr:5.3 found here : https://github.com/docker-solr/docker-solr/blob/dfe2c80ca10ca9191ae8ce7c6193ecd47c6c0b5f/5.3/Dockerfile.

I’ve installed the images “spun up a docker container” pulled  the schema file and ran it through Sitecore 8.2 “enrichment” process. Next I started to build my docker file containing all the configuration for building the container ie configuring the different cores . All that happens is  first to copy in the new schema file  to the basic_configset and afterwards copy the basic_configset to multiple new folders one for each core. See the docker file below

FROM solr:5.3

MAINTAINER istern

ENV SOLR_PATH /opt/solr/server/solr

COPY resources/schema.xml $SOLR_PATH/configsets/basic_configs/conf

RUN cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_core_index && \
echo name=sitecore_core_index > $SOLR_PATH/sitecore_core_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_master_index && \
echo name=sitecore_master_index > $SOLR_PATH/sitecore_master_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_web_index && \
echo name=sitecore_web_index > $SOLR_PATH/sitecore_web_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_fxm_master_index && \
echo name=sitecore_fxm_master_index > $SOLR_PATH/sitecore_fxm_master_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_fxm_web_index && \
echo name=sitecore_fxm_web_index > $SOLR_PATH/sitecore_fxm_web_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_list_index && \
echo name=sitecore_list_index > $SOLR_PATH/sitecore_list_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_marketing_asset_index_master && \
echo name=sitecore_marketing_asset_index_master > $SOLR_PATH/sitecore_marketing_asset_index_master/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_marketing_asset_index_web && \
echo name=sitecore_marketing_asset_index_web > $SOLR_PATH/sitecore_marketing_asset_index_web/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_marketingdefinitions_master && \
echo name=sitecore_marketingdefinitions_master> $SOLR_PATH//sitecore_marketingdefinitions_master/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_marketingdefinitions_web && \
echo name=sitecore_marketingdefinitions_web > $SOLR_PATH/sitecore_marketingdefinitions_web/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_suggested_test_index && \
echo name=sitecore_suggested_test_index > $SOLR_PATH/sitecore_suggested_test_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_testing_index && \
echo name=sitecore_testing_index > $SOLR_PATH/sitecore_testing_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/social_messages_master && \
echo name=social_messages_master > $SOLR_PATH/social_messages_master/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/social_messages_web && \
echo name=social_messages_web > $SOLR_PATH/social_messages_web/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_analytics_index && \
echo name=sitecore_analytics_index > $SOLR_PATH/sitecore_analytics_index/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_core_indexMainAlias && \
echo name=sitecore_core_indexMainAlias > $SOLR_PATH/sitecore_core_indexMainAlias/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_master_indexMainAlias && \
echo name=sitecore_master_indexMainAlias > $SOLR_PATH/sitecore_master_indexMainAlias/core.properties && \
cp -r $SOLR_PATH/configsets/basic_configs/ $SOLR_PATH/sitecore_web_indexMainAlias && \
echo name=sitecore_web_indexMainAlias > $SOLR_PATH/sitecore_web_indexMainAlias/core.properties

You can see the project here at github https://github.com/istern/Sitecore-Containers/tree/master/containers/solr/sitecore8.2  the container image is at dockerhub  at https://hub.docker.com/r/istern/solr-sitecore/

You can test it out  by installing docker and then running the following command.

docker run –name nameofyoucontainer -d -p 8983:8983 istern/solr-sitecore:8.2

You can now reach you solr admin interface on your http://localhost:8983

If you want to add an extra core I’ve made a script you can run from your favorite prompt.

 docker exec [NAMEOFYOURSOLRCONTAINER] ./createcore.sh NameOfNewCore

You could combine the above image with docker compose to have both a solr and mongo running in containers. Below is an example  of a docker-compose.yml

version: ‘2.0’
services:
solr:
image: istern/solr-sitecore:8.2
ports:
– “8983:8983”
mongo:
image: mongo
ports:
– “27020:27017”

you can test it by runnning the following command . The “-d” means as a daemon in he background.

docker-compose up -d

and now you have both a solr and mongo server running as  containers .

A big thanks to @pbering for getting me started and helping m with all my silly docker questions.

Categories: Docker, Sitecore 8 Tags: ,

Unit testing in Sitecore 8.2

19/09/2016 Leave a comment

Sitecore has done a great job but abstracting a lot and marking a lot of methods as Virtual, take the Datbase class for instance it is now abstract class, and implement in the DefaultDatabase Also all methods in the Item class is now marked virtual. I must say I think It is great way Sitcore is heading, and they are doing great but allowing developers easly testing the code by taking the framework in this direction.

Ok,  but before I could also test using Microsoft Fakes, yes and there is Sitecore FakeDB, and also there was the old Framework I created myself Sitecore.Fakes, which didn’t work with sitecore 7+ because the Database contructer was made internal,  but now working again in 8.2, the latter two Framworks (Sitecore FAkeDB and Sitecore.Fakes) required additional setup in a App.config along with a license file in your Test project  With the changes mention before this is no longer required ..  I’ve updated the Sitecore.Fakes found here https://github.com/istern/Sitecore-Fakes the solution contains examples of how to test with this Framework, a simple example is given below.


[Fact]

public void NewFakeItemDefaultNameShouldBeFakeItem()

{

var fake = new FakeItem();

fake.Name.Should().Be("FakeItem");

}

Note I’ve trimmed the framework a lot, ie. removed functionality that will be rewritten., so it is no longer as feature rich as before but now working J, also it is by fare not as feature rich as Sitecore FakeDB.

Running Sitecore Field Editor from a Speak Command in Sitecore Experience editor Sitecore 8.1 Version

14/12/2015 Leave a comment

So with the release of sitecore 8.1 also came some minor changes to how the javascript are structured, this means that to run the Sitecore Field Editor from a Speak Command in Sitecore Experience editor, which i presented in this post, a minor changes is required. All that is needed to be changed is the way the reference to Experience editor is handled the full Javascript with the modification is show below.

define(["sitecore", "/-/speak/v1/ExperienceEditor/ExperienceEditor.js"], function (Sitecore, ExperienceEditor) {
    Sitecore.Commands.LaunchFieldEditor =
    {
        canExecute: function (context) {
            //YOU COULD ADD FUNCTIONALITY HERE TO SEE IF ITEMS HAVE THE CORRECT FIELDS
            return true;
        },
        execute: function (context) {
            // THIS IS FOR THE ALT TEXT ON IMAGE
            context.currentContext.argument = context.button.viewModel.$el[0].firstChild.alt;

            //THIS IS THE TOOLTIP ON LINK TAG "A"
            context.currentContext.argument = context.button.viewModel.$el[0].title;
            console.log(Sitecore);
            console.log(ExperienceEditor);
            ExperienceEditor.PipelinesUtil.generateRequestProcessor("ExperienceEditor.GenerateFieldEditorUrl", function (response) {
                var DialogUrl = response.responseValue.value;
                var dialogFeatures = "dialogHeight: 680px;dialogWidth: 520px;";
                ExperienceEditor.Dialogs.showModalDialog(DialogUrl, '', dialogFeatures, null);
            }).execute(context);

        }
    };
});

Only modification is the mapping of The Experience editor is now loaded with a direct link to ExperienceEditor.js Line 1.

Categories: C#, Javascript, Sitecore 8 Tags: , ,

Sitecore 8.1 Preview doesn’t match current site

01/12/2015 Leave a comment

With the release of sitecore 8.1 came a minor little config change, the resolve site configuration is now default false, previous version this was default set to true.

 

The settings is in 8.1 is set to default false

 <setting name="Preview.ResolveSite" value="false" />

 

when set to false the preview site, will always be set to what is configured in the following setting

 


<setting name="Preview.DefaultSite" value="website" />

 

Change the setting to true and Sitecore will try to resolve the sites matching a site from <sites> section.

Categories: Sitecore 8

Sitecore social connected Invalid Scopes: user_interests

12/11/2015 Leave a comment

I’ve set my self the task to have a go at the social connected, which I never really had a look at before.

So I’ve set it up a clean sitecore 8.1 and included the Facebook login in a MVC rendering and everything is working fine, except when trying to login on facebook, then I was shown an error See image below
2015-11-12_09-11-39

The fix is pretty simple, fields that are pulled out of Facebook is configured in /app_config/include/Social/Sitecore.Social.ProfileMapping.Facebook.config and for the error i got it was the interest field that did’t exist in my user profile or had been renamed, but commenting out the field made, se below,e the error go away. the downside is that facebook interest isn’t mappen to contact details.

 

<!-- The interests listed on the user's profile. -->
<field enabled="true" originalKey="" sitecoreKey="fb_interests" permission="user_interests" access="/me/interests" text="Interests" /> 

I have to say my first impression of the module is it an great module easy to use and easy top configure, and can add a lot of value to any Sitecore solution

Categories: Sitecore 8, Social Tags: