<?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>DEV Community: Nik Volkov</title>
    <description>The latest articles on DEV Community by Nik Volkov (@heku4).</description>
    <link>https://dev.to/heku4</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%2F1004603%2F0126eacc-794d-4b21-ac0e-57c970d0a7fc.png</url>
      <title>DEV Community: Nik Volkov</title>
      <link>https://dev.to/heku4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/heku4"/>
    <language>en</language>
    <item>
      <title>Jetbrains Rider External Tools example based on Docker</title>
      <dc:creator>Nik Volkov</dc:creator>
      <pubDate>Mon, 20 May 2024 20:32:44 +0000</pubDate>
      <link>https://dev.to/heku4/jetbrains-rider-external-tools-example-based-on-docker-19om</link>
      <guid>https://dev.to/heku4/jetbrains-rider-external-tools-example-based-on-docker-19om</guid>
      <description>&lt;p&gt;Hello! &lt;/p&gt;

&lt;p&gt;In my work I often use Docker Compose to start test environment (databases, message buses, etc). Usually, I restart or remove containers and rerun it from &lt;em&gt;docker-compose.yml&lt;/em&gt; file.  In general, compose files stores in &lt;code&gt;%SolutionDir%/tests/&lt;/code&gt; directory. In my pet projects I organise project structure in the same way. &lt;/p&gt;

&lt;p&gt;To stay focused on code and stop switching to Docker-dashboard (or type commands) I need functionality that will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;restart containers from IDE&lt;/li&gt;
&lt;li&gt;remove containers from IDE&lt;/li&gt;
&lt;li&gt;start compose file from IDE&lt;/li&gt;
&lt;li&gt;show actual state for every container from IDE&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I found a solution to achieve all these goals. This is the &lt;a href="https://www.jetbrains.com/help/rider/Settings_Tools_External_Tools.html#advanced_options"&gt;Rider External Tools&lt;/a&gt;! This feature allows you to start shell-scripts, external apps and something like that. I want to show you how I use these tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create an External Tool
&lt;/h2&gt;

&lt;p&gt;The easiest way to show you creation tool is script for containers state.&lt;br&gt;
Open the Rider IDE. Go to &lt;em&gt;Settings → Tools → External Tools&lt;/em&gt; and click on the &lt;em&gt;+&lt;/em&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faz91slkmzbideihmrpof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faz91slkmzbideihmrpof.png" alt="Image description" width="571" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add a name and a description (optional) to a new tool. For example the name is &lt;em&gt;Container stats&lt;/em&gt;. You can type a new group name to create a specific group of your tools. Choose Docker as program. Add &lt;code&gt;ps -a&lt;/code&gt; as arguments to &lt;code&gt;docker&lt;/code&gt; command. Click &lt;em&gt;OK&lt;/em&gt; button to save a tool.&lt;/p&gt;

&lt;p&gt;Congratulations! You have created your first External Tool!&lt;/p&gt;
&lt;h2&gt;
  
  
  Add new tool to a toolbar
&lt;/h2&gt;

&lt;p&gt;External Tools will not be so useful if it can't be placed on a toolbar. It's very simple!&lt;br&gt;
Open a context menu on the central toolbar (or any other).&lt;br&gt;
And choose the &lt;em&gt;Customize Toolbar...&lt;/em&gt; option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcr411vm5yjmlw2jnxrbu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcr411vm5yjmlw2jnxrbu.png" alt="Image description" width="785" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the opened menu choose &lt;em&gt;Center&lt;/em&gt; toolbar and click the &lt;em&gt;+&lt;/em&gt; button. Now you can add an External Tool as button on the toolbar or add a separator to divide groups of buttons.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu77owvihrw2sa2htyzl7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu77owvihrw2sa2htyzl7.png" alt="Image description" width="588" height="591"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To add your custom External Tool choose &lt;em&gt;Add Action... → External Tools → %GroupName% → Container stats&lt;/em&gt; → OK. After that, choose your tool in list and click on the &lt;em&gt;pencil&lt;/em&gt; button.&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtq5wtk2corwg3qeaa4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbtq5wtk2corwg3qeaa4k.png" alt="Image description" width="26" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can upload your own image for button or choose Jetbrains standard icons. I just typed &lt;em&gt;docker&lt;/em&gt; and chose a nice Docker logo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgzg2brtivfpku54ltb17.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgzg2brtivfpku54ltb17.png" alt="Image description" width="599" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All done! Let's test our new tool-button. Just click on it and you will see an output in Runner menu.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gbr6bvnalza8pk5rlqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6gbr6bvnalza8pk5rlqh.png" alt="Image description" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Use macros for  specific commands
&lt;/h2&gt;

&lt;p&gt;To start &lt;em&gt;compose&lt;/em&gt; file just by clicking on external tool button - create new External Tool like on the screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe6x1ksgzv3qk29b6o9bt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe6x1ksgzv3qk29b6o9bt.png" alt="Image description" width="571" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;Working directory&lt;/em&gt; set with macros:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$UnixSeparators($ProjectFileDir$/tests)$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(for mac/linux).&lt;br&gt;
This macros will create absolute &lt;em&gt;path&lt;/em&gt; to your project folder and concatenate &lt;em&gt;/tests&lt;/em&gt; postfix.&lt;/p&gt;

&lt;p&gt;Add the new tool to toolbar and run it. You will see command output in the runner window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16qgkrb0u54bm0vigklb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16qgkrb0u54bm0vigklb.png" alt="Image description" width="800" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With a macros you can defined unique path (for an External Tool it must be absolute path) for you tool.&lt;/p&gt;

&lt;p&gt;Thank you! Hope this article will be helpful to you!&lt;/p&gt;
&lt;h2&gt;
  
  
  See also
&lt;/h2&gt;

&lt;p&gt;External Tools available not only for Rider!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.jetbrains.com/help/rider/Settings_Tools_External_Tools.html#advanced_options"&gt;External Tools Rider&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jetbrains.com/help/rider/built-in-macros.html"&gt;Built-in IDE macros&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jetbrains.com/help/idea/settings-tools-external-tools.html"&gt;External Tools IDEA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jetbrains.com/help/webstorm/configuring-third-party-tools.html"&gt;External Tools WebStorm&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  p.s.
&lt;/h3&gt;

&lt;p&gt;You can create your own script and map it on a tool. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker stop $(docker ps -a -q) &amp;amp;&amp;amp; docker rm $(docker ps -a -q)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this script will stop all containers and remove it. This command can be executed from any directory.&lt;/p&gt;

</description>
      <category>jetbrains</category>
      <category>rider</category>
      <category>docker</category>
      <category>backenddevelopment</category>
    </item>
  </channel>
</rss>
