<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Chris Vafiadis</title>
    <description>All about Chris Vafiadis</description>
    <link>http://www.chrisvafiadis.com</link>
    <atom:link href="http://www.chrisvafiadis.com/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Optimizely Foundation on a Mac</title>
        <description>&lt;h3 id=&quot;introduction&quot;&gt;Introduction&lt;/h3&gt;

&lt;p&gt;With all of the exciting stuff going on at Optimizely, perhaps the biggest thing for developers is our move to .NET 5, which provides a ton of benefits, performance being one of them.  The other thing that has developers excited is being able to code in any operating system.  I’m on a Mac and have successfully gotten Foundation up and running locally.  I’m excited to share the steps I took to hopefully accelerate the time it takes for you to start working with Optimizely on your Mac.  There have been some great blog posts written that share how to load the solution across multiple different platforms.  I thank those authors for giving me a great head start and I encourage you to explore those as well.&lt;/p&gt;

&lt;p&gt;I will start by listing some prerequisites that you will require, which will be a one-time install.  Once we get the prerequisites out of the way, I’ll walk you through the steps I added to my setup script (setup.sh).  Note that I installed Docker for Windows in order to host SQL Server.  If you will be using SQL Azure instead, you can skip that step.&lt;/p&gt;

&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;
&lt;p&gt;Before getting to the solution, some prerequisites are required on your Mac. This section will quickly walk you through those.&lt;/p&gt;

&lt;h3 id=&quot;net-5&quot;&gt;.NET 5&lt;/h3&gt;
&lt;p&gt;You will need .NET 5, which you can download directly from the &lt;a href=&quot;https://web.archive.org/web/20220703115658/https://dotnet.microsoft.com/download/dotnet/5.0&quot;&gt;Microsoft website&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;npm&quot;&gt;NPM&lt;/h3&gt;
&lt;p&gt;You will need to install Node and NPM in order to build the CSS.  I prefer using &lt;a href=&quot;https://web.archive.org/web/20220703115658/https://brew.sh/&quot;&gt;homebrew&lt;/a&gt; as my package manager on my Mac. &lt;strong&gt;Note that the version of Node seems to make a difference and I have found version 12 seems to work well&lt;/strong&gt;. Once installed, you can install Node and NPM in a Terminal window, as follows&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;brew update
brew install node@12
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Check to make sure both Node and NPM are installed:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;node -v
npm -v
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;visual-studio-for-mac&quot;&gt;Visual Studio For Mac&lt;/h3&gt;
&lt;p&gt;Take advantage of the &lt;a href=&quot;https://web.archive.org/web/20220703115658/https://visualstudio.microsoft.com/vs/mac/preview/&quot;&gt;latest release&lt;/a&gt; of Visual Studio for Mac in order to maintain that rich IDE experience.&lt;/p&gt;

&lt;h3 id=&quot;docker-desktop&quot;&gt;Docker Desktop&lt;/h3&gt;
&lt;p&gt;Although the code will be running directly on the Mac, the database will be running within a Docker container, which will require &lt;a href=&quot;https://web.archive.org/web/20220703115658/https://docs.docker.com/desktop/mac/install/&quot;&gt;Docker Desktop&lt;/a&gt; on your Mac.&lt;/p&gt;

&lt;h3 id=&quot;azure-data-studio&quot;&gt;Azure Data Studio&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20220703115658/https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15&quot;&gt;Azure Data Studio&lt;/a&gt; is optional but a nice way to interact with your database hosted in Docker.&lt;/p&gt;

&lt;h3 id=&quot;installation&quot;&gt;Installation&lt;/h3&gt;
&lt;h4 id=&quot;run-the-script&quot;&gt;Run the script&lt;/h4&gt;
&lt;p&gt;That’s all we need for prerequisites.  Let’s get to the code!  You can find my setup.sh script in the Git repo below, which will handle everything in this section.  If you’re not patient enough to read through the rest of this post, you can follow these simple steps.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Open a Terminal window&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Create a folder where you will clone the foundation-mvc-cms repo&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     mkdir ~/Documents/Code/core-cms
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Switch to the new folder&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     cd ~/Documents/Code/core-cms
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Clone the net5-mac branch of my forked repo&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     git clone -b net5-mac https://github.com/chrisvaf/foundation-mvc-cms.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Switch to the foundation-mvc-cms folder&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     cd foundation-mvc-cms
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Run setup.sh (if you are creating your own script, don’t forget to make it executable –&amp;gt; chmod 755 setup.sh).&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     ./setup.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;what-the-script-does&quot;&gt;What the script does&lt;/h4&gt;
&lt;p&gt;So, what does the script do?  Let’s walk through the different steps.  The first thing it does is prompt for an app name, which is required, and the SQL Server instance which defaults to localhost.  It then installs a couple of tools.&lt;/p&gt;

&lt;p&gt;First is the Optimizely .NET Templates which can be used to create new projects.  .Net 5 provides developers the ability to create new project templates using the dotnet new command.  There are many templates out there to help scaffold different types of .Net 5 applications.  For Optimizely, we provide empty cms and empty commerce projects.&lt;/p&gt;

&lt;p&gt;We also also install the .NET CLI tool which provides some nice goodies to do things like create admin users and databases, as well as update the connection string in appsettings.json.&lt;/p&gt;

&lt;p&gt;Finally, we ensure the Optimizely Nuget feed is added as well, so that all packages can be restored.&lt;/p&gt;

&lt;p&gt;.NET 5 includes an https dev certificate and we want to trust the cerificate by running the following command:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet dev-certs https --trust.  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that this will prompt you for your Mac password.  If you’re going to be running this script multiple times you can comment this line out after the first time.&lt;/p&gt;

&lt;p&gt;The next thing we do is build the solution using dotnet build.  Once completed, we check to see if the image for the latest version of SQL Server 2019 is available in Docker.  If not, it adds it while also creating a new container called sql_server_optimizely. If it does exist, a check is made to see if a container named sql_server_optimizely has already been added.  The same container can be used to host databases from multiple different sites – no need for more than one.&lt;/p&gt;

&lt;p&gt;Once SQL Server is in place, we run&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm ci 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm run dev.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The last step is to provision the database.  We first check for the existence of the database and if found, delete the backup history and drop the database.  We then call&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dotnet-episerver create-cms-database 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;to provision the new database for our site.&lt;/p&gt;

&lt;p&gt;If all goes well, the script ends and we can now load our site!  Note than I initially called dotnet run on the project within the script, however there doesn’t seem to be a way to load the browser, and on top of that I kept getting prompted for my login keychain password.  Instead, open up Visual Studio Preview and load the project.  &lt;strong&gt;F5&lt;/strong&gt; will kick off the browser.  Be patient on first load as the site gets provisioned.  You can monitor the database tables in Azure Data Studio to see the tables get provisioned.  If you’re as lucky as me, you should have a running Foundation site within a few minutes.&lt;/p&gt;

&lt;p&gt;Hope this helps getting things going on your Mac.  If you encounter any issues or if I left out any prerequisites feel free to reach out and let me know.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;
</description>
        <pubDate>Wed, 08 Dec 2021 00:00:00 +0000</pubDate>
        <link>http://www.chrisvafiadis.com/optimizely-foundation-on-a-mac-2/</link>
        <guid isPermaLink="true">http://www.chrisvafiadis.com/optimizely-foundation-on-a-mac-2/</guid>
      </item>
    
  </channel>
</rss>
