<?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: Kevin Nielsen</title>
    <description>The latest articles on Forem by Kevin Nielsen (@kevinanielsen).</description>
    <link>https://forem.com/kevinanielsen</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%2F1235003%2Ff519bb17-c1b5-4587-bfcb-90576405d8ce.jpeg</url>
      <title>Forem: Kevin Nielsen</title>
      <link>https://forem.com/kevinanielsen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kevinanielsen"/>
    <language>en</language>
    <item>
      <title>How to host your own CDN for free in less than 10 minutes</title>
      <dc:creator>Kevin Nielsen</dc:creator>
      <pubDate>Sat, 16 Dec 2023 19:46:35 +0000</pubDate>
      <link>https://forem.com/kevinanielsen/how-to-host-your-own-cdn-for-free-in-less-than-10-minutes-4l4h</link>
      <guid>https://forem.com/kevinanielsen/how-to-host-your-own-cdn-for-free-in-less-than-10-minutes-4l4h</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/kevinanielsen/go-fast-cdn/"&gt;github.com/kevinanielsen/go-fast-cdn&lt;/a&gt; recently reached version 0.1.0 and I thought a great way to celebrate that would be to show you how to use the pocketbase of CDNs to host for free and use it as your private CDN.&lt;br&gt;
To do this, there are very few requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic understanding of RESTful APIs&lt;/li&gt;
&lt;li&gt;Very basic understanding of dockerfiles&lt;/li&gt;
&lt;li&gt;Basic understanding of using your terminal of choice.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;Go-fast-cdn is a very minimal and easy-to-use CDN, and this is used as an advantage - With CDN's speed is the key, and that is no different for go-fast-cdn. &lt;em&gt;Fast&lt;/em&gt; is not just a part of the name for the sake of marketing. Go-fast-cdn is, as you might be able to tell, written in Golang which is known for its simplicity and its speed.&lt;/p&gt;

&lt;p&gt;Other than its speed, functionality is, as stated above, also a big factor for why you should try out go-fast-cdn. It has a straightforward API, with great documentation at go-fast-cdn.redoc.ly. It also, like Pocketbase, has a very minimalistic UI to assist you when uploading and listing content.&lt;/p&gt;

&lt;p&gt;For now, the CDN only supports images and documents, but expect more to come in the future.&lt;/p&gt;


&lt;h2&gt;
  
  
  How do I use it?
&lt;/h2&gt;

&lt;p&gt;Well, that's the easy part - All you need is Docker installed on your local machine and an internet connection.&lt;br&gt;
First, head over to fly.io and sign up. Then download the flyctl cli with one of the following commands.&lt;/p&gt;
&lt;h3&gt;
  
  
  MacOS
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;flyctl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pwsh &lt;span class="nt"&gt;-Command&lt;/span&gt; &lt;span class="s2"&gt;"iwr https://fly.io/install.ps1 -useb | iex"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Linux
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://fly.io/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then, create a file, where you want to store the Dockerfile and create a Dockerfile.&lt;br&gt;
touch Dockerfile&lt;br&gt;
Then open said Dockerfile with your favorite text editor, and paste the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; alpine:latest&lt;/span&gt;

&lt;span class="k"&gt;ARG&lt;/span&gt;&lt;span class="s"&gt; GO_FAST_VERSION=0.1.0&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;apk add &lt;span class="nt"&gt;--no-cache&lt;/span&gt; unzip openssh

&lt;span class="c"&gt;# download and unzip go-fast-cdn&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt;&lt;span class="s"&gt; https://github.com/kevinanielsen/go-fast-cdn/releases/download/${GO_FAST_VERSION}/go-fast-cdn-x86_64-linux.zip /tmp/cdn.zip&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;unzip /tmp/cdn.zip &lt;span class="nt"&gt;-d&lt;/span&gt; /cdn/

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 8080&lt;/span&gt;

&lt;span class="c"&gt;# start go-fast-cdn&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["/cdn/go-fast-cdn-linux"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the file, then return to your terminal and run the following commands. Make sure that Docker is running on your machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; cdn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this ran without issues, you should be ready to go, and you can quickly test it out by running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 8080:8080 cdn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you should be able to go to your browser, visit localhost:8080, and see go-fast-cdn running. If this is the case, then you are ready to deploy it on fly.io. Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flyctl launch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything looks correct, then go ahead and type n on your keyboard. Otherwise, you can tweak the settings by pressing y and get taken to fly.io to adjust the settings to your liking.&lt;br&gt;
The flyctl launcher should now be running and after a minute or two, the following text will appear&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Visit your newly deployed app at https://&amp;lt;your-chosen-name&amp;gt;.fly.dev/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you're good to go. If you want to contribute to go-fast-cdn, you're in luck - It's open-source! Head over to github.com/kevinanielsen/go-fast-cdn and open a PR if you want to see a change.&lt;/p&gt;

&lt;p&gt;If you like the project and want to support it, the best way to do so is by giving it a star on &lt;a href="https://github.com/kevinanielsen/go-fast-cdn/"&gt;GitHub&lt;/a&gt;. It lets more people know about the project and gives me motivation to continue developing it. Otherwise, go ahead and share this article with a friend or coworker.&lt;/p&gt;

</description>
      <category>cdn</category>
      <category>go</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
