deploylify
v1.0.1
Published
A CLI tool for automated CI/CD deployments to AWS EC2 via GitHub Actions
Downloads
2
Maintainers
Readme
Deploylify
A CLI tool that helps developers to set up automated deployment of services to AWS EC2 instances via GitHub Actions.
Features
- Simple configuration file for deployment settings
- Automatic GitHub Actions workflow generation
- Support for Node.js and Docker projects
- Secure deployment using SSH keys
- Zero-config deployment process
- Secure environment variable handling via GitHub secrets
Installation
npm install -g deploylifyUsage
- Initialize a new configuration:
deploylify initThis will create a deploy.json file with your deployment settings.
- Generate the GitHub Actions workflow:
deploylify generateThis creates the .github/workflows/deploy.yml file that handles the automated deployment.
Add required secrets to your GitHub repository:
Required secrets:
EC2_HOST: Your EC2 instance's public DNS or IPEC2_USER: SSH user (usually 'ubuntu')EC2_KEY: Base64-encoded SSH private key (how to create and encode SSH keys)# Generate SSH key ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ./deploy_key # Base64 encode the private key (the content will be your EC2_KEY secret) cat deploy_key | base64 # Copy the public key to your EC2 instance's authorized_keys cat deploy_key.pub >> ~/.ssh/authorized_keysEC2_DEPLOY_PATH: Path on EC2 where code will be deployed- Each variable listed in your config's
privatearray
Push your code to trigger the deployment:
git add .
git commit -m "Setup CI/CD with deploylify"
git pushPrerequisites
Before using deploylify, ensure you have:
An AWS EC2 instance running:
Required software on your EC2 instance:
- Git:
sudo apt-get update && sudo apt-get install git - For Node.js projects:
- For Docker projects:
- Git:
GitHub repository with:
Configuration
The cicd.config.json file supports the following options:
{
"type": "node", // "node" or "docker"
"build": "npm run build", // Optional build command
"test": "npm test", // Optional test command
"deployBranch": "main", // Branch that triggers deployment
"ec2": {
"host": "ec2-xx-xx.amazonaws.com", // Used for local testing
"user": "ubuntu", // Used for local testing
"deployPath": "/home/ubuntu/app" // Where to deploy on EC2
},
"env": { // Optional environment configuration
"general": { // Non-sensitive environment variables
"NODE_ENV": "production",
"PORT": "3000",
"LOG_LEVEL": "info"
},
"private": [ // Names of sensitive environment variables
"DATABASE_URL", // Each name must match a GitHub secret
"API_KEY",
"JWT_SECRET"
]
}
}Note: SSH authentication is handled entirely through the EC2_KEY GitHub secret, not through local SSH keys. This ensures better security and easier setup across different development machines.
Environment Variables
deploylify supports two types of environment variables:
1. General Environment Variables
These are non-sensitive variables that can be directly specified in your cicd.config.json:
"env": {
"general": {
"NODE_ENV": "production",
"PORT": "3000",
"LOG_LEVEL": "info"
}
}2. Private Environment Variables
These are sensitive variables that are stored securely as individual GitHub secrets:
- List the private variable names in your config:
"env": {
"private": ["DATABASE_URL", "API_KEY", "JWT_SECRET"]
}- Add each variable as a separate GitHub secret:
- Go to
Settings > Secrets and variables > Actionsin your repository - For each variable in your
privatearray, create a secret with the exact same name - Detailed guide on managing repository secrets
- Go to
Docker Support
For Docker projects ("type": "docker"), ensure you have:
A valid
Dockerfilein your project rootDocker installed on your EC2 instance:
# Install Docker on Ubuntu curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh # Add your user to docker group (requires re-login) sudo usermod -aG docker $USERProper permissions to run Docker commands:
Security Best Practices
EC2 Security:
- AWS security best practices
- Use security groups to limit access
- Keep your system updated
- Use strong SSH keys
GitHub Actions Security:
- Security hardening for GitHub Actions
- Never print secrets in logs
- Use minimum required permissions
- Regularly rotate secrets
Docker Security:
- Docker security best practices
- Keep base images updated
- Use multi-stage builds
- Run containers with least privilege
Troubleshooting
Common issues and solutions:
SSH Connection Issues:
- Troubleshoot EC2 SSH connections
- Verify security group settings
- Check SSH key permissions
Docker Issues:
- Docker troubleshooting guide
- Check Docker service status
- Verify user permissions
GitHub Actions Issues:
- Troubleshooting GitHub Actions
- Check workflow run logs
- Verify secret names and values
License
MIT
