<?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: Daniel Proctor</title>
    <description>The latest articles on DEV Community by Daniel Proctor (@danielproctor31).</description>
    <link>https://dev.to/danielproctor31</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%2F445026%2F350f1c7b-91e6-4dd4-8c65-d2e5cbd03d60.png</url>
      <title>DEV Community: Daniel Proctor</title>
      <link>https://dev.to/danielproctor31</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danielproctor31"/>
    <language>en</language>
    <item>
      <title>Fedora Silverblue</title>
      <dc:creator>Daniel Proctor</dc:creator>
      <pubDate>Thu, 20 Apr 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/danielproctor31/fedora-silverblue-59j0</link>
      <guid>https://dev.to/danielproctor31/fedora-silverblue-59j0</guid>
      <description>&lt;h2&gt;
  
  
  What is Silverblue?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://silverblue.fedoraproject.org/"&gt;Silverblue&lt;/a&gt; is Linux distribution created by Fedora that takes a different approach to system updates and maintenance. Unlike most traditional Linux distributions that allow system updates to be applied in-place, Silverblue is an &lt;strong&gt;immutable distribution&lt;/strong&gt; , which means that its core operating system and applications are read-only and cannot be modified during runtime. Instead, system updates are managed through &lt;a href="https://coreos.github.io/rpm-ostree/"&gt;rpm-ostree&lt;/a&gt;, which creates a new deployment of the system with updated packages and configuration files. This allows for a more reliable and stable system, as all changes are isolated to individual deployments, with the ability to rollback to the previous deployment should anything go wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flatpak
&lt;/h2&gt;

&lt;p&gt;Another advantage of Silverblue is the use of containers for applications. Applications are installed using &lt;a href="https://flatpak.org/"&gt;Flatpak&lt;/a&gt;. Flatpak applications are sandboxed meaning they do not interfere with the core operating system and can be updated and managed independently.&lt;/p&gt;

&lt;h2&gt;
  
  
  DistroBox
&lt;/h2&gt;

&lt;p&gt;As a developer, having a read-only file system can become a hindrance when you need to change things at the system level. This is where Toolbox and Distrobox come in. Using these you can run a completely different distribution with its own system using podman/docker while still having access to your home directory. This gives you access to a terminal environment which a traditional package manager using the distribution of your choice which you can modify as much as you like. Any issues will not break anything in the host system and you can easily start again from scratch if needed.&lt;/p&gt;

&lt;p&gt;Another benefit of this is you are able to setup your own pre-built images. In &lt;a href="https://github.com/danielproctor31/archbox"&gt;this repository&lt;/a&gt; I have created my own arch based image with all the software I use pre-installed and use a github action to build the image should I make any changes to it.&lt;/p&gt;

&lt;p&gt;Using distrobox I can pull down this and get up an running quickly by pulling the image and creating the container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;distrobox-create -i ghcr.io/danielproctor31/archbox:latest -n archbox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;whenever I then want to work in the container I can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;distrobox-enter archbox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Overlay
&lt;/h2&gt;

&lt;p&gt;In some cases there are packages which simply need to be installed at the operating system level to work. Such as Wireguard, Docker and Distrobox itself.&lt;/p&gt;

&lt;p&gt;In these instances you can use rpm-ostree to overlay these on top on the system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rpm-ostree install distrobox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the package at the system level and will be kept and updated like all the other system packages. To check which packages you have overlayed you can use &lt;code&gt;rpm-ostree status&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom Images
&lt;/h2&gt;

&lt;p&gt;My interest in Silverblue first came about when I came across the &lt;a href="https://github.com/ublue-os"&gt;uBlue Project&lt;/a&gt;. With Silverblue you can build your own images similar to how I previously mentioned with DistroBox. Then use rpm-ostree to rebase to it.&lt;/p&gt;

&lt;p&gt;This allows you to automate installing any packages you would always add whenever you install Linux and pre-configure anything to your liking. I have setup my own &lt;a href="https://github.com/danielproctor31/silverblue/"&gt;here&lt;/a&gt; which builds a new image nightly with updates from Fedora.&lt;/p&gt;

&lt;p&gt;After installing Silverblue from the official ISO you can rebase using rpm-ostree. In my case this would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo rpm-ostree rebase --experimental ostree-unverified-registry:ghcr.io/danielproctor31/silverblue:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After a reboot my system is setup to my liking and ready to go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://silverblue.fedoraproject.org/"&gt;https://silverblue.fedoraproject.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://coreos.github.io/rpm-ostree/"&gt;https://coreos.github.io/rpm-ostree/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/89luca89/distrobox"&gt;https://github.com/89luca89/distrobox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://flatpak.org/"&gt;https://flatpak.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ublue-os"&gt;https://github.com/ublue-os&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Git Hooks for .NET</title>
      <dc:creator>Daniel Proctor</dc:creator>
      <pubDate>Tue, 15 Mar 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/danielproctor31/commit-hooks-in-net-5e2g</link>
      <guid>https://dev.to/danielproctor31/commit-hooks-in-net-5e2g</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;When working in larger teams, It can be hard to keep a codebase in a consistent style, everyone has their own preference and may not have their IDE set up in the same way. This can lead to inconsistent code across the codebase depending on who has been working on it. In addition to this ensuring all code that gets pushed up is in a state where it can be deployed or anyone can checkout the branch with confidence that it will run without error can be hard. This is where githooks come in. We can set these up so all code that gets committed is in once consistent style and has been verified as buildable before it gets pushed up to the remote.&lt;/p&gt;

&lt;p&gt;The javascript ecosystem has a lot of tools that people have created to manage this, such as &lt;a href="https://www.npmjs.com/package/husky"&gt;Husky&lt;/a&gt; and &lt;a href="https://eslint.org/"&gt;eslint&lt;/a&gt;. But what about dotnet?&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/"&gt;Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/dotnet/format"&gt;dotnet-format&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A .NET Core project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  EditorConfig
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022"&gt;EditorConfig&lt;/a&gt; allows you to setup coding styles used in the codebase. This is supported by many IDE’s including Visual Studio and Rider. Below is a basic example provided by Microsoft. This should be saved as &lt;code&gt;.editorconfig&lt;/code&gt; in the root of your Solution alongside the .sln file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options"&gt;https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;###############################
# Core EditorConfig Options #
###############################
root = true
# All files
[*]
indent_style = space

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

# XML config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
insert_final_newline = true
charset = utf-8-bom
###############################
# .NET Coding Conventions #
###############################
[*.{cs,vb}]
# Organize usings
dotnet_sort_system_directives_first = true
# this. preferences
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_readonly_field = true:suggestion
# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
###############################
# Naming Conventions #
###############################
# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# Use PascalCase for constant fields  
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
###############################
# C# Coding Conventions #
###############################
[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent
# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
# Expression-level preferences
csharp_prefer_braces = true:silent
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
###############################
# C# Formatting Rules #
###############################
# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left
# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
###############################
# VB Coding Conventions #
###############################
[*.vb]
# Modifier preferences
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  IDE Settings
&lt;/h3&gt;

&lt;p&gt;Within your IDE you can setup to format documents on save. This will ensure whenever you are editing new or existing files, they will be formatted according to the .editorconfig whenever the file is saved.&lt;/p&gt;

&lt;p&gt;Rider: &lt;code&gt;File &amp;gt; Settings &amp;gt; Tools &amp;gt; Reformat and Cleanup Code&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Visual Studio (2022): &lt;code&gt;Tools &amp;gt; Options &amp;gt; Text Editor &amp;gt; Code Cleanup &amp;gt; Run Code Cleanup Profile on Save&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  dotnet-format
&lt;/h2&gt;

&lt;p&gt;dotnet-format is a cli tool which we can use to format the code as part of the githook. Style preferences will be read from the .editorconfig file. &lt;a href="https://github.com/dotnet/format"&gt;https://github.com/dotnet/format&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dotnet tool install -g dotnet-format&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Githooks
&lt;/h2&gt;

&lt;p&gt;At the root of the repo, there will be a .git folder. Within here there is a folder for hooks and a config file. As the idea for this is to share the hooks across the team. We will be running the hooks from a &lt;code&gt;.hooks&lt;/code&gt; folder in the root of the repo. This will need to be set per user in their local git config. This can be done with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --local core.hooksPath .hooks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The hooks folder can then exist in source code.&lt;/p&gt;

&lt;h3&gt;
  
  
  pre-commit
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;.hooks/pre-commit&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh

FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs")
if [-n "$FILES"]
then
    dotnet format ./path/to/project.sln --include $FILES
    echo "$FILES" | xargs git add
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This runs on each commit and performs the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get a list of staged files where the file extension is &lt;code&gt;.cs&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If there are any files, run dotnet format with the path to the solution and pass in the list of files.&lt;/li&gt;
&lt;li&gt;re-stages the formatted files ready to be committed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ensure that the solution path is changed to the correct path and filename.&lt;/p&gt;

&lt;h3&gt;
  
  
  pre-push
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;.hooks/pre-push&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh

dotnet build "./path/to/project.sln"
dotnet test "./path/to/project.sln" --filter "Category!=Integration"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will be on push and performs the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run a full build of the solution.&lt;/li&gt;
&lt;li&gt;Runs the unit tests for the solution where the category is not &lt;code&gt;Integration&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Integration tests can be very long running and are best avoid during git commands. Any build errors or test failure will result in the push being rejected. Again, ensure the project path and filename are correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  Done
&lt;/h2&gt;

&lt;p&gt;That’s everything setup. It is worth noting that anyone pulling down the codebase for the first time will have to update their local gitconfig to point to the hooks folder. There are ways to automate this as a build script or as part of the .csproj Build targets, but that’s for another post :).&lt;/p&gt;

</description>
      <category>git</category>
      <category>githooks</category>
      <category>dotnet</category>
      <category>dotnetcore</category>
    </item>
    <item>
      <title>Duck DNS and Docker</title>
      <dc:creator>Daniel Proctor</dc:creator>
      <pubDate>Tue, 01 Mar 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/danielproctor31/duck-dns-and-docker-16ck</link>
      <guid>https://dev.to/danielproctor31/duck-dns-and-docker-16ck</guid>
      <description>&lt;p&gt;&lt;a href="https://www.duckdns.org/"&gt;Duck DNS&lt;/a&gt; is a service which lets you setup (up to 5) free sub domains on duckdns.org. In this post I will go over how I have automated this using Docker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;I use a home server for various things - a plex server, vpn, game servers to name a few. What if i need to access it remotely, Or Share an address so my friends can join a game? I could share my ip address and this would work for a time, but depending on what ISP you are with, your ip will likely change at some point in the near future. This is where Duck DNS comes in. Using their api and a cron job, we can use a duckdns.org subdomain and keep it updated with the correct ip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/get-docker/"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://www.duckdns.org"&gt;duckdns&lt;/a&gt; account.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that this tutorial is assuming you will be using linux containers with docker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating your Subdomain
&lt;/h2&gt;

&lt;p&gt;Login to &lt;a href="https://www.duckdns.org"&gt;https://www.duckdns.org&lt;/a&gt; using one of the login methods they provide. Here you will be presented with a page which lets you create a subdomain. Take note of the token displayed on this page as we will be using it later. Go ahead a create a subdomain. You will see the ip is set to your current ip address. This is what we will be changing using their api and your token.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bash Script
&lt;/h2&gt;

&lt;p&gt;Duck DNS provide an endpoint to keep your ip’s update to date:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.duckdns.org/update?domains=YourSubDomains&amp;amp;token=YourToken&amp;amp;ip=OptionalIp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can see they allow 3 query parameters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Domains - A comma separated string of your subdomains to update with the ip.&lt;/li&gt;
&lt;li&gt;Token - Your token we saw earlier.&lt;/li&gt;
&lt;li&gt;ip - This one is optional. You can provide an ip address. Or Duck DNS will determine your ip from where the request is coming from. In this instance we are assuming you want to use your current ip and will be leaving it blank.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I have written a simple bash script which uses curl to call this endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh

echo "Updating ip for domains: $DOMAINS"

if [-n "$IP"]; then
  echo "using ip: $IP"
fi

echo "$(curl "https://www.duckdns.org/update?domains=$DOMAINS&amp;amp;token=$TOKEN&amp;amp;ip=$IP")"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are using environment variables for the domains, ip and token. The script will echo the domains to be updated and the ip given if present. It will then use curl to call the endpoint with the given parameters and echo the output. Save this file as &lt;code&gt;run.sh&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cron Job
&lt;/h2&gt;

&lt;p&gt;We could run this script manually. But the idea is we want to automate this and not have to worry about it in future. For this we will be using cron.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*/5 * * * * /duckdns/run.sh &amp;gt;&amp;gt; /proc/1/fd/1 2&amp;gt;/proc/1/fd/2
# Newline to make file valid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have a cronfile which calls our script every 5 minutes and outputs to the shell. Note the &lt;code&gt;run.sh&lt;/code&gt; is being called in a /duckdns folder. We will be setting that up during the docker build. Save this as file &lt;code&gt;cronconfig&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A handy site for create cron schedules is &lt;a href="https://crontab.guru/#*/5_*_*_*_*"&gt;crontab.guru&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker
&lt;/h2&gt;

&lt;p&gt;We will be creating a custom Docker image to setup the cron.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM alpine:latest

# Create duckdns dir
RUN mkdir /duckdns
WORKDIR /duckdns

# Copy files
COPY run.sh run.sh
COPY cronconfig cronconfig

# Install dos2unix
RUN apk update \
    apk --no-cache add dos2unix
RUN apk add curl

# ensure scripts are using correct line endings
RUN dos2unix "run.sh"

# Set permissions
RUN chmod 0644 "cronconfig"
RUN chmod 0744 "run.sh"

## setup cron configs
RUN crontab "cronconfig"

# start container with crond
CMD ["crond", "-f"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Dockerfile performs the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use alpine as a base image.&lt;/li&gt;
&lt;li&gt;Create a directory where we will store our files.&lt;/li&gt;
&lt;li&gt;Copies our &lt;code&gt;run.sh&lt;/code&gt; and &lt;code&gt;cronconfig&lt;/code&gt; into the folder.&lt;/li&gt;
&lt;li&gt;Install dos2unix and curl.&lt;/li&gt;
&lt;li&gt;Uses dos2unix to ensure our files are using the correct line endings.&lt;/li&gt;
&lt;li&gt;Sets the correct permissions on the file so they can be executed.&lt;/li&gt;
&lt;li&gt;Runs crontab with our config to setup our cron.&lt;/li&gt;
&lt;li&gt;Finally set the container to startup with crond and runs in the foreground. Save this as &lt;code&gt;Dockerfile&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason dos2unix is required is if we are working on a windows or other non-unix operating system. The line endings without our files will be save as CRLF. As the Docker image is unix based (which uses LF line endings), this can causes issues running our scripts. using dos2unix ensure they are correct in every build regardless of the operating system they were created on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker-Compose
&lt;/h3&gt;

&lt;p&gt;I like to use docker-compose wherever I can. It makes recreating containers easier and reproducible without remembering any lengthy docker run commands. We can also specify our environment variables within the compose file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "2.4"
services:
  app:
    build:
      context: .
    env_file:
      - .env
    container_name: duck-dns
    restart: unless-stopped
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this as &lt;code&gt;docker-compose.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note we have specified an env file. Create a file called &lt;code&gt;.env&lt;/code&gt; within the same directory with the following content. Replacing the values with your relevant subdomains, token and optional ip.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DOMAINS=yourdomain1,yourdomain2
TOKEN=yourtoken
IP=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run the Container
&lt;/h2&gt;

&lt;p&gt;Finally we can get the container running. Run the container with :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let it do its thing and once it’s up and running you can check the logs to ensure it’s working as expected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker container logs duck-dns --follow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Updating ip for domains: yourdomain
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 2 0 2 0 0 1 0 --:--:-- 0:00:01 --:--:-- 1
OK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  All done
&lt;/h2&gt;

&lt;p&gt;That’s everything. Now you access your home network from wherever you need without needing to know the ip address. I have the final code setup as a github project &lt;a href="https://github.com/danielproctor31/duck-dns-docker"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>duckdns</category>
      <category>networking</category>
      <category>homelab</category>
    </item>
  </channel>
</rss>
