these days i am using a note taking tool called logseq. I will save about this tool for another post but this apps has changed the way i rememeber things. This post is first of my thoughts out of second brain logseq
After site being down for couple of week, i ended up spending sometime to get it up and running in few hours. Along the while i docuemented few things on logseq that helped bring this up and running.
Before my site went down(due droplet was re-created and cert expired) i had nginx server that would serve a static site built using hugo and had lets-encrypt certbot for cert , both the services were running as the docker container. however now that i am re-doing the whole setup, i though giving caddy a try.
-
Pre-requisite
- a domain- i bought this domain from namecheap.
- a droplet in digital ocean(good choice of names for business)- for this now this is simplest way to spin up a node to expose on internet.
-
Setup the droplet.
- Create a droplet on the digital ocean which comes with a root user. use the following commands to create a user and install necesasry tools
- create a user for droplet and enable firewall.
-
adduser msio usermod -aG sudo msio ufw allow OpenSSH ufw enable ufw status
-
-
install docker
- sudo apt install docker-ce
- if in case you have to sudo to use docker and want to avoid then this will help
-
sudo usermod -aG docker ${USER}
-
-
install docker compose
- Use below commands to install and check the version of the docker-composer
-
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose --version
-
- Use below commands to install and check the version of the docker-composer
-
Caddy
- Caddy is go based server that has lot of features built-in and make the configuration lot easier than other server. One such feature i really like in caddy is automatic lets-encrypt setup out of the box. all you need to let caddy know is an email address to get the https working. First lets use docker compose and setup an image and volume for it wor
- We need two things to setup caddy
- Caddyfile: this fine describes our configuration that caddy to should configure with. in my case i need to let addy know of domain, and content dir to server from and email for letsencrypt
- Docker Compose file : in this file we describe caddy server and volume and respective mapping.
-
Caddyfile
-
# used for the letsencrypt cert setup { email [email protected] } sandeepm.dev { # this tells caddy to serve the content from the . in docker-compose.yaml you will see /srv will be mapped in the volume to directory fo where my site data is mappeds root * /srv file_server } www.sandeepm.dev { root * /srv file_server }
-
-
docker-compose.yaml
-
version: '3' services: #caddy service caddy: # pulling in alpine image image: caddy:alpine #https://docs.docker.com/config/containers/start-containers-automatically/ - do not restart when stopped restart: unless-stopped volumes: # caddy own data - caddy_data:/data - caddy_config:/config # static content to serve - /home/mso/sandeepm.dev/public:/srv # Caddy require a caddyfile that has configuration you want to customize. by deafult image is shiped with one. - /home/mso/sandeepm.dev/docker/Caddyfile:/etc/caddy/Caddyfile # exposing port for external access. ports: - 80:80 - 443:443 # create a new caddy network. this would be better use full if you would deploy caddy to acts reverse proxy to some other backend servers networks: - caddy volumes: caddy_data: caddy_config: networks: caddy: external: true
-
- We need two things to setup caddy
- Caddy is go based server that has lot of features built-in and make the configuration lot easier than other server. One such feature i really like in caddy is automatic lets-encrypt setup out of the box. all you need to let caddy know is an email address to get the https working. First lets use docker compose and setup an image and volume for it wor
- you run the above docker file from the same dir as the file with
docker-compose up
. This will do following- Pull in the caddy server image
- map the volume as specified
- if the file and location are correct, container will take the Caddyfile you specified
- starts the lets-encrypt cert challenge and make sure cert is setup correctly.
- once the caddy is up wihtout any errors , you should be able to access content from your domain
-
Git Action Workfolw
- Additionally i have a git action workflow that pushes the content from my github to the nodes for this i have setup the git Runner and workflow. i will describe the process in the next post.