<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Timur M. on Medium]]></title>
        <description><![CDATA[Stories by Timur M. on Medium]]></description>
        <link>https://medium.com/@misharintimur?source=rss-11379479c915------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wFuHf84xI_EZDJdN-ipDNQ@2x.jpeg</url>
            <title>Stories by Timur M. on Medium</title>
            <link>https://medium.com/@misharintimur?source=rss-11379479c915------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 08:59:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@misharintimur/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Generating Dockerfiles in Visual Studio Code Using OpenAI’s GPT-3 — In-depth Tutorial]]></title>
            <link>https://medium.com/@misharintimur/generating-dockerfiles-in-visual-studio-code-using-openais-gpt-3-in-depth-tutorial-fb8a9fcb457c?source=rss-11379479c915------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb8a9fcb457c</guid>
            <category><![CDATA[visual-studio-code]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[chat-gpt-ai]]></category>
            <category><![CDATA[openai]]></category>
            <dc:creator><![CDATA[Timur M.]]></dc:creator>
            <pubDate>Sun, 04 Jun 2023 11:49:50 GMT</pubDate>
            <atom:updated>2023-06-04T12:10:39.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*HabivlyzHswU-oGR-fpyow.png" /></figure><h3>Generating Dockerfiles in Visual Studio Code Using OpenAI’s GPT-3 — In-depth Tutorial</h3><p>Creating Dockerfiles can often be a bit tedious, especially when you have to take care of various configurations and dependencies. But what if there was a way to automatically generate Dockerfiles using AI? In this article, we will walk through the process of creating a Visual Studio Code (VS Code) extension that uses OpenAI’s GPT-3 to generate Dockerfiles.</p><p><strong>You can check out the extension on the VS Code Marketplace </strong><a href="https://marketplace.visualstudio.com/items?itemName=TimurMisharin.dockerfile-generator"><strong>here</strong></a><strong> and the source code on GitHub </strong><a href="https://github.com/TimurMisharin/DockerGenie"><strong>here</strong></a><strong>.</strong></p><h4>Prerequisites</h4><p>Before we dive into the tutorial, you will need:</p><p>1. Node.js installed on your system (download from <a href="https://nodejs.org/">here</a>).<br>2. Visual Studio Code (VS Code) installed on your system (download from <a href="https://code.visualstudio.com/">here</a>).<br>3. Basic understanding of TypeScript and Dockerfiles.<br>4. An API key from OpenAI. If you don’t have one, you can get it from the <a href="https://beta.openai.com/signup/">OpenAI Dashboard</a>.</p><h4>Setting Up Your VS Code Extension Project</h4><p>First, we need to set up a new VS Code extension project. For this, we’ll use <a href="https://yeoman.io/">Yeoman</a>, a scaffolding tool for modern web apps. Run the following commands in your terminal to install Yeoman and the VS Code extension generator:</p><pre>npm install -g yo generator-code</pre><p>Next, use Yeoman to generate a new VS Code extension:</p><pre><br>yo code</pre><p>During the setup process, select the following options:</p><p>- <strong>Type of extension</strong>: TypeScript<br>- <strong>Name</strong>: Dockerfile Generator<br>- <strong>Identifier</strong>: dockerfile-generator<br>- <strong>Description</strong>: Automatically generates Dockerfiles using GPT-3.<br>- <strong>Initialize a git repository?</strong> (Y/n): n (you can initialize a git repository later if you wish)</p><p>The setup will generate a new directory, `<em>dockerfile-generator</em>`, with a basic structure for your extension.</p><h4>Understanding the Extension Code</h4><p>Navigate to the `<em>src</em>` directory and open the `<em>extension.ts</em>` file. This is where most of our code will reside.</p><p>The boilerplate code comes with two key functions, `<em>activate</em>` and `<em>deactivate</em>`. The `<em>activate</em>` function is called when your extension is activated (i.e., when your command is executed for the first time), and `<em>deactivate</em>` is called when your extension is deactivated.</p><p>The primary goal of our extension is to generate Dockerfiles using OpenAI’s GPT-3. To do this, we’re using the `<em>vscode.commands.registerCommand</em>` method to register our command. This method is called when the user executes the command from the command palette (`<em>Ctrl+Shift+P</em>` or `<em>Cmd+Shift+P</em>`).</p><p>Let’s break down the logic of our command:</p><p>1. <strong>Check workspace</strong>: The extension first verifies if a workspace is open. If not, it shows an error message and exits.</p><pre><br> const workspaceFolders = vscode.workspace.workspaceFolders;<br> if (!workspaceFolders) {<br>   vscode.window.showErrorMessage(“No workspace folder is opened.”);<br>   return;<br> }<br></pre><p>2. <strong>Create Dockerfile</strong>: Next, it tries to create a new Dockerfile in the root of the first workspace folder.</p><pre><br> const dockerfilePath = `${workspaceFolders[0].uri.fsPath}/Dockerfile`;<br> try {<br>   await vscode.workspace.fs.writeFile(vscode.Uri.file(dockerfilePath), Buffer.from(“”));<br> } catch(e) {<br>   if (e instanceof Error) {<br>     vscode.window.showErrorMessage(`Failed to create Dockerfile: ${e.message}`);<br>     return;<br>   } else {<br>     throw e;<br>   }<br> }<br> </pre><p>3. <strong>Fetch configuration</strong>: After creating the Dockerfile, the extension fetches the configuration from VS Code’s settings. It includes</p><p>the GPT-3 version and OpenAI API key.</p><pre><br> const config = vscode.workspace.getConfiguration(‘dockerfile-generator’);<br> const chatGptVersion = config.get(‘chatGptVersion’, ‘gpt-3.5-turbo’);<br> const apiKey = config.get(‘openaiApiKey’, ‘’);<br> if (!apiKey) {<br>   vscode.window.showErrorMessage(“No API key for OpenAI provided.”);<br>   return;<br> }<br></pre><p>4. <strong>Get Dockerfile contents from user:</strong> The extension then prompts the user to provide the content details of the Dockerfile.</p><pre> const input = await vscode.window.showInputBox({prompt: ‘What should the Dockerfile include?’});<br> </pre><p>5. <strong>Generate Dockerfile content</strong>: Using the provided details, the extension makes a request to OpenAI’s API to generate the Dockerfile content.</p><pre> const chatGptResponse = await axios.post&lt;ChatGptResponse&gt;(<br>     “https://api.openai.com/v1/chat/completions&quot;,<br>     {<br>       “model”: chatGptVersion,<br>       “messages”: [<br>         {<br>           “role”: “user”,<br>           “content”: `Generate Dockerfile code only with comments for: ${input}`,<br>     }]<br>   },{<br>   headers: {<br>   ‘Content-Type’: ‘application/json’,<br>   ‘Authorization’: `Bearer ${apiKey}`<br>   },<br>   maxBodyLength: Infinity,<br> });<br></pre><p>6. <strong>Insert Dockerfile content</strong>: Finally, the extension opens the newly created Dockerfile and inserts the generated content at the beginning of the file.</p><pre> const dockerfile = await vscode.workspace.openTextDocument(vscode.Uri.file(dockerfilePath));<br> await vscode.window.showTextDocument(dockerfile, {preview: false});<br> await vscode.window.activeTextEditor?.edit(edit =&gt; {<br>   edit.insert(new vscode.Position(0, 0), chatGptResponse.data.choices[0].message.content);<br> });<br></pre><p>The extension handles exceptions using a try/catch block. If any error occurs during the process, it shows an error message with the relevant details.</p><h4>Running Your Extension</h4><p>To run your extension, open VS Code and go to the Debug view (`<em>Ctrl+Shift+D</em>` or `<em>Cmd+Shift+D</em>`). Then, click on the “Run Extension” configuration, and click on the “Start Debugging” button (or `<em>F5</em>`).</p><p>After successfully starting your extension, a new VS Code window will open. In this new window, open the command palette (`<em>Ctrl+Shift+P</em>` or `<em>Cmd+Shift+P</em>`), search for “Generate Dockerfile”, and hit `<em>Enter</em>`.</p><h3>Publishing Your Extension</h3><p>After testing your extension thoroughly, the next step is to publish it on the Visual Studio Code Marketplace. Here’s how you can do that:</p><h4><strong>Prerequisites for Publishing</strong></h4><p>1. Install `<em>vsce</em>`, the command-line tool for managing VS Code extensions. Use the following npm command to install it globally:</p><pre><br> npm install -g vsce<br> </pre><p>2. Create a Microsoft account, if you don’t have one already. This is required to access the Visual Studio Marketplace.</p><h4><strong>Publishing Steps</strong></h4><p>1. <strong>Login to the Publisher</strong>: The first step is to create a publisher ID on the <a href="https://marketplace.visualstudio.com/manage/publishers">Visual Studio Marketplace Management Site</a>. After creating your publisher ID, log in with the following command:</p><pre><br> vsce login [publisher name]<br> </pre><p>You’ll be prompted to enter a Personal Access Token. Follow the instructions <a href="https://code.visualstudio.com/api/working-with-extensions/publishing-extension#get-a-personal-access-token">here</a> to generate a new Personal Access Token.</p><p>2. <strong>Package Your Extension</strong>: Before publishing, it’s a good idea to package your extension into a VSIX file and test it locally. Run this command in your terminal to create a `<em>.vsix</em>` file:</p><pre><br> vsce package<br> </pre><p>This file can be installed in VS Code by navigating to the extensions view, clicking on the `<em>…</em>` at the top right, selecting `<em>Install from VSIX…</em>`, and choosing your file.</p><p>3. <strong>Publish Your Extension</strong>: After you’ve tested your extension, publish it to the marketplace using this command:</p><pre><br> vsce publish<br> </pre><p>This will package your extension, create a new version, and publish it under your publisher ID.</p><p>Congratulations! Your extension is now available for anyone to use. You’ve just contributed to the vibrant ecosystem of tools and utilities that make VS Code such a powerful editor.</p><h4>Conclusion</h4><p>In this tutorial, we’ve walked you through the process of creating a VS Code extension that uses OpenAI’s GPT-3 model to generate Dockerfiles, and we’ve shown you how to publish that extension to the VS Code Marketplace. By automating Dockerfile creation, you’ve added a tool to the developer community that can save time and reduce errors. With a little bit of tweaking, you can extend this concept to generate other types of files or even write boilerplate code. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb8a9fcb457c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>