#!/bin/bash # Check if AWS CLI and zip are installed if ! command -v aws &> /dev/null; then echo "AWS CLI not found. Please install and configure the AWS CLI." exit 1 fi if ! command -v zip &> /dev/null; then echo "zip not found. Please install zip utility." exit 1 fi BUCKET_NAME=$S3_BUCKET_NAME ZIP_FILE="app-artifacts.zip" TMP_DIR="tmp/app-artifacts" # Create a temporary directory rm -rf "$TMP_DIR" mkdir -p "$TMP_DIR" # Copy the Dockerfile and the required files into the temporary directory cp Dockerfile "$TMP_DIR/" cp pipeline.py "$TMP_DIR/" cp inference.py "$TMP_DIR/" cp app.py "$TMP_DIR/" cp serve.sh "$TMP_DIR/" # Save the current directory CURRENT_DIR=$(pwd) # Change to the temporary directory cd "$TMP_DIR" # Create a zip file of the artifacts echo "Creating zip file $ZIP_FILE..." zip -r "$ZIP_FILE" . # Move the zip file to the original directory mv "$ZIP_FILE" "$CURRENT_DIR" # Change back to the original directory cd "$CURRENT_DIR" # Upload the zip file to the specified S3 bucket echo "Uploading $ZIP_FILE to s3://$BUCKET_NAME/..." aws s3 cp "$ZIP_FILE" "s3://$BUCKET_NAME/$ZIP_FILE" if [ $? -ne 0 ]; then echo "Failed to upload $ZIP_FILE to s3://$BUCKET_NAME/" exit 1 fi echo "App artifacts uploaded successfully to s3://$BUCKET_NAME/$ZIP_FILE" # Clean up rm -rf "$TMP_DIR" rm "$ZIP_FILE" echo "Temporary files cleaned up."