CI/CD Pipeline from Scratch: Ship Code to Production in Under a Week

TL;DR: A CI/CD pipeline automates your entire software delivery process from code commit to production deployment. This guide shows you how to build one using GitHub Actions, Docker, and AWS in under a week.

Shipping code manually is slow, error-prone, and does not scale. If your team is still using FTP uploads, running scripts by hand, or spending hours on deployment day, a CI/CD pipeline will change how you work permanently.

What Is CI/CD and Why It Matters

CI (Continuous Integration) means every code change is automatically tested. If a developer pushes broken code, the pipeline fails immediately before it reaches production.

CD (Continuous Delivery) means tested code is automatically packaged and deployed to staging, and to production with a single click.

The business impact:
  • Deployment time: from hours to minutes
  • Deployment frequency: from monthly to daily
  • Failed deployments: reduced by 60-80%
  • Recovery time when something breaks: minutes, not hours

The Stack We Use

  • GitHub Actions – free CI/CD runner built into GitHub
  • Docker – containerize the application for consistent environments
  • Amazon ECR – store Docker images
  • Amazon ECS Fargate – run containers without managing servers

Day 1-2: Containerize Your Application

Start by creating a Dockerfile in your project root. Use a multi-stage build to keep the final image small:

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
EXPOSE 3000
CMD ["node", "dist/index.js"]

Day 3-4: GitHub Actions Workflow

Create .github/workflows/deploy.yml. The workflow has two jobs: test (runs on every push) and deploy (runs only on merges to main):

name: Build and Deploy
on:
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test
  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build and push to ECR
        run: |
          docker build -t $ECR_URI:$GITHUB_SHA .
          docker push $ECR_URI:$GITHUB_SHA
      - name: Deploy to ECS
        run: aws ecs update-service --cluster prod --service myapp --force-new-deployment

Day 5-7: Staging Gate and Monitoring

Add a staging environment as a mandatory gate before production. Use GitHub Environments with required approvers. Configure ECS health checks so failed deployments roll back automatically. Add Slack notifications so your team knows immediately when a build passes or fails.

What You Have at the End of Week 1

Automated Testing

Every push triggers tests. Broken code never reaches production.

🐳
Docker Containers

Consistent environments from dev to production. No more works-on-my-machine.

🚀
One-Click Deploys

Merge a PR and code ships to production in under 5 minutes.

Want This Set Up for Your Team?

CloudShift360 builds and hands off production-grade CI/CD pipelines in 5-7 days. Your team ships faster on day 1 of the handoff.

Get Your Pipeline Built
FREE CONSULTATION

🚀 Need Help With Your Cloud Infrastructure?

We have optimized AWS, Azure, and GCP environments for 88+ enterprise clients reducing costs by an average of 35% and achieving 99.9% uptime SLA. Let us audit your setup for free.

  • ✓ Free 30-minute cloud audit
  • ✓ Written action plan, no obligation
  • ✓ Available this week
📅 Book Free Audit ✉ Email Directly

Response within 24 hours

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *