<?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: Anthony Dreessen</title>
    <description>The latest articles on Forem by Anthony Dreessen (@pinwheeler).</description>
    <link>https://forem.com/pinwheeler</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%2F53793%2F89df589c-2976-4537-a3da-21041a2c851e.jpeg</url>
      <title>Forem: Anthony Dreessen</title>
      <link>https://forem.com/pinwheeler</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pinwheeler"/>
    <language>en</language>
    <item>
      <title>Dirt Cheap Boot</title>
      <dc:creator>Anthony Dreessen</dc:creator>
      <pubDate>Sat, 30 Jan 2021 17:25:57 +0000</pubDate>
      <link>https://forem.com/pinwheeler/dirt-cheap-boot-49eh</link>
      <guid>https://forem.com/pinwheeler/dirt-cheap-boot-49eh</guid>
      <description>&lt;p&gt;Gather round as we embark on a journey about how you can host your very own fully fledged Spring Boot web application (API and Frontend) for as little as $5/month.&lt;/p&gt;

&lt;p&gt;I would like for this guide to be as comprehensive as possible. So if you have questions about how to get from point A to point B, please leave a comment.&lt;br&gt;
Oh, and if something here was helpful to you, remember to bookmark this guide so you can find it again.&lt;/p&gt;

&lt;p&gt;if you would like to see the projects I'm running using this technique check them out!&lt;br&gt;
&lt;a href="https://parrit.io"&gt;https://parrit.io&lt;/a&gt;&lt;br&gt;
&lt;a href="https://plenti.dev"&gt;https://plenti.dev&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  What You Need
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A spring boot web application that can run on your localhost machine&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Step 1: The Accounts
&lt;/h1&gt;

&lt;p&gt;We’re going to be signing up for a variety of accounts to piece together all of the various services you’re going to be using. &lt;em&gt;(Note: this simply the best, cheapest list of technologies I’ve found so far. If you have betters or alternatives, leave a comment below!)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Database: &lt;a href="https://www.elephantsql.com/"&gt;elephantsql&lt;/a&gt; (free)&lt;/p&gt;

&lt;p&gt;Hosting: &lt;a href="https://www.digitalocean.com/"&gt;digitalocean&lt;/a&gt; ($5/month)&lt;/p&gt;

&lt;p&gt;CI/CD: &lt;a href="https://codeship.com/"&gt;codeship&lt;/a&gt; (free)&lt;/p&gt;
&lt;h1&gt;
  
  
  Step 2: Environments
&lt;/h1&gt;

&lt;p&gt;Part of what is going to be so great about the finished product is the ability to use various environments all linked to their own git branches. Codeship is will be able to read the git branch and publish using the environment you specify.&lt;/p&gt;

&lt;p&gt;Here is my short writeup on environments. Follow this if you’re looking to set up staging versus production versus development and don’t already know how (or need a refresher)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://anthony-orange.medium.com/development-environments-in-spring-boot-dfda98833752"&gt;https://anthony-orange.medium.com/development-environments-in-spring-boot-dfda98833752&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Step 3: Configuring the Database
&lt;/h1&gt;

&lt;p&gt;Externalized databases running on separate servers than your application is a good idea. In order to get there, you’re going to need your localhost application to be using a local database instance. Here’s my guide for how to do that: &lt;a href="https://medium.com/@anthonyjamesdreessen/externalized-postgres-in-spring-boot-9043de80a7df"&gt;https://medium.com/@anthonyjamesdreessen/externalized-postgres-in-spring-boot-9043de80a7df&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we’re configured to do that, we want to use a remote database instance. We can do that through our environments!&lt;/p&gt;

&lt;p&gt;Here is a template of what a finished environment might look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring.datasource.url=jdbc:postgresql://dbname.db.elephantsql.com:5432/db_user_name
spring.datasource.username=db_user_name
spring.datasource.password=password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Step 4: Launching the Application
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Logging in through SSH
&lt;/h3&gt;

&lt;p&gt;First, make sure you can ssh into your droplet. You’re going to need get it set up so you don’t have to enter in the password every time. Check out this article for a how-to: &lt;a href="https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/"&gt;https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(tl;dr add your computer’s public key &lt;code&gt;~/.ssh/id_rsa.pub&lt;/code&gt; to your server’s &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Java
&lt;/h3&gt;

&lt;p&gt;An important step. DigitalOcean droplets don’t necessarily come with Java already installed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Update your apt-get&lt;/li&gt;
&lt;li&gt;Check out if your machine does &lt;code&gt;java -version&lt;/code&gt; if nothing is installed, you should be shown commands for how to do so. The default method is &lt;code&gt;sudo apt install default-jre&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Copy your application to your droplet
&lt;/h3&gt;

&lt;p&gt;copy over your &lt;code&gt;.jar&lt;/code&gt; file to the droplet &lt;code&gt;scp path/to/jar username@ip_address:&lt;/code&gt; &lt;strong&gt;make sure you add the colon.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then, after ssh-ing into your server, you can verify that your program works by running &lt;code&gt;/usr/bin/java -jar -Dspring.profiles.active=profile myapp.jar&lt;/code&gt; &lt;em&gt;(Note: don’t use this for your production deployment method. There’s something better in the next section)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;you should see the familiar Spring Boot startup console. navigate to &lt;code&gt;&amp;lt;droplet_ip&amp;gt;:8080&lt;/code&gt; in your browser/client to see it working.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 5: Starting your application remotely through SSH
&lt;/h1&gt;

&lt;p&gt;Modern Linux distros use systemd for deploying things like a Spring Boot application. In order to get it set up, you have to do some configuration on your droplet. I have instructions below, but if you want more information about this topic, click &lt;a href="https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#deployment-systemd-service"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While ssh-ed into your droplet:&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a service definition for your application
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;sudo vi /etc/systemd/system/myapp.service&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The service definition file should look something like this
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Unit]
Description=My Java Application
After=syslog.target

[Service]
Environment="MY_DATABASE_PASSWORD=&amp;lt;database_password&amp;gt;"
User=&amp;lt;droplet_username&amp;gt;
ExecStart=/usr/bin/java -Xmx256m -Dspring.profiles.active=&amp;lt;profile&amp;gt; -jar /home/&amp;lt;droplet_username&amp;gt;/myapp.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;systemctl daemon-reload&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test that the service is able to run the app manually by using the command &lt;code&gt;systemctl start myapp&lt;/code&gt; &lt;em&gt;(Note: since systemctl knows to look for the extension &lt;code&gt;.service&lt;/code&gt; you don’t need to append it to myapp, but you can)&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If step #4 fails, you can see what went wrong by using systemctl status myapp&lt;/p&gt;

&lt;h3&gt;
  
  
  Bake in SU access
&lt;/h3&gt;

&lt;p&gt;Now if you'll notice, when when we run the &lt;code&gt;systemctl start myapp&lt;/code&gt; command, we are interactively asked for our password. This will break any attempt to do this from an automated shell script which makes it difficult to automate our deploys on Codeship.&lt;/p&gt;

&lt;p&gt;In order to work around this, we specify exactly one command (the restart command) that our particular user is going to be able to execute without needing to enter a password. This remains a secure (enough) thing to do because we still have the SSH key for login into the droplet.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;sudo vi /etc/sudoers.d/myapp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;add this line &lt;code&gt;&amp;lt;username&amp;gt; ALL = NOPASSWD: /bin/systemctl restart myapp&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;**IMPORTANT: The value of myapp in the above must not contain any word boundaries. This mean no periods &lt;code&gt;.&lt;/code&gt; and no hyphens &lt;code&gt;-&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 6: Deploying automatically with Codeship
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Add ssh access to your codeship account
&lt;/h3&gt;

&lt;p&gt;This is very similar to what we did in step 4. In fact, you're simply going to append to the file we modified in step 4. You can find CodeShip's SSH key in &lt;code&gt;Builds =&amp;gt; Project Settings (gear icon) =&amp;gt; General =&amp;gt; Keys&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create deployment script on Codeship
&lt;/h3&gt;

&lt;p&gt;In the deploy settings on your Codeship project. We're going to want to use a custom script. The most basic version of this looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./gradlew bootJar
scp build/libs/myapp.jar username@ip_address:
ssh -t username@ip_address 'sudo /bin/systemctl restart myapp'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;builds the jar&lt;/li&gt;
&lt;li&gt;copies it over like we did last time&lt;/li&gt;
&lt;li&gt;executes the &lt;code&gt;restart&lt;/code&gt; command for &lt;code&gt;systemd&lt;/code&gt; to restart our service that we defined above&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Success!
&lt;/h1&gt;

&lt;p&gt;If I’ve successfully guided you then after your build goes green then you should be able to push code to a repository and have it trigger an automatic deploy to the cloud!&lt;/p&gt;

&lt;p&gt;Again, if you would like more explanation about how to get from point A to point B please leave a comment and I’ll be sure to get more thorough.&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>cloud</category>
      <category>infrastructure</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Explain Certificates Like I'm Five</title>
      <dc:creator>Anthony Dreessen</dc:creator>
      <pubDate>Mon, 20 Aug 2018 21:34:20 +0000</pubDate>
      <link>https://forem.com/pinwheeler/explain-certificates-like-im-five-1c0e</link>
      <guid>https://forem.com/pinwheeler/explain-certificates-like-im-five-1c0e</guid>
      <description>&lt;p&gt;Wondering about the difference between certificates, private keys, and public keys and what the general model is for being able to offload most of that work to keychain or some other automated "code signing" entity&lt;/p&gt;

</description>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>Apple Screenshots Made Easy</title>
      <dc:creator>Anthony Dreessen</dc:creator>
      <pubDate>Mon, 19 Mar 2018 23:15:22 +0000</pubDate>
      <link>https://forem.com/pinwheeler/apple-screenshots-made-easy-1mg5</link>
      <guid>https://forem.com/pinwheeler/apple-screenshots-made-easy-1mg5</guid>
      <description>&lt;p&gt;I try not to store a lot of things on my desktop, and it’s not a convenient place for me to store any screenshots that I might take in order to quickly email when I have all kinds of other windows up. I wanted a way to be able to just click and drag my most recent screenshot into whatever I might be working with. For this purpose, I looked into how to change the default screenshot location and found out it was very easy thanks to OSX Daily. For my purposes, I’m using the location of a folder named Screenshots on my desktop, but you could put anything in the file path specified. The very cool part is that this screenshots folder is sitting on my dock and is sorted by date added. What this means is I can just CMD-SHIFT-4 and badda-bing, badda-boom have a screenshot ready to work with. Want to do the same? Just open up terminal and type the following: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;defaults write com.apple.screencapture location ~/Desktop/Screenshots/&lt;/code&gt;&lt;br&gt;
&lt;code&gt;killall SystemUIServer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and if you wanted to switch back to the regular path, you could type the following&lt;br&gt;
&lt;code&gt;defaults write com.apple.screencapture location ~/Desktop/&lt;br&gt;
&lt;/code&gt;killall SystemUIServer`&lt;/p&gt;

&lt;p&gt;Bonus protip: add that folder to your dock and sort it by date added. Your most recent screenshots will be a click away&lt;/p&gt;

</description>
      <category>screenshots</category>
      <category>automation</category>
      <category>lifehacks</category>
      <category>protips</category>
    </item>
    <item>
      <title>Explain Load Balancers Like I'm Five</title>
      <dc:creator>Anthony Dreessen</dc:creator>
      <pubDate>Mon, 15 Jan 2018 22:16:35 +0000</pubDate>
      <link>https://forem.com/pinwheeler/explain-load-balancers-like-im-five-594l</link>
      <guid>https://forem.com/pinwheeler/explain-load-balancers-like-im-five-594l</guid>
      <description>&lt;p&gt;Why are they special? Wot's the big deal.&lt;/p&gt;

</description>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>Compile Time Pain</title>
      <dc:creator>Anthony Dreessen</dc:creator>
      <pubDate>Mon, 15 Jan 2018 21:32:15 +0000</pubDate>
      <link>https://forem.com/pinwheeler/compile-time-pain-4k95</link>
      <guid>https://forem.com/pinwheeler/compile-time-pain-4k95</guid>
      <description>&lt;p&gt;Hey all- not sure how many other iOS devs there are on this platform but I like the discussions I've seen so far. Wondering if anyone has any experience reducing compile time for their Swift apps and if there are any sharable tips and tricks you have.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>ios</category>
    </item>
  </channel>
</rss>
