Skip to content

Deepak-coder80/ecr-deploy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ECR Deploy Tool πŸš€

A powerful, cross-platform CLI tool that automates AWS ECR repository creation and Docker image deployment. Built with Go for speed, reliability, and ease of use across development teams.

Go Version License Platform

✨ Features

  • πŸ”„ Automated ECR repository creation - Creates repositories if they don't exist
  • 🐳 Docker integration - Handles authentication, building, and pushing
  • πŸ‘€ AWS profile support - Use multiple AWS profiles seamlessly
  • 🌍 Cross-platform - Works on Linux, Windows, and macOS
  • 🏷️ Flexible tagging - Custom tags or default to 'latest'
  • πŸ’» Interactive mode - User-friendly prompts when needed
  • πŸ“¦ Easy distribution - Pre-built binaries and packages
  • ⚑ Fast deployment - Optimized workflow for quick deployments

🎯 Quick Start

One-Line Installation

# Linux/macOS
curl -sSL https://raw.githubusercontent.com/Deepak-coder80/ecr-deploy/main/install.sh | bash

# Windows (PowerShell as Administrator)
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/Deepak-coder80/ecr-deploy/main/install.ps1" | Invoke-Expression

Manual Installation

Linux (Ubuntu/Debian)

wget https://github.com/Deepak-coder80/ecr-deploy/releases/latest/download/ecr-deploy-1.0.0-linux-amd64.deb
sudo dpkg -i ecr-deploy-1.0.0-linux-amd64.deb

Linux (Other Distributions)

wget https://github.com/Deepak-coder80/ecr-deploy/releases/latest/download/ecr-deploy-1.0.0-linux-amd64.tar.gz
tar -xzf ecr-deploy-1.0.0-linux-amd64.tar.gz
sudo cp usr/local/bin/ecr-deploy /usr/local/bin/

Windows

  1. Download ecr-deploy-1.0.0-windows-amd64.zip
  2. Extract the zip file
  3. Run install.bat as Administrator
  4. Restart your terminal

macOS

# Intel Macs
wget https://github.com/Deepak-coder80/ecr-deploy/releases/latest/download/ecr-deploy-1.0.0-darwin-amd64.tar.gz
tar -xzf ecr-deploy-1.0.0-darwin-amd64.tar.gz
cd ecr-deploy-1.0.0-darwin-amd64 && ./install.sh

# Apple Silicon Macs
wget https://github.com/Deepak-coder80/ecr-deploy/releases/latest/download/ecr-deploy-1.0.0-darwin-arm64.tar.gz
tar -xzf ecr-deploy-1.0.0-darwin-arm64.tar.gz
cd ecr-deploy-1.0.0-darwin-arm64 && ./install.sh

πŸš€ Usage

Basic Examples

# Simple deployment to ECR
ecr-deploy --repo my-web-app

# With specific AWS profile
ecr-deploy --repo my-api --profile production

# Custom region and tag
ecr-deploy --repo my-service --region eu-west-1 --tag v2.1.0

# From specific directory
ecr-deploy --repo backend-service --path ./services/backend/

# Interactive mode (prompts for repository name)
ecr-deploy

Command Line Options

Usage:
  ecr-deploy [flags]

Flags:
  -h, --help              help for ecr-deploy
  -l, --list-profiles     List available AWS profiles
  -p, --path string       Path to Dockerfile directory (default: current directory)
      --profile string    AWS profile to use (default: default profile)
  -r, --region string     AWS region (default: "us-east-1")
  -n, --repo string       ECR repository name
  -t, --tag string        Docker image tag (default: "latest")

Commands:
  examples    Show usage examples
  version     Print version information

Advanced Usage

List Available AWS Profiles

ecr-deploy --list-profiles

Deploy with Environment-Specific Configuration

# Development
ecr-deploy --repo my-app --profile dev --region us-west-2 --tag dev-$(git rev-parse --short HEAD)

# Staging
ecr-deploy --repo my-app --profile staging --region us-east-1 --tag staging-v1.2.3

# Production
ecr-deploy --repo my-app --profile prod --region us-east-1 --tag v1.2.3

πŸ“‹ Prerequisites

Required Tools

  • AWS CLI - Configured with appropriate credentials
  • Docker - Running and accessible
  • Git (optional) - For version tagging

AWS Permissions

Your AWS user/role needs the following ECR permissions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ecr:GetAuthorizationToken",
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "ecr:PutImage",
                "ecr:InitiateLayerUpload",
                "ecr:UploadLayerPart",
                "ecr:CompleteLayerUpload",
                "ecr:CreateRepository",
                "ecr:DescribeRepositories"
            ],
            "Resource": "*"
        }
    ]
}

AWS Profile Setup

# Configure default profile
aws configure

# Configure additional profiles
aws configure --profile production
aws configure --profile staging

πŸ”„ Workflow Integration

GitHub Actions

name: Deploy to ECR
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v2
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1

      - name: Install ECR Deploy Tool
        run: |
          wget https://github.com/Deepak-coder80/ecr-deploy/releases/latest/download/ecr-deploy-1.0.0-linux-amd64.tar.gz
          tar -xzf ecr-deploy-1.0.0-linux-amd64.tar.gz
          sudo cp usr/local/bin/ecr-deploy /usr/local/bin/

      - name: Deploy to ECR
        run: |
          IMAGE_URI=$(ecr-deploy --repo ${{ github.event.repository.name }} --tag ${{ github.sha }})
          echo "IMAGE_URI=$IMAGE_URI" >> $GITHUB_ENV

      - name: Update ECS service
        run: |
          # Use $IMAGE_URI in your deployment scripts
          echo "Deploying $IMAGE_URI to ECS..."

Jenkins Pipeline

pipeline {
    agent any

    environment {
        AWS_REGION = 'us-east-1'
        ECR_REPO = "${env.JOB_NAME}"
    }

    stages {
        stage('Build and Deploy to ECR') {
            steps {
                script {
                    // Install ECR Deploy Tool
                    sh '''
                        wget -q https://github.com/Deepak-coder80/ecr-deploy/releases/latest/download/ecr-deploy-1.0.0-linux-amd64.tar.gz
                        tar -xzf ecr-deploy-1.0.0-linux-amd64.tar.gz
                        sudo cp usr/local/bin/ecr-deploy /usr/local/bin/ || cp usr/local/bin/ecr-deploy ./
                    '''

                    // Deploy to ECR
                    def imageUri = sh(
                        script: "./ecr-deploy --repo ${ECR_REPO} --region ${AWS_REGION} --tag ${env.BUILD_NUMBER}",
                        returnStdout: true
                    ).trim()

                    env.IMAGE_URI = imageUri.split('\n').last().split(': ')[1]
                    echo "Deployed image: ${env.IMAGE_URI}"
                }
            }
        }
    }
}

GitLab CI/CD

deploy_to_ecr:
  stage: deploy
  image: docker:latest
  services:
    - docker:dind
  before_script:
    - apk add --no-cache curl
    - curl -sSL https://raw.githubusercontent.com/Deepak-coder80/ecr-deploy/main/install.sh | sh
  script:
    - ecr-deploy --repo $CI_PROJECT_NAME --tag $CI_COMMIT_SHA
  only:
    - main

πŸ› οΈ Development Setup

Prerequisites for Development

  • Go 1.21 or higher
  • Make (optional, for using Makefile)
  • Git

Quick Development Setup

# Clone the repository
git clone https://github.com/Deepak-coder80/ecr-deploy.git
cd ecr-deploy

# Option 1: Use automated setup
./quick-setup.sh

# Option 2: Manual setup
go mod download
go mod tidy
make build

Development Commands

# Run in development mode
make dev

# Build for current platform
make build

# Build for all platforms
make build-all

# Create distribution packages
make dist

# Run tests
make test

# Format and lint code
make lint

# Clean build artifacts
make clean

# Install locally for testing
make install

Project Structure

ecr-deploy/
β”œβ”€β”€ main.go              # Main application
β”œβ”€β”€ go.mod               # Go module dependencies
β”œβ”€β”€ go.sum               # Dependency lock file
β”œβ”€β”€ Makefile             # Build automation
β”œβ”€β”€ README.md            # This file
β”œβ”€β”€ LICENSE              # License file
β”œβ”€β”€ .gitignore           # Git ignore rules
β”œβ”€β”€ build/               # Built binaries (gitignored)
β”œβ”€β”€ dist/                # Distribution packages (gitignored)
└── docs/                # Additional documentation
    β”œβ”€β”€ CONTRIBUTING.md  # Contribution guidelines
    └── DEPLOYMENT.md    # Deployment guide

πŸ“Š What the Tool Does

  1. πŸ” Repository Check - Verifies if ECR repository exists
  2. πŸ“¦ Repository Creation - Creates repository if it doesn't exist
  3. πŸ” Authentication - Handles Docker login to ECR
  4. πŸ—οΈ Image Building - Builds Docker image with proper ECR URI
  5. πŸ“€ Image Pushing - Pushes image to ECR with specified tag
  6. πŸ“‹ Output - Returns complete image URI for deployment use

Sample Output

🌟 Starting ECR deployment for repository: my-web-app
πŸ“ Region: us-east-1
πŸ‘€ AWS Profile: production
πŸ“ Dockerfile path: .
🏷️  Tag: v1.2.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ”§ Initializing AWS session (Region: us-east-1, Profile: production)
βœ… AWS Authentication successful! Account: 123456789012
πŸ” Checking if ECR repository 'my-web-app' exists...
πŸ“¦ Creating ECR repository 'my-web-app'...
βœ… Repository 'my-web-app' created successfully!
πŸ”‘ Authenticating Docker with ECR...
πŸš€ Executing: bash -c aws ecr get-login-password --region us-east-1 --profile production | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-east-1.amazonaws.com
πŸ—οΈ  Building Docker image: 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-web-app:v1.2.0
πŸš€ Executing: docker build -t 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-web-app:v1.2.0 .
πŸ“€ Pushing image to ECR: 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-web-app:v1.2.0
πŸš€ Executing: docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-web-app:v1.2.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
πŸŽ‰ Deployment completed successfully!
⏱️  Total time: 45s
πŸ“‹ Image URI: 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-web-app:v1.2.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

πŸ› Troubleshooting

Common Issues and Solutions

AWS Authentication Errors

# Check AWS configuration
aws configure list
aws sts get-caller-identity

# Verify profile exists
ecr-deploy --list-profiles

# Test with specific profile
aws sts get-caller-identity --profile your-profile-name

Docker Issues

# Check Docker status
docker info

# Start Docker (Linux)
sudo systemctl start docker

# Check Docker permissions (Linux)
sudo usermod -aG docker $USER
# Log out and back in

Build Errors

# Clean and rebuild
make clean
go mod tidy
make build

# Update dependencies
go get -u ./...
go mod tidy

Permission Errors

# Linux: Add user to docker group
sudo usermod -aG docker $USER

# AWS: Check ECR permissions
aws ecr describe-repositories --region us-east-1

Getting Help

# Show help
ecr-deploy --help

# Show examples
ecr-deploy examples

# Check version
ecr-deploy version

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Contribution Steps

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Run tests: make test
  5. Submit a pull request

Development Guidelines

  • Follow Go best practices
  • Add tests for new features
  • Update documentation
  • Use conventional commit messages

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

πŸš€ What's Next?

  • Configuration file support (.ecr-deploy.yaml)
  • Multi-tag deployment in single command
  • Batch repository operations
  • ECS/EKS integration helpers
  • Docker Compose support
  • Vulnerability scanning integration

Made with ❀️ by the DevOps Team

⭐ Star this repo if it helped you! ⭐

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors