De­vOps

10:10AMJuly 7 2020Daniel Tompkins

Archive KB

De­vOps (de­vel­oper op­er­a­tions) has be­come a very im­por­tant part of my per­sonal and pro­fes­sional work. As a soft­ware en­gi­neer, the tools we use to pro­vide ap­pli­ca­tion sta­bility and clear us­ability often be­comes part of our reg­ular soft­ware main­te­nance. Many of my own tools for set­ting up an ap­pli­ca­tion be­come ver­sion-con­trolled.

To me, De­vOps are the BASH scripts, Dock­er­files, en­vi­ron­ment con­fig­u­ra­tion, and many other things that are tan­gen­tial to the ap­pli­ca­tion— yet crit­ical for a more pain­less de­vel­oper ex­pe­ri­ence (DX). These notes pro­vide step-by-step guides, as well as quick notes and hacks, for en­gi­neering pow­erful local and re­mote de­vel­op­ment en­vi­ron­ments.

Git

Ba­sics

Up­date Re­mote

To up­date the re­mote URI for a git repo, use the fol­lowing:

# Remove existing remote git remote rm origin # Configure the new repote git remote add origin git@github.com:/[username]/[repo_name].git # Push to new upstream (-u | --set-upstream) git push -u origin master
shell

Node

NVM

I rec­om­mend in­stalling Node through the Node Ver­sion Man­ager (NVM) script. This al­lows you to easily mi­grate be­tween Node ver­sions on the system.

Install Node version manager (NVM)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
shell

Log out and back in or source ~/.bashrc to begin using the nvm com­mand.

Package Man­age­ment

Yarn

Yarn seems to pro­vide some ben­e­fits out-of-the-box be­yond what NPM (Node Package Man­ager) does.

# Install Yarn # Add the Yarn privacy key to pull from that APT repo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/ # Update your package manager (Ubuntu's APT shown) and install the yarn package sudo apt update && sudo apt install yarn
shell

Con­tent Man­age­ment Sys­tems (CMS)

Ghost

Ghost has changed dra­mat­i­cally since I first tried it out. In the be­gin­ning, I thought it was more of an open-source CMS... Now, it seems more like an all-in-one plat­form for making a fully-fea­tured Node.js blog. Bat­teries in­cluded means:

  • Lo­gins for mem­bers
  • Sub­scrip­tion models
  • Pay­ment op­tions for au­di­ence

It's un­clear to me now, from the home­page, whether it still sup­ports some kind of free op­tion for hobby de­vel­opers. I wrote a quick tu­to­rial from when that was the case. Keep in mind this was circa 2019 and things move fast.

In­stall Ghost CLI

yarn global add ghost-cli
shell

In­stall local CMS admin

mkdir ghost-admin && cd ghost-admin # Admin access is at: http://localhost:2368/ghost ghost install local
shell

Gatsby Fron­tend

Gatsby is a fron­tend React frame­work that has been around for a bit. I've never used it for a long time. I got drawn into Next.js around the same time that I was fi­nally fig­uring out React. I did find some in­ter­esting tu­to­rials for in­te­grating it with the Ghost CMS.

Quickstart
cd gatsby-starter-ghost yarn install # serve on http://localhost:8000 yarn dev
shell

Link the Ghost CMS admin to the Gatsby fron­tend:

  • Go to Ghost admin: http://​lo­cal­host:2368/​ghost/
  • Go to Set­tings > In­te­gra­tions
  • Click Add Custom In­te­gra­tion link and give it a name
  • Copy the Con­tent API key and paste in gatsby-starter-ghost/.ghost.json
.ghost.json
{ "development": { "apiUrl": "https://localhost:2368", "contentApiKey": "[API_KEY]" } }
json

To run with Dock­er­ized Nginx:

docker-compose.yml
version: '3' services: ghost: image: ghost:latest restart: always depends_on: - db environment: url: https://example.com database__client: mysql database__connection__host: db database__connection__user: root database__connection__password: your_database_root_password database__connection__database: ghost volumes: - /opt/ghost_content:/var/lib/ghost/content db: image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: your_database_root_password volumes: - /opt/ghost_mysql:/var/lib/mysql nginx: build: context: ./nginx dockerfile: Dockerfile restart: always depends_on: - ghost ports: - "80:80" - "443:443" volumes: - /etc/letsencrypt/:/etc/letsencrypt/ - /usr/share/nginx/html:/usr/share/nginx/html
yml

Certbot SSL

Install Certbot directly on server
# Install using a package manager (Ubuntu APT shown) sudo apt update # Update to lastest packages sudo apt install software-properties-common sudo add-apt-repository ppa:certbot/certbot # Add the certbot repo sudo apt update # Update again to fetch latest packages sudo apt install certbot # Install certbot package # Generate a certificate with certbot sudo certbot certonly --standalone -d example.com
shell