init strucure #1
This file contains 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: Deploy AWS Pub/Sub Reference App Resources | |
# on: | |
# push: | |
# branches: | |
# - main | |
jobs: | |
setup-diagrid-project: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@main | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
# Install Diagrid CLI | |
- name: Install Diagrid CLI | |
run: | | |
# Download the latest Diagrid CLI from GitHub or direct source | |
curl -o- https://downloads.diagrid.io/cli/install.sh | bash | |
sudo mv ./diagrid /usr/local/bin | |
# Log into Diagrid | |
- name: Log Into Diagrid | |
run: | | |
diagrid login --api-key ${{secrets.DIAGRID_API_KEY}} | |
# Diagrid Version | |
- name: Diagrid Version | |
run: | | |
diagrid version | |
- name: Create Diagrid Project | |
run: | | |
diagrid project create ${{secrets.DIAGRID_PROJECT}} | |
# Assign Diagrid Project | |
- name: Assign Diagrid Project | |
run: | | |
diagrid project use ${{secrets.DIAGRID_PROJECT}} --api-key ${{secrets.DIAGRID_API_KEY}} | |
- name: Create Diagrid APP IDS | |
run: | | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
diagrid appid create -p ${{secrets.DIAGRID_PROJECT}} $service_name | |
sleep 10 | |
done | |
- name: Creating Dynamodb Tables | |
run: | | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
echo "DynamoDB table name : ${service_name}-table" | |
table_name="${service_name}-table" | |
aws dynamodb create-table --table-name $table_name --attribute-definitions AttributeName=key,AttributeType=S --key-schema AttributeName=key,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 | |
done | |
- name: Check App Status | |
run: | | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
diagrid appid get $service_name -p ${{secrets.DIAGRID_PROJECT}} | |
done | |
- name: Create Pub/Sub Component | |
run: | | |
diagrid component create aws-pubsub --type pubsub.aws.snssqs --metadata accessKey=${{ secrets.AWS_ACCESS_KEY_ID }} --metadata secretKey=${{ secrets.AWS_SECRET_ACCESS_KEY }} --metadata awsRegion=${{ secrets.AWS_DEFAULT_REGION }} --project ${{ secrets.DIAGRID_PROJECT }} | |
- name: Create State Component | |
run: | | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
table_name="${service_name}-table" | |
diagrid component create $table_name --type state.aws.dynamodb --metadata accessKey=${{ secrets.AWS_ACCESS_KEY_ID }} --metadata secretKey=${{ secrets.AWS_SECRET_ACCESS_KEY }} --metadata awsRegion=${{ secrets.AWS_DEFAULT_REGION }} --metadata table=$table_name --scopes $service_name --project ${{secrets.DIAGRID_PROJECT}} | |
sleep 30 | |
done | |
- name: Check App Status | |
run: | | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
diagrid appid get $service_name -p ${{secrets.DIAGRID_PROJECT}} | |
done | |
- name: Creating subscriptions | |
run: | | |
cat ./group_subs.yaml | |
diagrid subscriptions apply --wait --file ./group_subs.yaml | |
upload-to-ecs: | |
runs-on: ubuntu-latest | |
needs: setup-diagrid-project | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v4 | |
- name: Install the CDK Dependency | |
run: | | |
npm install -g aws-cdk | |
# Install Diagrid CLI | |
- name: Install Diagrid CLI | |
run: | | |
# Download the latest Diagrid CLI from GitHub or direct source | |
curl -o- https://downloads.diagrid.io/cli/install.sh | bash | |
sudo mv ./diagrid /usr/local/bin | |
# Log into diagrid | |
- name: Log Into Diagrid | |
run: | | |
diagrid login --api-key ${{secrets.DIAGRID_API_KEY}} | |
# Diagrid Version | |
- name: Diagrid Version | |
run: | | |
diagrid version | |
# Assign Diagrid Project | |
- name: Assign Diagrid Project | |
run: | | |
diagrid project use ${{secrets.DIAGRID_PROJECT}} --api-key ${{secrets.DIAGRID_API_KEY}} | |
#Retrieve apiTokens for all project services | |
- name: Retrieve apiToken for each service | |
run: | | |
# Initialize an empty array for the final output | |
json_array="[]" | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
# Fetch the Diagrid app identity information in JSON format | |
# Error handling if diagrid appid get command fails | |
if ! diagrid_output=$(diagrid appid get $service_name -o json 2>/dev/null); then | |
echo "Error: Failed to retrieve Diagrid app identity for $service_name" | |
continue # Skip this service and move to the next one | |
fi | |
# Extract the apiToken using jq from the Diagrid output | |
api_token=$(echo $diagrid_output | jq -r '.status.apiToken') | |
# Check if apiToken is null or empty | |
if [ -z "$api_token" ] || [ "$api_token" == "null" ]; then | |
echo "Error: No valid apiToken found for $service_name" | |
continue # Skip this service and move to the next one | |
fi | |
echo "API Token for $service_name: $api_token" | |
# Create a JSON object with the service and apiToken | |
json_object=$(jq -n --arg service "$service_name" --arg apiToken "$api_token" \ | |
'{service: $service, apiToken: $apiToken}') | |
# Add the JSON object to the array | |
json_array=$(echo $json_array | jq --argjson obj "$json_object" '. += [$obj]') | |
done | |
# Save the JSON array to a file | |
echo $json_array | jq . > cdk-infra/service_tokens.json | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "service_tokens<<$EOF" >> $GITHUB_OUTPUT | |
echo "$json_array" >> $GITHUB_OUTPUT | |
echo "$EOF" >> $GITHUB_OUTPUT | |
cat cdk-infra/service_tokens.json | |
- name: Upload service_tokens.json | |
uses: actions/upload-artifact@v4 | |
with: | |
name: service_tokens | |
path: cdk-infra/service_tokens.json | |
- name: Install other dependencies | |
run: | | |
npm install | |
working-directory: ./cdk-infra | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@main | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
# Download the service_tokens.json artifact | |
- name: Download service_tokens.json | |
uses: actions/download-artifact@v4 | |
with: | |
name: service_tokens | |
path: cdk-infra/ | |
- name: Synthesize CDK Stack | |
run: | | |
json_array=$(cat service_tokens.json) | |
# Save the JSON array to a file | |
echo $json_array | jq . > tokens.json | |
echo "Final JSON Array:" | |
cat tokens.json | |
cdk synth -c configfile=tokens.json | |
working-directory: ./cdk-infra | |
- name: Bootstrap CDK Stack | |
run: | | |
json_array=$(cat service_tokens.json) | |
# Save the JSON array to a file | |
echo $json_array | jq . > service_tokens.json | |
echo "Final JSON Array:" | |
cat service_tokens.json | |
cdk bootstrap -c configfile=service_tokens.json | |
working-directory: ./cdk-infra | |
- name: Deploy repoStackName to AWS | |
run: | | |
json_array=$(cat service_tokens.json) | |
# Save the JSON array to a file | |
echo $json_array | jq . > service_tokens.json | |
echo "Final JSON Array:" | |
cat service_tokens.json | |
cdk deploy repoStackName --require-approval=never -c configfile=service_tokens.json | |
working-directory: ./cdk-infra | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build and push Docker images | |
run: | | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
ecr_repo="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{secrets.AWS_DEFAULT_REGION}}.amazonaws.com/$service_name" | |
echo "Building Docker image for $service_name" | |
docker build -t "$ecr_repo:latest" "$service" | |
echo "Pushing Docker image to ECR for $service_name" | |
docker push "$ecr_repo:latest" | |
done | |
- name: Deploy CdkInfraStack to AWS | |
run: | | |
json_array=$(cat service_tokens.json) | |
# Save the JSON array to a file | |
echo $json_array | jq . > service_tokens.json | |
echo "Final JSON Array:" | |
cat service_tokens.json | |
cdk deploy CdkInfraStack --require-approval=never -c configfile=service_tokens.json | |
working-directory: ./cdk-infra | |
- name: Update Cluster to get the most recent image | |
run: | | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
aws ecs update-service --cluster GROUP-CHAT-cluster --service $service_name --force-new-deployment | |
done | |
- name: Retrieving the DNS for the services and updating the appIDs | |
run: | | |
# Initialize an empty array | |
json_array="[]" | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
alb_name=$(basename "$service")-ALB | |
alb_dns=$(aws elbv2 describe-load-balancers --names $alb_name --query "LoadBalancers[0].DNSName" --output text) | |
echo "ALB DNS: $alb_dns" | |
echo "Service name is : $service_name" | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "alb_dns<<$EOF" >> $GITHUB_OUTPUT | |
echo "$alb_dns" >> $GITHUB_OUTPUT | |
echo "$EOF" >> $GITHUB_OUTPUT | |
# Create a JSON object with the service and ALB DNS | |
json_object=$(jq -n --arg service "$service_name" --arg alb_dns "$alb_dns" \ | |
'{service: $service, url: $alb_dns}') | |
# Add the JSON object to the array | |
json_array=$(echo $json_array | jq --argjson obj "$json_object" '. += [$obj]') | |
done | |
# Save the JSON array to a file | |
echo $json_array | jq . > alb_services.json | |
# Output the JSON array | |
echo "JSON Array:" | |
cat alb_services.json | |
# Loop through the JSON array and extract values | |
- name: | |
Loop through the JSON array and extract ALB DNS and Service name,update | |
Catalyst API public Endpoint for each service | |
run: | | |
# Read the JSON array from the file | |
json_array=$(cat alb_services.json) | |
# Loop through the array and extract service and alb_dns | |
for row in $(echo "${json_array}" | jq -r '.[] | @base64'); do | |
_jq() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
service=$(_jq '.service') | |
alb_dns=$(_jq '.url') | |
diagrid appid update $service --app-endpoint "http://$alb_dns" -w --api-key ${{secrets.DIAGRID_API_KEY}} | |
echo "Service: $service, ALB DNS: $alb_dns" | |
done | |
# Save the JSON array to a file | |
echo $json_array | jq . > cdk-graphql-stack/alb_services.json | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "alb_services<<$EOF" >> $GITHUB_OUTPUT | |
echo "$json_array" >> $GITHUB_OUTPUT | |
echo "$EOF" >> $GITHUB_OUTPUT | |
cat cdk-graphql-stack/alb_services.json | |
- name: Upload alb_services.json | |
uses: actions/upload-artifact@v4 | |
with: | |
name: alb_services | |
path: cdk-graphql-stack/alb_services.json | |
deploy-graphql-cdk-stack: | |
runs-on: ubuntu-latest | |
needs: upload-to-ecs | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v4 | |
- name: Install the CDK Dependency | |
run: | | |
npm install -g aws-cdk | |
- name: Install other dependencies | |
run: | | |
npm install | |
working-directory: ./cdk-graphql-stack | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@main | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
- name: Retrieving the DNS for the services and updating the appIDs | |
run: | | |
# Initialize an empty array | |
json_array="[]" | |
for service in ./services/*/ ; do | |
service_name=$(basename "$service") | |
alb_name=$(basename "$service")-ALB | |
alb_dns=$(aws elbv2 describe-load-balancers --names $alb_name --query "LoadBalancers[0].DNSName" --output text) | |
echo "ALB DNS: $alb_dns" | |
echo "Service name is : $service_name" | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "alb_dns<<$EOF" >> $GITHUB_OUTPUT | |
echo "$alb_dns" >> $GITHUB_OUTPUT | |
echo "$EOF" >> $GITHUB_OUTPUT | |
# Create a JSON object with the service and ALB DNS | |
json_object=$(jq -n --arg service "$service_name" --arg alb_dns "$alb_dns" \ | |
'{service: $service, url: $alb_dns}') | |
# Add the JSON object to the array | |
json_array=$(echo $json_array | jq --argjson obj "$json_object" '. += [$obj]') | |
done | |
# Save the JSON array to a file | |
echo $json_array | jq . > alb_services.json | |
# Output the JSON array | |
echo "JSON Array:" | |
cat alb_services.json | |
# Download the service_tokens.json artifact | |
- name: Download service_tokens.json | |
uses: actions/download-artifact@v4 | |
with: | |
name: alb_services | |
path: cdk-graphql-stack/ | |
- name: Synthesize CdkGroupChatMicroserviceStack | |
run: | | |
json_array=$(cat alb_services.json) | |
# Save the JSON array to a file | |
echo $json_array | jq . > tokens.json | |
echo "Final JSON Array:" | |
cat tokens.json | |
cdk synth -c configfile=tokens.json | |
working-directory: ./cdk-graphql-stack | |
- name: Bootstrap CDK Stack | |
run: | | |
json_array=$(cat alb_services.json) | |
# Save the JSON array to a file | |
echo $json_array | jq . > tokens.json | |
echo "Final JSON Array:" | |
cat tokens.json | |
cdk bootstrap -c configfile=tokens.json | |
working-directory: ./cdk-graphql-stack | |
- name: Deploy CdkGroupChatMicroserviceStack to AWS | |
run: | | |
json_array=$(cat alb_services.json) | |
# Save the JSON array to a file | |
echo $json_array | jq . > tokens.json | |
echo "Final JSON Array:" | |
cat tokens.json | |
cdk deploy CdkGroupChatMicroserviceStack --require-approval=never -c configfile=tokens.json | |
working-directory: ./cdk-graphql-stack |