Quick Start Infrastructure: Using ChristianLempa's Templates for Docker, K8s, and Ansible
Here's a friendly explanation of how this collection can help you, along with guidance on adoption and sample code examples.
These templates are beneficial because they let you focus on writing code rather than spending excessive time on infrastructure setup and configuration.
| Tool | Benefit for Software Engineers | Example Use Case |
| Docker | Consistency & Isolation | Quickly containerize a new web service (e.g., a Python Flask API or a Node.js app) ensuring it runs the same way everywhere. |
| Kubernetes | Scalability & Orchestration | Deploy a complete, production-ready microservices application with features like load balancing and self-healing built-in. |
| Ansible | Automation & Infrastructure as Code (IaC) | Automate the setup of development or staging servers, ensuring all team members have the same environment configuration. |
In short, using these boilerplates means
Faster Project Start
No need to write basic configuration files from scratch.
Best Practices
The templates often follow community-accepted best practices, which can improve your application's reliability and security.
Reduced Errors
Copy-pasting known good configurations minimizes setup mistakes.
Adopting these boilerplates is straightforward and typically involves three main steps
Cloning, Customizing, and Implementing.
First, get a local copy of the templates
# Clone the repository
git clone https://github.com/ChristianLempa/boilerplates.git
# Navigate into the cloned directory
cd boilerplates
Browse the folders (e.g., docker/, kubernetes/, ansible/) to find the configuration that matches your needs.
Example
If you need a Docker setup for a basic web application
# Assuming a structure like this exists in the repo
cp docker/basic-web-app/Dockerfile ./my-new-project/
cp docker/basic-web-app/.dockerignore ./my-new-project/
This is the most crucial step. The boilerplate is just a starting point; you'll need to tailor it to your specific application.
Docker
Update the base image, port mappings, and environment variables.
Kubernetes
Modify the image names, replicas count, resource limits, and service type.
Ansible
Change hostnames, variables, and specific tasks within the playbooks.
Let's look at a conceptual example for each tool to illustrate how you'd use a template.
A common template is a basic Dockerfile for a Node.js application.
| Boilerplate Snippet | Customization Needed |
FROM node:18-alpine | Change to python:3.11-slim if you're using Python. |
WORKDIR /app | Keep this unless you have a specific reason to change your working directory. |
COPY package*.json ./ | Change to COPY requirements.txt ./ for Python. |
EXPOSE 3000 | Change to 8080 if your application listens on port 8080. |
CMD ["npm", "start"] | Change to CMD ["python", "app.py"] for a Python app. |
Goal
Quickly containerize a Python Flask application.
Action
Take the Node.js boilerplate, rename it to Dockerfile in your project root, and apply the Python-specific changes.
A Kubernetes template often includes a deployment.yaml file. You'll primarily customize the image and resource requests.
# Simplified kubernetes/deployment-web.yaml template
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
spec:
replicas: 3 # <--- CUSTOMIZE: How many instances (pods) you want
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp-container
image: christianlempa/boilerplate-app:latest # <--- CUSTOMIZE: Your actual Docker image
ports:
- containerPort: 8080
resources:
limits:
memory: "256Mi" # <--- CUSTOMIZE: Set appropriate resource limits
Ansible templates (Playbooks) automate server configuration. A simple template might be for installing a package.
# Simplified ansible/playbook-install.yaml template
---
- name: Setup Web Server
hosts: web_servers # <--- CUSTOMIZE: Define which servers this applies to (via hosts file)
become: true # Run commands with elevated privileges
tasks:
- name: Ensure NGINX is installed
ansible.builtin.apt:
name: nginx
state: present
update_cache: yes
when: ansible_os_family == "Debian" # Only run on Debian/Ubuntu systems
- name: Start NGINX service
ansible.builtin.service:
name: nginx
state: started
enabled: yes
Customization
If you needed to install Apache instead of NGINX, you'd change the name field in the first task from nginx to apache2. You might also change the hosts variable to target your database servers instead and change the tasks to install PostgreSQL.