<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Andrey Koppel</title>
    <description>The latest articles on Forem by Andrey Koppel (@akoppela).</description>
    <link>https://forem.com/akoppela</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F39668%2Fa2ce3a60-b43b-4144-bedd-bc23aa96d632.png</url>
      <title>Forem: Andrey Koppel</title>
      <link>https://forem.com/akoppela</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/akoppela"/>
    <language>en</language>
    <item>
      <title>Migrating from AngularJS to Elm</title>
      <dc:creator>Andrey Koppel</dc:creator>
      <pubDate>Tue, 08 Sep 2020 06:27:57 +0000</pubDate>
      <link>https://forem.com/akoppela/migrating-from-angularjs-to-elm-23ad</link>
      <guid>https://forem.com/akoppela/migrating-from-angularjs-to-elm-23ad</guid>
      <description>&lt;h2&gt;
  
  
  What?
&lt;/h2&gt;

&lt;p&gt;Hi! In this article I'll describe &lt;a href="https://www.npmjs.com/package/@contasystemer/angularjs-custom-element"&gt;the tool&lt;/a&gt; and approach &lt;a href="https://github.com/ContaSystemer"&gt;we&lt;/a&gt; took to migrate our code base from &lt;a href="https://angularjs.org"&gt;AngularJS&lt;/a&gt; to &lt;a href="https://elm-lang.org"&gt;Elm&lt;/a&gt;. The goal is to share and to help anyone who could possibly have to go down the same route at any given moment.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;AngularJS is in the Long Term Support period at the moment. December 31, 2021 is the official deprecation date for AngularJS. Development teams and businesses will have to make a decision of which technology to migrate existing AngularJS code base to. We have decided to migrate to Elm. There are many good articles describing why Elm is a good choice. I'll focus on the migration part only.&lt;/p&gt;




&lt;h2&gt;
  
  
  How?
&lt;/h2&gt;

&lt;p&gt;There are various migration approaches like full rewrite from scratch and gradual migration, etc. A code base size may influence the migration strategy. Small code bases are very good for full rewrites. Full rewrites of bigger code bases are long and expensive. Depending on a current business situation the correct migration strategy may vary.&lt;/p&gt;




&lt;h2&gt;
  
  
  Our case
&lt;/h2&gt;

&lt;p&gt;We had a relatively big code base with around 100k lines of AngularJS code, around 150 different pages and 8 frontend developers. The business is in a growth stage and it's important to maintain and deliver new functionality with improvements to the customers. &lt;/p&gt;




&lt;h2&gt;
  
  
  Gradual migration
&lt;/h2&gt;

&lt;p&gt;We have chosen a gradual migration strategy. We want to reuse existing code as much as possible until we find a good time to do a full rewrite of a particular page. We want to write all new code in Elm. A good time for a full rewrite might be when significant changes are planned for a particular page or when a page is small enough for a fast migration. To be able to write new code in Elm we need to replicate the existing internal framework (shared functionality between all pages).&lt;/p&gt;

&lt;p&gt;So the strategy is to reuse existing AngularJS pages, directives, components in Elm when possible to speed up the migration and write new code in Elm. Never reuse Elm code in AngularJS (e.g. by wrapping Elm code with components) to stop AngularJS code base growth. Instead do a migration of the page to Elm.&lt;/p&gt;




&lt;h2&gt;
  
  
  The tool
&lt;/h2&gt;

&lt;p&gt;To reuse existing AngularJS code in Elm we have created and open sourced &lt;a href="https://www.npmjs.com/package/@contasystemer/angularjs-custom-element"&gt;angularjs-custom-element&lt;/a&gt; service to wrap any directive/component with a custom element. It has few usage examples in readme. Custom elements can be used in Elm very easily.&lt;/p&gt;




&lt;h2&gt;
  
  
  Migration step 1 - Independent Elm programs
&lt;/h2&gt;

&lt;p&gt;We started with an independent Elm program for each page. When AngularJS route changes a controller is initialized and an Elm program is embedded. On route leave an Elm program is destroyed. &lt;a href="https://discourse.elm-lang.org/t/unmountable-elm-programs/1515"&gt;Here&lt;/a&gt; you can find details on how to destroy an Elm program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migration step 2 - One single Elm program
&lt;/h2&gt;

&lt;p&gt;The next step was to combine all Elm programs into one single program. The first thing to do after AngularJS app bootstrap is to embed the main Elm program and not to render AngularJS page. The main entry point (an HTML element) for the main Elm program should be somewhere right after &lt;code&gt;ng-app&lt;/code&gt;. Elm program will decide when to render AngularJS page. In Elm program we add a special case (usually a page constructor) to fallback to AngularJS page (via custom element for &lt;code&gt;ng-view&lt;/code&gt;/&lt;code&gt;ui-view&lt;/code&gt;). Global subscription for route changes is added and a current URL is sent to Elm program via flags or a flag that current page is AngularJS page is sent. An Elm program parses URL and renders appropriate page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migration step 3 - Elm is everywhere
&lt;/h2&gt;

&lt;p&gt;AngularJS state router is removed. Elm manages all pages and routing. AngularJS app is bootstrapped when needed for existing legacy. A new custom element is created to bootstrap AngularJS page.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;It was a very nice experience for us and we are happy with what we've got now. It's still a long way for us to rewrite all pages to Elm. But the ability to move fast and do a migration at the same time is key for us as a development team and for a business!&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;

</description>
      <category>elm</category>
      <category>angular</category>
      <category>migration</category>
      <category>customelements</category>
    </item>
    <item>
      <title>How I installed GuixSD on DigitalOcean</title>
      <dc:creator>Andrey Koppel</dc:creator>
      <pubDate>Thu, 14 Nov 2019 05:32:50 +0000</pubDate>
      <link>https://forem.com/akoppela/how-i-installed-guixsd-on-digitalocean-26b0</link>
      <guid>https://forem.com/akoppela/how-i-installed-guixsd-on-digitalocean-26b0</guid>
      <description>&lt;p&gt;Hi. &lt;a href="http://guix.gnu.org/"&gt;Guix&lt;/a&gt; a functional package management tool. It can be used either on top of existing Linux distribution or as a part of Guix System Distribution (GuixSD). Which is quite interesting project for many reasons. &lt;a href="http://digitalocean.com/"&gt;DigitalOcean&lt;/a&gt; is a development cloud (DO for short).&lt;/p&gt;

&lt;p&gt;In this post I'm going to share what I did to install GuixSD on DO. I'm very new to Linux thus I got some issues on the way and I'd like to get some help in order to solve them.&lt;/p&gt;

&lt;p&gt;DO does not have GuixSD as available distribution. Thus there are two options how to install GuixSD.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;a href="https://lists.gnu.org/archive/html/guix-devel/2017-04/msg00139.html"&gt;Convert existing Linux distribution to GuixSD&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;However I got some issues on the last steps maybe because the post is from 2017 and things have changed, maybe there is other reason. Another thing is that it requires more knowledge about existing distribution to clean up after conversion. And being a noob in this area I decided to install GuixSD system from scratch.&lt;/p&gt;




&lt;h3&gt;
  
  
  Install GuixSD on DO from scratch
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Reformat system installer
&lt;/h4&gt;

&lt;p&gt;Guix provide a compressed ISO with system installer. DO has an option to upload custom image. It supports various formats but not ISO. Thus the first thing to do is to reformat installer image to a format which DO supports. I had VirtualBox installed already so I used it to convert the image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Download GuixSD installer
wget https://ftp.gnu.org/gnu/guix/guix-system-install-1.0.1.x86_64-linux.iso.xz

# Uncompress ISO
xz -d guix-system-install-1.0.1.x86_64-linux.iso.xz

# Convert ISO to VDI
vboxmanage convertfromraw guix-system-install-1.0.1.x86_64-linux.iso guix-system-install-1.0.1.x86_64-linux.vdi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Create DO droplet and install Guix system
&lt;/h4&gt;

&lt;p&gt;Next step is to upload image to DO and create droplet from it.&lt;/p&gt;

&lt;p&gt;When creating droplet DO provides &lt;code&gt;/dev/vda&lt;/code&gt; as a main disk. DO boots the machine with installer stored in &lt;code&gt;/dev/vda&lt;/code&gt; disk. When I followed &lt;a href="https://guix.gnu.org/manual/en/html_node/System-Installation.html"&gt;installation instructions&lt;/a&gt; I was unable to reformat &lt;code&gt;/dev/vda&lt;/code&gt; due to it being used by the system. I tried to check what part of the system exactly uses it, but could not find. There were no partitions/disks mounted, etc.. So this is one part which I'd like to understand if it's possible to reformat the disk which stores operation system and if yes how can I find out how it's used by the system.&lt;/p&gt;

&lt;p&gt;The next thing I tried is to add additional volume and install Guix system on it.&lt;/p&gt;

&lt;p&gt;When adding additional volumes DO provides &lt;code&gt;/dev/sdX&lt;/code&gt; disks. Following &lt;a href="https://guix.gnu.org/manual/en/html_node/System-Installation.html"&gt;installation instructions&lt;/a&gt; I was able to easily install GuixSD on &lt;code&gt;/dev/sda&lt;/code&gt; disk. I created 3 partitions one for Bios boot (1M), one for Linux swap (8G) and one for Linux filesystem (the rest). I used &lt;a href="https://github.com/akoppela/dotfiles/blob/f48aa9353fbd803a80a7bf1c07f614e3c69246d5/os-config.scm"&gt;bare bone system configuration&lt;/a&gt; to initialize GuixSD system.&lt;/p&gt;

&lt;h4&gt;
  
  
  Booting GuixSD
&lt;/h4&gt;

&lt;p&gt;The next thing was to boot installed GuixSD.&lt;/p&gt;

&lt;p&gt;As I understood DO uses &lt;code&gt;/dev/vda&lt;/code&gt; as a disk to boot system from. So after previous step I got 2 disks one with installer and one with GuixSD installed. Probably it would be possible to instruct DO to boot from additional volume with GuixSd but that would mean I had to carry installer along the way. What I did is I cloned &lt;code&gt;/dev/sda&lt;/code&gt; disk to &lt;code&gt;/dev/vda&lt;/code&gt; disk with following command (keep in mind that size of the volume should match the size of the droplet disk).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dd if=/dev/sda of=/dev/vda bs=64M conv=sync,noerror status=progress
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After reboot I was able to boot GuixSD from &lt;code&gt;/dev/vda&lt;/code&gt; disk.&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In the end it was a successful experiment though it felt like a workaround. I would like to know what I missed and if there is an easier way to install clean GuixSD on DO.&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;

</description>
      <category>guix</category>
      <category>digitalocean</category>
      <category>linux</category>
      <category>server</category>
    </item>
  </channel>
</rss>
