Mini Automation Project
beginnerautomationbashdeploymentnginx
Create a simple deployment automation script for static websites
← Back to BeginnerLearning Objectives
- Understand basic deployment automation concepts
- Learn to create reliable and idempotent shell scripts
- Develop skills in service management
- Implement basic deployment verification
- Create maintainable automation scripts
Requirements
You are required to write a Bash script deploy-site.sh that automates the deployment of a static website:
- Script Structure
- Well-organized script with clear comments
- Usage instructions displayed with
-hor--help - Accept a parameter for the source directory
- Basic error handling throughout
- Environment Setup
- Check if Nginx is installed; install if missing
- Verify the web root directory exists
- Create it if necessary
- Deployment Process
- Copy HTML/CSS/JS files from source directory to web root
- Set appropriate permissions for web files
- Create a simple backup of any existing files before overwriting
- Handle common errors: missing source directory, permission issues
- Service Management
- Test Nginx configuration before restarting (
nginx -t) - Restart the Nginx service
- Handle service restart failures gracefully
- Test Nginx configuration before restarting (
- Verification
- Send an HTTP GET request to localhost
- Check for a 200 status code response
- Display a clear success or failure message
Stretch Goals
- Add timestamp logging for each deployment step
- Implement simple version numbering for deployments
- Create a rollback function to restore the previous version
Deliverables
deploy-site.shimplementing all required steps- Sample HTML files for testing
- Documentation covering: usage, what each part does, and troubleshooting tips
References
- Bash Scripting Tutorial
- Nginx Beginner's Guide
- Linux File Permissions Explained
- curl Command Examples
- HTTP Status Codes - MDN
Once you complete this task you will be able to automate basic website deployments using shell scripting - the same principle behind every CI/CD pipeline you will build in the Intermediate level.
Submit Your Solution
Completed this project? Share your solution with the community!
- Push your code to a GitHub repository
- Open an issue on our GitHub repo with your solution link
- Share on X with the hashtag #DevOpsDiary
