<?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"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://fanthoni.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 16:17:48 GMT</lastBuildDate><atom:link href="https://fanthoni.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Deploy Containerized Python Flask App to Heroku]]></title><description><![CDATA[App.py
In the main function, ensure you have the following code to get the port from the os environment
if __name__ == '__main__':
    port = int(os.environ.get("PORT", 6000))
    app.run(host="0.0.0.0", port=port, debug=True)

Dockerfile
# syntax=do...]]></description><link>https://fanthoni.hashnode.dev/deploy-containerized-python-flask-app-to-heroku</link><guid isPermaLink="true">https://fanthoni.hashnode.dev/deploy-containerized-python-flask-app-to-heroku</guid><dc:creator><![CDATA[Ferrel Anthoni]]></dc:creator><pubDate>Fri, 17 May 2024 05:39:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1715923925021/7adff7a1-078e-49e9-9bd1-10399e2a4bba.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-apppy">App.py</h2>
<p>In the main function, ensure you have the following code to get the port from the os environment</p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    port = int(os.environ.get(<span class="hljs-string">"PORT"</span>, <span class="hljs-number">6000</span>))
    app.run(host=<span class="hljs-string">"0.0.0.0"</span>, port=port, debug=<span class="hljs-literal">True</span>)
</code></pre>
<h2 id="heading-dockerfile">Dockerfile</h2>
<pre><code class="lang-dockerfile"><span class="hljs-comment"># syntax=docker/dockerfile:1</span>

<span class="hljs-keyword">FROM</span> python:<span class="hljs-number">3.9</span>-slim-buster

<span class="hljs-keyword">WORKDIR</span><span class="bash"> /python-docker</span>

<span class="hljs-keyword">COPY</span><span class="bash"> requirements.txt requirements.txt</span>
<span class="hljs-keyword">RUN</span><span class="bash"> pip install -r requirements.txt</span>

<span class="hljs-keyword">COPY</span><span class="bash"> . .</span>

<span class="hljs-keyword">CMD</span><span class="bash"> [ <span class="hljs-string">"python"</span>, <span class="hljs-string">"app.py"</span>]</span>
</code></pre>
<p>The requirements.txt are the list of dependencies packages required by our app to function properly. In this case my requirements.txt look something like this</p>
<pre><code class="lang-dockerfile">google-ai-generativelanguage==<span class="hljs-number">0.6</span>.<span class="hljs-number">2</span>
google-api-core==<span class="hljs-number">2.19</span>.<span class="hljs-number">0</span>
google-api-python-client==<span class="hljs-number">2.129</span>.<span class="hljs-number">0</span>
google-auth==<span class="hljs-number">2.29</span>.<span class="hljs-number">0</span>
google-auth-httplib2==<span class="hljs-number">0.2</span>.<span class="hljs-number">0</span>
google-generativeai==<span class="hljs-number">0.5</span>.<span class="hljs-number">2</span>
googleapis-common-protos==<span class="hljs-number">1.63</span>.<span class="hljs-number">0</span>
Flask==<span class="hljs-number">3.0</span>.<span class="hljs-number">3</span>
python-dotenv==<span class="hljs-number">1.0</span>.<span class="hljs-number">0</span>
</code></pre>
<p>To automatically write all package dependencies to <code>requirements.txt</code>, run the following command:</p>
<pre><code class="lang-dockerfile">pip3 freeze &gt; requirements.txt
</code></pre>
<h2 id="heading-deployment">Deployment</h2>
<ol>
<li>Build the project</li>
</ol>
<p><code>docker build --platform linux/amd64 -t &lt;TAG_NAME&gt; .</code></p>
<ol start="2">
<li>Make sure the image is there</li>
</ol>
<p><code>docker image ls</code></p>
<ol start="3">
<li>Tag the image with the heroku registry app</li>
</ol>
<p><code>docker tag &lt;TAG_NAME&gt;</code><a target="_blank" href="http://registry.heroku.com/portfolio-gpt/web"><code>registry.heroku.com/&lt;APP_NAME&gt;/web</code></a></p>
<ol start="4">
<li>Push the image to heroku</li>
</ol>
<p><code>docker push</code><a target="_blank" href="http://registry.heroku.com/portfolio-gpt/web"><code>registry.heroku.com/&lt;APP_NAME&gt;/web</code></a></p>
<p>If for some reason upon <code>docker push</code>, you are getting <code>unauthorized: authentication required</code> error, please run the following command</p>
<pre><code class="lang-dockerfile">heroku container:login
</code></pre>
<ol start="5">
<li>Release</li>
</ol>
<p><code>heroku container:release web -a &lt;APP_NAME&gt;</code></p>
]]></content:encoded></item><item><title><![CDATA[Deploying DotNet Core App to Heroku using Docker]]></title><description><![CDATA[Introduction
In this post, I'll explain how to dockerize a .Net core app. This post specifically talks about dockerizing in Apple Silicon M1 chip (arm64 architecture) as there are some difficulties with building the solution in docker with this archi...]]></description><link>https://fanthoni.hashnode.dev/deploying-dotnet-core-app-to-heroku-using-docker</link><guid isPermaLink="true">https://fanthoni.hashnode.dev/deploying-dotnet-core-app-to-heroku-using-docker</guid><category><![CDATA[Docker]]></category><category><![CDATA[.NET]]></category><category><![CDATA[deployment]]></category><category><![CDATA[Heroku]]></category><dc:creator><![CDATA[Ferrel Anthoni]]></dc:creator><pubDate>Mon, 08 Jan 2024 03:32:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1704684885129/33dbc22e-90de-412b-a993-d6193a83affa.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>In this post, I'll explain how to dockerize a .Net core app. This post specifically talks about dockerizing in Apple Silicon M1 chip (arm64 architecture) as there are some difficulties with building the solution in docker with this architecture.</p>
<p>This post won't be going over what is Docker. If you are interested in learning docker please visit <a target="_blank" href="https://docs.docker.com/get-started/overview/">this</a> official website from docker.</p>
<p>Let's dive in!</p>
<h2 id="heading-step-by-step-to-dockerize-and-deploy-net-to-heroku">Step by Step to Dockerize and Deploy .NET to Heroku</h2>
<p>Here are the steps to create and deploy app to Heroku:</p>
<ol>
<li><p>Create .NET app</p>
</li>
<li><p>Create Heroku project</p>
</li>
<li><p>Containerize our app and deploy to Heroku</p>
</li>
</ol>
<h3 id="heading-create-your-net-app">Create your .NET App</h3>
<p><em>source:</em> <a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-8.0&amp;tabs=visual-studio-code">https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-8.0&amp;tabs=visual-studio-code</a></p>
<ol>
<li>In your root project, open the terminal and start the project</li>
</ol>
<pre><code class="lang-plaintext">dotnet new webapi --use-controllers -o &lt;YourAppName&gt;
</code></pre>
<ol>
<li>A new project folder will be created</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1704682472977/8698e3a6-40b5-4cff-9046-f5311a2a4b2a.png" alt class="image--center mx-auto" /></p>
<ol>
<li>Run <em>dotnet run</em> in terminal and check if your app is running successfully. In this example I'm using Microsoft's weather forecast example.</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1704682733796/eba50abb-6ea1-492c-b440-4fb6f2089d9c.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-heroku-setup">Heroku Setup</h2>
<ol>
<li>Login to your Heroku account and create an app. Let's say the project name is <em>PalladiumFloorsBE</em></li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1704682865767/120ff08d-d256-46f2-af3a-8c0cf8cd5c6a.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-containerize">Containerize</h2>
<ol>
<li><p>In your VSCode project's root folder terminal type in the following:</p>
<pre><code class="lang-plaintext"> heroku login
</code></pre>
<p> A window will pop up in your browser prompting you to login to your heroku account</p>
</li>
<li><p>Next open your Docker Desktop app</p>
</li>
<li><p>Run the following command in your terminal</p>
<pre><code class="lang-plaintext"> heroku container:login
</code></pre>
</li>
<li><p>Make a release file of your solution by running the following command:</p>
<pre><code class="lang-plaintext"> dotnet publish -c Release -o out
</code></pre>
<p> This should create a folder with name <em>out</em></p>
</li>
<li><p>In that <em>out</em> folder, create a <em>Dockerfile</em> file and paste the following:</p>
<pre><code class="lang-dockerfile"> <span class="hljs-keyword">FROM</span> mcr.microsoft.com/dotnet/aspnet:<span class="hljs-number">8.0</span> AS runtime
 <span class="hljs-keyword">WORKDIR</span><span class="bash"> /App</span>
 <span class="hljs-keyword">COPY</span><span class="bash"> . .</span>
 <span class="hljs-keyword">CMD</span><span class="bash"> ASPNETCORE_URLS=http://*:<span class="hljs-variable">$PORT</span> dotnet &lt;YourProjectName&gt;.dll</span>
</code></pre>
<ul>
<li><p>Replace the runtime image on the first line according to your project's needs. To find which version is your using, you can go to the <em>.csproj</em> file at the root of the project and find the following line:</p>
<pre><code class="lang-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">TargetFramework</span>&gt;</span>net8.0<span class="hljs-tag">&lt;/<span class="hljs-name">TargetFramework</span>&gt;</span>
</code></pre>
</li>
<li><p>In this case my project is using .NET8</p>
</li>
<li><p>On the last line, replace the &lt;YourProjectName&gt; with the proper project name. Your project name should be the same one that you typed in step 1 of Create Your .NET App section of this post</p>
</li>
</ul>
</li>
<li><p>Build your project</p>
<pre><code class="lang-plaintext"> docker build --platform linux/amd64 -t palladiumfloorsbe ./out
</code></pre>
<ul>
<li>the --platform is to specify which architecture to run on. By default if you are using the M1 Apple Silicon chip, it will configure the platform to be arm64, which is not available by Heroku container registry</li>
</ul>
</li>
<li><p>Tag and push your image</p>
<pre><code class="lang-plaintext"> docker tag palladiumfloorsbe registry.heroku.com/&lt;YourAppNameInHeroku&gt;/web
 docker push registry.heroku.com/&lt;YourAppNameInHeroku&gt;/web
</code></pre>
</li>
<li><p>Release and deploy</p>
<pre><code class="lang-plaintext">  heroku container:release web -a &lt;YourAppNameInHeroku&gt;
</code></pre>
</li>
<li><p>Congrats!! You have deployed your project. Happy coding</p>
</li>
</ol>
<h2 id="heading-troubleshooting">Troubleshooting</h2>
<ul>
<li><p>If you app is deployed but there are errors, you can monitor them by running the following command:</p>
<pre><code class="lang-plaintext">  heroku logs --tail
</code></pre>
</li>
<li><p>Whenever you change your code and would like to release. You need to refollow step 6 to 8</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>