Created
March 25, 2024 07:36
-
-
Save uurtech/459a9e284ef747c153602c5fd8788554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- '*' | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
# Install and configure AWS CLI | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: your-aws-region | |
# Install kubectl | |
- name: Install kubectl | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y apt-transport-https | |
sudo apt-get install -y curl | |
sudo apt-get install -y gnupg | |
sudo apt-get install -y lsb-release | |
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - | |
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list | |
sudo apt-get update | |
sudo apt-get install -y kubectl | |
# Authenticate with AWS EKS | |
- name: Configure kubectl for EKS | |
run: aws eks --region your-aws-region update-kubeconfig --name your-eks-cluster-name | |
# Install Helm | |
- name: Install Helm | |
run: | | |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | |
chmod 700 get_helm.sh | |
./get_helm.sh | |
# Install Nginx Ingress Controller | |
- name: Install Nginx Ingress Controller | |
run: | | |
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx | |
helm repo update | |
helm install nginx-ingress ingress-nginx/ingress-nginx \ | |
--namespace nginx-ingress \ | |
--set controller.replicaCount=2 \ | |
--set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \ | |
--set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \ | |
--set controller.service.type=LoadBalancer | |
# Create Node.js Deployment YAML | |
- name: Create Node.js Deployment YAML | |
id: create_nodejs_deployment_yaml | |
run: | | |
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) | |
cat <<EOF > nodejs-app-deployment.yaml | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: nodejs-app | |
labels: | |
app: nodejs-app | |
spec: | |
replicas: 3 | |
selector: | |
matchLabels: | |
app: nodejs-app | |
template: | |
metadata: | |
labels: | |
app: nodejs-app | |
spec: | |
containers: | |
- name: nodejs-app | |
image: your-nodejs-image:${BRANCH_NAME} | |
ports: | |
- containerPort: 3000 | |
EOF | |
shell: bash | |
# Deploy Node.js Application | |
- name: Deploy Node.js Application | |
run: kubectl apply -f nodejs-app-deployment.yaml | |
# Update Route 53 DNS Record | |
- name: Update Route 53 DNS Record | |
run: | | |
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) | |
aws route53 change-resource-record-sets --hosted-zone-id your-hosted-zone-id --change-batch '{ | |
"Changes": [ | |
{ | |
"Action": "UPSERT", | |
"ResourceRecordSet": { | |
"Name": "${BRANCH_NAME}.yourdomain.com", | |
"Type": "A", | |
"TTL": 300, | |
"ResourceRecords": [ | |
{ | |
"Value": "your-nginx-load-balancer-dns-name" | |
} | |
] | |
} | |
} | |
] | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment