DevOps (developer operations) has become a very important part of my personal and professional work. As a software engineer, the tools we use to provide application stability and clear usability often becomes part of our regular software maintenance. Many of my own tools for setting up an application become version-controlled.
To me, DevOps are the BASH scripts, Dockerfiles, environment configuration, and many other things that are tangential to the application— yet critical for a more painless developer experience (DX). These notes provide step-by-step guides, as well as quick notes and hacks, for engineering powerful local and remote development environments.
Git
Basics
Update Remote
To update the remote URI for a git repo, use the following:
# 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
Node
NVM
I recommend installing Node through the Node Version Manager (NVM) script. This allows you to easily migrate between Node versions on the system.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Log out and back in or source ~/.bashrc
to begin using the nvm
command.
Package Management
Yarn
Yarn seems to provide some benefits out-of-the-box beyond what NPM (Node Package Manager) 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
Content Management Systems (CMS)
Ghost
Ghost has changed dramatically since I first tried it out. In the beginning, I thought it was more of an open-source CMS... Now, it seems more like an all-in-one platform for making a fully-featured Node.js blog. Batteries included means:
- Logins for members
- Subscription models
- Payment options for audience
It's unclear to me now, from the homepage, whether it still supports some kind of free option for hobby developers. I wrote a quick tutorial from when that was the case. Keep in mind this was circa 2019 and things move fast.
Install Ghost CLI
yarn global add ghost-cli
Install local CMS admin
mkdir ghost-admin && cd ghost-admin
# Admin access is at: http://localhost:2368/ghost
ghost install local
Gatsby Frontend
Gatsby is a frontend React framework 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 finally figuring out React. I did find some interesting tutorials for integrating it with the Ghost CMS.
cd gatsby-starter-ghost
yarn install
# serve on http://localhost:8000
yarn dev
Link the Ghost CMS admin to the Gatsby frontend:
- Go to Ghost admin: http://localhost:2368/ghost/
- Go to Settings > Integrations
- Click Add Custom Integration link and give it a name
- Copy the Content API key and paste in
gatsby-starter-ghost/.ghost.json
{
"development": {
"apiUrl": "https://localhost:2368",
"contentApiKey": "[API_KEY]"
}
}
To run with Dockerized Nginx:
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
Certbot SSL
# 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