Jekyll2017-05-26T20:22:13+00:00http://geeks.akinox.com/Akinox Developer BlogDevelopers' Blog for Akinox Solutions Inc.HTML Emails :(2017-03-29T10:00:00+00:002017-03-29T10:00:00+00:00http://geeks.akinox.com/2017/03/29/html-emails<p>Apparently, wanting technology that was drafted in 1997 and finalised in 2011 to work
properly in 2017 is asking too much. Pretty emails that work consistently across different
clients are <em>very</em> hard to build. If your application sends transactional emails, this
post is probably relevant to you!</p>
<p>Plain text will (unfortunately) get you only so far. Users expect a little more from email
than simple text. But once you start getting involved in <em>overly</em> complicated things like
background colours or even making text centered, you’re opening Pandora’s box. There is a
plethora of
<a href="https://www.campaignmonitor.com/css/">different clients that all handle things differently</a>.
Some will respect CSS in the <code class="highlighter-rouge"><head></code>, others won’t. Some will simply ignore all CSS. The only reliable way is to use basic HTML elements and attributes like it’s 1997 all over again.
Also, table for layout is back in action for this wonderful task.</p>
<p>Obviously, writing markup manually for tables and repetitive styles like font-style, weight,
size, family and so on would be way too tedious for anyone. If only someone had done
all this work already…</p>
<p><a href="http://foundation.zurb.com/emails.html">Someone did!</a> We’re saved!</p>
<p><img src="/img/posts/zurb-foundation-emails.png" alt="Zurb Foundation for Email" /></p>
<p>Zurb’s Foundation for Email requires <a href="https://nodejs.org/">NodeJS</a>, which you probably
already have installed if you do frontend development work. There’s a
<a href="https://foundation.zurb.com/emails/docs/sass-guide.html">handy guide</a> available for
starting a new project. The framework uses
<a href="https://foundation.zurb.com/emails/docs/inky.html">Inky</a> to write HTML like code
that will then be transformed into actual HTML. Then, for a production build, it will
also inline your CSS and minify your HTML. That means you can develop using regular
CSS (event SASS in the default project’s configuration) with IDs and classes and whatnot
so you don’t repeat everything at development time. Then for production, you get a
cross-client compatible output.</p>
<p>Basically, you turn this</p>
<div class="language-xml highlighter-rouge"><pre class="highlight"><code><span class="nt"><wrapper</span> <span class="na">class=</span><span class="s">"header"</span><span class="nt">></span>
<span class="nt"><container></span>
<span class="nt"><row</span> <span class="na">class=</span><span class="s">"collapse"</span><span class="nt">></span>
<span class="nt"><columns</span> <span class="na">small=</span><span class="s">"6"</span><span class="nt">></span>
<span class="nt"><img</span> <span class="na">src=</span><span class="s">"http://placehold.it/200x50/663399"</span><span class="nt">></span>
<span class="nt"></columns></span>
<span class="nt"><columns</span> <span class="na">small=</span><span class="s">"6"</span><span class="nt">></span>
<span class="nt"><p</span> <span class="na">class=</span><span class="s">"text-right"</span><span class="nt">></span>BASIC<span class="nt"></p></span>
<span class="nt"></columns></span>
<span class="nt"></row></span>
<span class="nt"></container></span>
<span class="nt"></wrapper></span>
<span class="nt"><container></span>
<span class="nt"><spacer</span> <span class="na">size=</span><span class="s">"16"</span><span class="nt">></spacer></span>
<span class="nt"><row></span>
<span class="nt"><columns</span> <span class="na">small=</span><span class="s">"12"</span><span class="nt">></span>
<span class="nt"><h1></span>Hi, Susan Calvin<span class="nt"></h1></span>
<span class="nt"><p</span> <span class="na">class=</span><span class="s">"lead"</span><span class="nt">></span>Lorem ipsum dolor sit amet<span class="nt"></p></span>
<span class="nt"><p></span>Lorem ipsum dolor sit amet, consectetur adipisicing elit.<span class="nt"></p></span>
<span class="nt"><callout</span> <span class="na">class=</span><span class="s">"primary"</span><span class="nt">></span>
<span class="nt"><p></span>Lorem ipsum dolor sit amet.<span class="nt"></p></span>
<span class="nt"></callout></span>
<span class="nt"></columns></span>
<span class="nt"></row></span>
<span class="nt"></container></span>
</code></pre>
</div>
<p>into this</p>
<p><img src="/img/posts/zurb-basic-output.png" alt="Zurb basic output" /></p>
<p>All this is styled using SASS and can be previewed and built in the browser with normal
development tools like Chrome’s. The project template already supports
<a href="https://www.npmjs.com/package/browser-sync">BrowserSync</a> which makes it even easier
to write and see as you code.</p>
<p>The basic CSS template can be modified at will or used as is. You can then customise
all your emails as you wish. Simply add a new <code class="highlighter-rouge">html</code> file and write away. I added
a step in the <code class="highlighter-rouge">gulpfile</code> to copy my templates’ output from the Zurb project to my
actual backend code. As I write the templates, they are automatically updated in my
backend and I can test them out with my unit tests or by using the UI to actually
send them!</p>
<p>Here’s the gulp function.</p>
<div class="language-javascript highlighter-rouge"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">copyToParents</span><span class="p">(</span><span class="nx">done</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">rimraf</span><span class="p">(</span><span class="s2">"../DotNetCoreBackend/Emails/*.cshtml"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=></span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">gulp</span>
<span class="p">.</span><span class="nx">src</span><span class="p">(</span><span class="s2">"dist/emails/*.html"</span><span class="p">)</span>
<span class="p">.</span><span class="nx">pipe</span><span class="p">(</span>
<span class="nx">$</span><span class="p">.</span><span class="nx">rename</span><span class="p">({</span>
<span class="na">extname</span><span class="p">:</span> <span class="s2">".cshtml"</span>
<span class="p">})</span>
<span class="p">)</span>
<span class="p">.</span><span class="nx">pipe</span><span class="p">(</span><span class="nx">$</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s2">"@media"</span><span class="p">,</span> <span class="s2">"@@media"</span><span class="p">))</span>
<span class="p">.</span><span class="nx">pipe</span><span class="p">(</span><span class="nx">gulp</span><span class="p">.</span><span class="nx">dest</span><span class="p">(</span><span class="s2">"../DotNetCoreBackend/Emails/Emails"</span><span class="p">))</span>
<span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s2">"end"</span><span class="p">,</span> <span class="nx">done</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">}</span>
</code></pre>
</div>
<p>I use <a href="https://github.com/toddams/RazorLight"><code class="highlighter-rouge">RazorLight</code></a> to fill out data in the
templates, so I change the extension while copying them. It’s also why I replace
<code class="highlighter-rouge">@media</code> with the Razor safe <code class="highlighter-rouge">@@media</code>.</p>
<p>In the end, I end up with good looking HTML emails that are filled with Razor and
can be sent to any user with any email client!</p>
<p><strong>EDIT:</strong> <a href="https://www.reddit.com/r/programming/comments/627egf/html_emails_its_2017_and_email_is_still_horrible/">Reddit discussion</a></p>Christian DroulersApparently, wanting technology that was drafted in 1997 and finalised in 2011 to work properly in 2017 is asking too much. Pretty emails that work consistently across different clients are very hard to build. If your application sends transactional emails, this post is probably relevant to you!Migrating .NET Core project.json to MSBuild format2017-03-17T15:00:00+00:002017-03-17T15:00:00+00:00http://geeks.akinox.com/2017/03/17/migrating-dotnetcore<p><a href="https://www.visualstudio.com/downloads/">VS2017</a> is officially out and with it,
the new version of the .NET Core build system: <code class="highlighter-rouge">MSBuild</code>!</p>
<p>What? They’ve gone BACK? Yes. <code class="highlighter-rouge">project.json</code> was basically reimplementing everything already present
in MSBuild so they changed back. Don’t worry, they upgraded MSBuild to be much lighter and less
XML verbose. One of my test project has only 65 lines of XML and that includes some whitespace.</p>
<p>So migrating was a little bit of work since the migration tool works well for a vanilla
<code class="highlighter-rouge">project.json</code>, but I had a few customizations for StyleCop and others. Here’s a quick recap of
all the steps I had to go through and some caveats to keep in mind.</p>
<h2 id="migrate-from-projectjson-to-csproj">Migrate from <code class="highlighter-rouge">project.json</code> to <code class="highlighter-rouge">csproj</code></h2>
<p>After installing the <a href="https://www.microsoft.com/net/core#windowscmd">.NET Core SDK 1.0.1</a>,
the first step is migrating to <code class="highlighter-rouge">csproj</code>.</p>
<p>First, I had to upgrade the <code class="highlighter-rouge">sdk</code> property of <code class="highlighter-rouge">global.json</code>, otherwise
it couldn’t find the <code class="highlighter-rouge">migrate</code> command.</p>
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">{</span><span class="w">
</span><span class="nt">"projects"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="s2">"src"</span><span class="p">,</span><span class="w"> </span><span class="s2">"test"</span><span class="w"> </span><span class="p">],</span><span class="w">
</span><span class="nt">"sdk"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nt">"version"</span><span class="p">:</span><span class="w"> </span><span class="s2">"1.1.1"</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre>
</div>
<p>Then, in the root folder of your solution:</p>
<div class="highlighter-rouge"><pre class="highlight"><code>dotnet migrate
</code></pre>
</div>
<p>This will take care of transforming all your <code class="highlighter-rouge">project.json</code> files to <code class="highlighter-rouge">csproj</code>.
I had to delete my <code class="highlighter-rouge">.sln</code> file and create it anew in VS2017, but that might be my fault.</p>
<p>That’s the easy part! After that, a simple <code class="highlighter-rouge">dotnet build</code> worked.</p>
<h2 id="stylecopanalyzers">StyleCop.Analyzers</h2>
<p>I use <a href="https://github.com/DotNetAnalyzers/StyleCopAnalyzers">StyleCop.Analyzers</a>
to lint my code and make sure everyone uses the same style. In each <code class="highlighter-rouge">project.json</code>,
I had the following to link to shared settings in the root directory:</p>
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="s2">"buildOptions"</span><span class="err">:</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="nt">"debugType"</span><span class="p">:</span><span class="w"> </span><span class="s2">"portable"</span><span class="p">,</span><span class="w">
</span><span class="nt">"additionalArguments"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
</span><span class="s2">"/ruleset:../../stylecop.ruleset"</span><span class="p">,</span><span class="w">
</span><span class="s2">"/additionalfile:../../stylecop.json"</span><span class="w">
</span><span class="p">],</span><span class="w">
</span><span class="nt">"warningsAsErrors"</span><span class="p">:</span><span class="w"> </span><span class="kc">false</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre>
</div>
<p>The <code class="highlighter-rouge">migrate</code> command <em>did not</em> take care of that. I had to open each <code class="highlighter-rouge">csproj</code> file
and add the following:</p>
<div class="language-xml highlighter-rouge"><pre class="highlight"><code><span class="nt"><PropertyGroup></span>
<span class="nt"><CodeAnalysisRuleSet></span>..\..\stylecop.ruleset<span class="nt"></CodeAnalysisRuleSet></span>
<span class="nt"></PropertyGroup></span>
<span class="nt"><ItemGroup></span>
<span class="nt"><AdditionalFiles</span> <span class="na">Include=</span><span class="s">"..\..\stylecop.json"</span> <span class="nt">/></span>
<span class="nt"></ItemGroup></span>
</code></pre>
</div>
<p>Depending on when you migrate, you might have an issue where the JSON file
is not loaded properly and StyleCop reports hundreds of errors.</p>
<p>The issue <a href="https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2290">is resolved and waiting for merge here</a>.</p>
<h2 id="dotnet-test-and-shippable"><code class="highlighter-rouge">dotnet test</code> and Shippable</h2>
<p>I had to upgrade the three following dependencies from NuGet to their latest version.</p>
<ul>
<li><code class="highlighter-rouge">Microsoft.NET.Test.Sdk</code>: 15.0.0</li>
<li><code class="highlighter-rouge">xunit</code>: 2.2.0</li>
<li><code class="highlighter-rouge">xunit.runner.visualstudio</code>: 2.2.0</li>
</ul>
<p><code class="highlighter-rouge">dotnet test</code> does not have the same xUnit runner anymore. The test results
are output in <code class="highlighter-rouge">TRX</code> format, which is not compatible with xUnit or jUnit by default.</p>
<p>I had to hunt the Internet for an XSLT file that transformed TRX to jUnit format
so Shippable could understand the test results.
<a href="https://gist.github.com/cdroulers/510d2ecd6ff92002bb39469821a3a1b5">Here is the result</a> on
GitHub Gist.</p>
<h2 id="shippableyml">Shippable.yml</h2>
<p>A few changes were needed to <code class="highlighter-rouge">shippable.yml</code> for everything to work. You can see
<a href="/2016/10/28/dotnet-shippable-build/">my original post explaining</a>
the basics of Shippable.</p>
<div class="language-yml highlighter-rouge"><pre class="highlight"><code><span class="s">language</span><span class="pi">:</span> <span class="s">none</span>
<span class="s">build</span><span class="pi">:</span>
<span class="s">pre_ci_boot</span><span class="pi">:</span>
<span class="s">image_name</span><span class="pi">:</span> <span class="s">microsoft/dotnet</span>
<span class="s">image_tag</span><span class="pi">:</span> <span class="s">1.1.1-sdk</span> <span class="c1"># Changed from 1.1.0-sdk-projectjson</span>
<span class="s">pull</span><span class="pi">:</span> <span class="s">true</span>
<span class="s">options</span><span class="pi">:</span> <span class="s2">"</span><span class="s">-e</span><span class="nv"> </span><span class="s">HOME=/root"</span>
<span class="s">ci</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">apt-get --assume-yes install xsltproc</span>
<span class="c1"># Removed the sed to treat warnings as errors</span>
<span class="pi">-</span> <span class="s">dotnet restore</span>
<span class="s"># Re-enable this when StyleCop.Analyzers is updated with the fix.</span>
<span class="pi">-</span> <span class="s">dotnet build</span> <span class="c1"># /p:TreatWarningsAsErrors=true</span>
<span class="pi">-</span> <span class="s">cd test/Akinox.Backend.Test.Unit</span>
<span class="c1"># Changed this to output TRX format</span>
<span class="pi">-</span> <span class="s">dotnet test --logger "trx;LogFileName=../../../output.xml"</span>
<span class="s">on_success</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">cd ../..</span>
<span class="c1"># Uses new XLST file.</span>
<span class="pi">-</span> <span class="s">xsltproc -o shippable/testresults/result.xml scripts/trx-to-junit.xslt output.xml</span>
<span class="s">on_failure</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">cd ../..</span>
<span class="c1"># Uses new XLST file.</span>
<span class="pi">-</span> <span class="s">xsltproc -o shippable/testresults/result.xml scripts/trx-to-junit.xslt output.xml</span>
</code></pre>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>And with that, I’m at the same point I was before, except in VS2017.
Now on to trying to load the solution with
<a href="https://www.visualstudio.com/vs/visual-studio-mac/">VS For Mac</a>!</p>
<p>If you’ve migrated and had problems, please mention them in the comments!</p>
<h2 id="relevant-links">Relevant links</h2>
<p>A few links I found useful while going through the migration.</p>
<ul>
<li><a href="http://www.natemcmaster.com/blog/2017/01/19/project-json-to-csproj/">Nate McMaster - project.json to csproj part 1</a></li>
<li><a href="http://www.natemcmaster.com/blog/2017/02/01/project-json-to-csproj-part2/">Nate McMaster - project.json to csproj part 2</a></li>
<li><a href="https://docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj">Microsoft Docs - project.json to csproj</a></li>
</ul>Christian DroulersVS2017 is officially out and with it, the new version of the .NET Core build system: MSBuild!Using wkthmltopdf to create PDFs of your pages2017-03-10T15:00:00+00:002017-03-10T15:00:00+00:00http://geeks.akinox.com/2017/03/10/wkhtmltopdf-printing<p>It might have happened to you before. Your boss asks you, for some reason, to generate a PDF.</p>
<p>Your mouth says “yes” but your heart screams “NOOOOOOOOOOOOOOOOOO”!</p>
<p>Toolkits to generate PDFs exist, there’s many of them. But they’re complicated and each of them has quirks
and special handling.</p>
<p>You know what’s simple? HTML, CSS and JavaScript. You’ve probably already got what you want in PDF in web format.
So why don’t we just print that? <a href="https://wkhtmltopdf.org/"><code class="highlighter-rouge">wkhtmltopdf</code></a> to the rescue!</p>
<p>This uses <a href="https://www.qt.io/">QT</a> and the <a href="https://webkit.org/">WebKit</a> engine
to render an HTML document to PDF. WebKit being a full-featured browser engine means your
JavaScript executes too. That means you can even render your
<abbr title="Single Page Application">SPA</abbr> to PDF!</p>
<p>So for users who don’t know or can’t use “Print to PDF” in Chrome or other browsers, you can
now easily offer that functionality.</p>
<p>If you don’t know about media types for printing, you should probably
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media">look into them</a> first. Just make sure
that your CSS hides all the fluff around your page (app-bar, menus, footers, etc.) when the
<code class="highlighter-rouge">media-type</code> is <code class="highlighter-rouge">print</code> and you should be good to go!</p>
<p>Here is the command I use, formatted for clarity. Escape for your shell of choice!</p>
<div class="highlighter-rouge"><pre class="highlight"><code>./wkhtmltopdf
--window-status "rendered"
--zoom 1
--dpi 96
--disable-smart-shrinking
-B 0
-T 0
-L 0
-R 0
--print-media-type
--page-size Letter
"http://example.org"
"./example.pdf"
</code></pre>
</div>
<ul>
<li><code class="highlighter-rouge">--window-status "rendered"</code>: This makes sure that <code class="highlighter-rouge">window.status</code> is equal to “rendered”
before creating the PDF. It’s also possible to use <code class="highlighter-rouge">--javascript-delay {delay-in-ms}</code> if
there are problems with <code class="highlighter-rouge">window.status</code>.</li>
<li><code class="highlighter-rouge">--zoom 1</code>: See DPI and Smart Shrinking.</li>
<li><code class="highlighter-rouge">--dpi 96</code>: DPI settings and Smart Shrinking need to be specified for the output to be
consistent on different computers. I had weird results in production because I had
tested on my 4K monitor with different DPI in Windows settings .</li>
<li><code class="highlighter-rouge">--disable-smart-shrinking</code>: See DPI</li>
<li><code class="highlighter-rouge">-B 0</code>: Border bottom</li>
<li><code class="highlighter-rouge">-T 0</code>: Border top</li>
<li><code class="highlighter-rouge">-L 0</code>: Border left</li>
<li><code class="highlighter-rouge">-R 0</code>: Border right</li>
<li><code class="highlighter-rouge">--print-media-type</code>: Renders the HTML page with a print media type.</li>
<li><code class="highlighter-rouge">--page-size Letter</code>: Set up the page size for your country.</li>
<li><code class="highlighter-rouge">"http://example.org"</code>: URL to render.</li>
<li><code class="highlighter-rouge">"./example.pdf"</code>: Output file.</li>
</ul>
<p>With this, I had very little work to get my report to become a PDF. I had to tweak the
<code class="highlighter-rouge">print</code> stylesheet some, but just to make sure it looked good and fit properly.</p>
<p>Tweaking the <code class="highlighter-rouge">print</code> stylesheet can be done easily with Chrome Developer tools since you
can tell it to render the page as it would for printing.</p>
<p><img src="/img/posts/chrome-devtools-css-media.png" alt="Chrome devtools CSS media" /></p>
<p><a href="http://stackoverflow.com/questions/21247583/not-able-to-find-emulate-css-media-in-google-chrome">See here for how to open the rendering tab</a>.</p>
<p>It’s a great solution since it also prevents having two different views for the same data and
it’s easy to re-use known technologies for rendering the HTML.</p>
<p><strong>EDIT</strong>: There’s a bunch of <a href="https://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=wkhtmltopdf&starCount=0">docker images</a>
available as well, so you might not even need to download anything to use it!</p>
<p>As I’ve <a href="/2017/03/03/cross-platform-development-with-dotnetcore-and-mssql/">posted recently about MSSQL on Docker</a>, it’s
a good idea to dockerize dependencies!</p>Christian DroulersIt might have happened to you before. Your boss asks you, for some reason, to generate a PDF.Cross platform development with .NET Core and MSSQL2017-03-03T11:30:00+00:002017-03-03T11:30:00+00:00http://geeks.akinox.com/2017/03/03/cross-platform-development-with-dotnetcore-and-mssql<p>For new development done at Akinox on our Telemedecine platform, we’ve chosen <a href="https://www.microsoft.com/net/core">.NET Core</a>
as the backend (a blog post will eventually explain why). Our frontend is built using <a href="https://nodejs.org/en/">Node.js</a> and React. The database is on SQL Server since it has been that for a long
time now.</p>
<p>Recently, we’ve had help from developers who run their development setup on Macs. This was a little
troublesome to setup backend development. It involved setting up a Windows VM on VirtualBox, installing
Visual Studio 2015, SQL Server and possibly other dependencies to build the legacy application where
the database backup and database migrations are currently held. Then, once that was done, network
configuration and port forwarding and so on had to be built. This was a long and complicated process
which is also heavy on a smaller development machine.</p>
<p>With the recent arrival of <a href="https://www.microsoft.com/en-us/sql-server/sql-server-vnext-including-Linux">MSSQL on Linux</a>,
I planned on looking into it. Last week was the final straw when a new developer couldn’t get his frontend
to communicate with the backend. I decided to look if there was a docker image for MSSQL.
<a href="https://hub.docker.com/r/microsoft/mssql-server-linux/">There totally was!</a></p>
<p>After downloading the huge image with</p>
<div class="highlighter-rouge"><pre class="highlight"><code>docker pull microsoft/mssql-server-linux
</code></pre>
</div>
<p>I was able to start a working instance with the following command</p>
<div class="highlighter-rouge"><pre class="highlight"><code>docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=AstrongPasswordHere!' -p 1433:1433 -v C:/dev/data/mssql:/var/opt/mssql --name mssql -d microsoft/mssql-server-linux
</code></pre>
</div>
<p>For those unfamiliar with docker, here’s a quick explanation of each parameter:</p>
<ul>
<li><code class="highlighter-rouge">-e 'ACCEPT_EULA=Y'</code>: Required by the container to start properly.</li>
<li><code class="highlighter-rouge">-e 'SA_PASSWORD=AstrongPasswordHere!'</code>: Setting the password for the SA user. It needs
to be a strong password or the instance will not start.</li>
<li><code class="highlighter-rouge">-p 1433:1433</code>: This means that port <code class="highlighter-rouge">1433</code> on localhost will forward to <code class="highlighter-rouge">1433</code> on the container.
If you already have <code class="highlighter-rouge">1433</code> used on localhost, you can change the first port to something else,
e.g. <code class="highlighter-rouge">11433:1433</code>.</li>
<li><code class="highlighter-rouge">-v C:/dev/data/mssql:/var/opt/mssql</code>: This maps the local path <code class="highlighter-rouge">C:\dev\data\mssql</code> to <code class="highlighter-rouge">/var/opt/mssql</code>
on the container. It’s useful to store data between restarts of the container. Also between upgrades and whatnot. Note that using forward slashes is required on Windows as well!</li>
<li><code class="highlighter-rouge">--name mssql</code>: Friendly name to give the container for re-use later on.</li>
<li><code class="highlighter-rouge">-d</code>: Runs as a deamon, meaning we won’t remain attached in the console.</li>
<li><code class="highlighter-rouge">microsoft/mssql-server-linux</code>: Tells docker to use this image for our container.</li>
</ul>
<p>Since I mapped a local folder, I simply copied a backup of my current database running in
SQL Server to the folder and I was able to use SQL Server Management Studio on my docker instance
to restore the backup.</p>
<p>It’s also possible to install <code class="highlighter-rouge">sqlcmd</code> directly on the container after attaching to it.
<a href="https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools">Here are instructions on installing it</a>.</p>
<p>Once installed, I had two extra steps before being able to run it.</p>
<div class="highlighter-rouge"><pre class="highlight"><code>locale-gen
export LC_ALL="en_US.UTF-8"
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA
</code></pre>
</div>
<p>Here is a screenshot of what it looks like!</p>
<p><img src="/img/posts/mssql-sqlcmd-sample.png" alt="sqlcmd sample output" /></p>
<p>Restoring my backup was a simple</p>
<div class="highlighter-rouge"><pre class="highlight"><code>RESTORE DATABASE [MyDatabase]
FROM DISK = N'/var/opt/mssql/backup/mydatabase.bak' WITH
FILE = 1,
MOVE N'MyDatabase_Data' TO N'/var/opt/mssql/data/MyDatabase_Data.MDF',
MOVE N'MyDatabase_Log' TO N'/var/opt/mssql/data/MyDatabase_Log.LDF',
NOUNLOAD,
REPLACE,
STATS = 5
</code></pre>
</div>
<p>And there you have it! SQL Server in a docker container! This worked much better for our
developer on Mac, removing the necessity of a VM!</p>
<p>It’s also practical to make the setup of the application faster and more easily reproducible
since all of it can be automated. I’ve changed my setup on my laptop to remove SQL Server entirely
since it’s lighter to run docker!</p>
<p>It’s also a step towards full containerization of our app, which would allow much easier deployments
and a transition to Cloud Hosting without too much hassle.</p>Christian DroulersFor new development done at Akinox on our Telemedecine platform, we’ve chosen .NET Core as the backend (a blog post will eventually explain why). Our frontend is built using Node.js and React. The database is on SQL Server since it has been that for a long time now..NET Core build on Shippable2016-10-28T16:30:00+00:002016-10-28T16:30:00+00:00http://geeks.akinox.com/2016/10/28/dotnet-shippable-build<p>At Akinox, we use <a href="https://app.shippable.com/">Shippable</a> for our automated builds. Mainly because
it integrates quite well with <a href="https://bitbucket.org">BitBucket</a>.</p>
<p>Since our new application uses .NET Core, we obviously had to do a bit of manual set-up since
it’s not in Shippable’s supported languages.</p>
<p>Starting from <a href="https://github.com/Shippable/support/issues/2870">this issue’s</a> <code class="highlighter-rouge">shippable.yml</code>
config, I was able to get our project to build and to get the test results out into Shippable.</p>
<p>Here is what is looks like</p>
<figure class="highlight"><pre><code class="language-yml" data-lang="yml"><span class="s">language</span><span class="pi">:</span> <span class="s">none</span>
<span class="s">build</span><span class="pi">:</span>
<span class="s">pre_ci_boot</span><span class="pi">:</span>
<span class="s">image_name</span><span class="pi">:</span> <span class="s">microsoft/dotnet</span>
<span class="s">image_tag</span><span class="pi">:</span> <span class="s">1.0.0-preview2-sdk</span>
<span class="s">pull</span><span class="pi">:</span> <span class="s">true</span>
<span class="s">options</span><span class="pi">:</span> <span class="s2">"</span><span class="s">-e</span><span class="nv"> </span><span class="s">HOME=/root"</span>
<span class="s">ci</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">apt-get --assume-yes install xsltproc</span>
<span class="pi">-</span> <span class="s">dotnet restore</span>
<span class="pi">-</span> <span class="s">dotnet build **/project.json</span>
<span class="pi">-</span> <span class="s">cd test/UnitTestProject</span>
<span class="pi">-</span> <span class="s">dotnet test -xml ../../output.xml</span>
<span class="pi">-</span> <span class="s">cd ../..</span>
<span class="pi">-</span> <span class="s">xsltproc -o shippable/testresults/result.xml scripts/xunit-to-junit.xslt output.xml</span></code></pre></figure>
<p>Since my tests use xUnit, I have to transform the output to <code class="highlighter-rouge">junit</code> format for Shippable
to understand them. I found
<a href="http://4a47.blogspot.ca/2014/12/xunitnet-junit-jenkins.html">this great post</a>
with the proper xslt which can
<a href="https://gist.github.com/cdroulers/e23eeb31d6c1c2cade6f680e321aed8d">be downloaded here</a>.
I only had to change the version to <code class="highlighter-rouge">1.0</code> for <code class="highlighter-rouge">xsltproc</code> to work!</p>Christian DroulersAt Akinox, we use Shippable for our automated builds. Mainly because it integrates quite well with BitBucket.A New Beginning2016-04-14T12:00:00+00:002016-04-14T12:00:00+00:00http://geeks.akinox.com/2016/04/14/a-new-beginning<p>Oh dear, my first blog post!</p>
<p><a href="/img/post-bg-fjord.jpg">
<img src="/img/post-bg-fjord.jpg" alt="Post Sample Image" width="750" />
</a>
<span class="caption text-muted">To go places and do things that have never been done before – that’s what living is all about.</span></p>
<figure class="highlight"><pre><code class="language-javascript" data-lang="javascript"><span class="kd">function</span> <span class="nx">sometesthere</span><span class="p">(</span><span class="nx">lolwot</span><span class="err">:</span> <span class="nx">string</span><span class="p">)</span> <span class="o">=></span> <span class="nx">number</span> <span class="p">{</span>
<span class="k">return</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">lolwot</span><span class="p">);</span>
<span class="p">}</span></code></pre></figure>Christian DroulersOh dear, my first blog post!