Spaces:
Running
Running
Download scripts/deploy_ecr.sh from MonteeqOrg/backend: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/spaces/MonteeqOrg/backend/resolve/main/scripts/deploy_ecr.sh
- Command line
-
hf download hf://spaces/MonteeqOrg/backend/scripts/deploy_ecr.sh
-
curl -L -o deploy_ecr.sh https://huggingface.co/spaces/MonteeqOrg/backend/resolve/main/scripts/deploy_ecr.sh
2.34 kB
| # Script to build and push backend image to Amazon ECR | |
| # Exit immediately if a command exits with a non-zero status | |
| set -e | |
| # Configuration variables (Modify these to match your AWS environment) | |
| AWS_REGION="${AWS_REGION:-us-west-2}" | |
| AWS_ACCOUNT_ID="${AWS_ACCOUNT_ID:-037302670720}" | |
| REPO_NAME="${REPO_NAME:-monteeq}" | |
| IMAGE_TAG="${IMAGE_TAG:-latest}" | |
| ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" | |
| echo "------------------------------------------------" | |
| echo "π Preparing ECR deployment for ${REPO_NAME}" | |
| echo "π Region: ${AWS_REGION}" | |
| echo "π ECR URL: ${ECR_URL}" | |
| echo "------------------------------------------------" | |
| # Resolve aws CLI binary path | |
| AWS_CLI="aws" | |
| if ! command -v aws &> /dev/null; then | |
| if [ -f "$HOME/bin/aws" ]; then | |
| AWS_CLI="$HOME/bin/aws" | |
| else | |
| echo "β Error: aws CLI command not found. Please install it or add it to PATH." | |
| exit 1 | |
| fi | |
| fi | |
| # Detect if docker requires sudo | |
| DOCKER_CMD="docker" | |
| if ! docker info &>/dev/null; then | |
| DOCKER_CMD="sudo docker" | |
| echo "β οΈ Note: Current user lacks Docker socket permissions. Using 'sudo docker' for container operations." | |
| fi | |
| # Step 1: Login to ECR | |
| echo "π Logging into Amazon ECR..." | |
| ${AWS_CLI} ecr get-login-password --region "${AWS_REGION}" | ${DOCKER_CMD} login --username AWS --password-stdin "${ECR_URL}" | |
| # Step 2: Create ECR repository if it doesn't exist | |
| echo "π¦ Checking/creating repository ${REPO_NAME} in ECR..." | |
| ${AWS_CLI} ecr describe-repositories --repository-names "${REPO_NAME}" --region "${AWS_REGION}" >/dev/null 2>&1 || \ | |
| ${AWS_CLI} ecr create-repository --repository-name "${REPO_NAME}" --region "${AWS_REGION}" | |
| # Step 3: Build Docker Image | |
| echo "ποΈ Building Docker image..." | |
| # Run build from backend directory | |
| cd "$(dirname "$0")/.." | |
| ${DOCKER_CMD} build -t "${REPO_NAME}" . | |
| # Step 4: Tag Image | |
| echo "π·οΈ Tagging image..." | |
| ${DOCKER_CMD} tag "${REPO_NAME}:latest" "${ECR_URL}/${REPO_NAME}:${IMAGE_TAG}" | |
| # Step 5: Push Image to ECR | |
| echo "π Pushing image to ECR..." | |
| ${DOCKER_CMD} push "${ECR_URL}/${REPO_NAME}:${IMAGE_TAG}" | |
| echo "------------------------------------------------" | |
| echo "β Deployment image successfully pushed to ECR!" | |
| echo "π³ Image URI: ${ECR_URL}/${REPO_NAME}:${IMAGE_TAG}" | |
| echo "------------------------------------------------" | |