Skip to content

Commit

Permalink
auto-deploy-apprunner
Browse files Browse the repository at this point in the history
  • Loading branch information
codernesty committed Aug 22, 2024
1 parent 58b4e22 commit 43a45ff
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,56 @@ on:
- master

jobs:
# Job for deploying the backend service
deploy-backend:
name: Deploy Backend to AWS App Runner
runs-on: ubuntu-latest # Run on the latest version of Ubuntu

steps:
# Step 1: Check out the code from the repository
- name: Check out code
uses: actions/checkout@v3 # GitHub Action to check out the code

# Step 2: Set up AWS CLI with necessary credentials
- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v2 # GitHub Action to configure AWS credentials
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} # AWS Access Key ID stored as a GitHub secret
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # AWS Secret Access Key stored as a GitHub secret
aws-region: ${{ secrets.AWS_REGION }} # AWS Region stored as a GitHub secret

# Step 3: Deploy the backend service to AWS App Runner with retry logic
- name: Deploy Backend
run: |
# Fetch the Service ARN from AWS App Runner
SERVICE_ARN=$(aws apprunner list-services --query "ServiceSummaryList[?ServiceName=='${{ secrets.APP_RUNNER_SERVICE_NAME_BACKEND }}'].ServiceArn | [0]" --output text)
if [ -z "$SERVICE_ARN" ]; then
echo "Error: Service ARN not found for service name ${{ secrets.APP_RUNNER_SERVICE_NAME_BACKEND }}."
exit 1
fi
# Retry logic with exponential backoff
RETRY_COUNT=0
MAX_RETRIES=15
BACKOFF_TIME=5 # Initial backoff time in seconds
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if aws apprunner update-service \
--service-arn $SERVICE_ARN \
--source-configuration {CodeRepository={RepositoryUrl=${{ secrets.REPOSITORY_URL }}, SourceCodeVersion={Type=BRANCH, Value=master}, SourceDirectory=linguaphoto}; then
echo "Service updated successfully."
exit 0
else
RETRY_COUNT=$((RETRY_COUNT + 1))
echo "Update failed. Attempt $RETRY_COUNT of $MAX_RETRIES. Retrying in $BACKOFF_TIME seconds..."
sleep $BACKOFF_TIME
BACKOFF_TIME=$((BACKOFF_TIME * 2)) # Exponential backoff
fi
done
echo "Failed to update the service after $MAX_RETRIES attempts."
exit 1
# # Job for deploying the backend service
# deploy-backend:
# name: Deploy Backend to AWS App Runner
# runs-on: ubuntu-latest # Run on the latest version of Ubuntu

# steps:
# # Step 1: Check out the code from the repository
# - name: Check out code
# uses: actions/checkout@v3 # GitHub Action to check out the code

# # Step 2: Set up AWS CLI with necessary credentials
# - name: Set up AWS CLI
# uses: aws-actions/configure-aws-credentials@v2 # GitHub Action to configure AWS credentials
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} # AWS Access Key ID stored as a GitHub secret
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # AWS Secret Access Key stored as a GitHub secret
# aws-region: ${{ secrets.AWS_REGION }} # AWS Region stored as a GitHub secret

# # Step 3: Deploy the backend service to AWS App Runner with retry logic
# - name: Deploy Backend
# run: |
# # Fetch the Service ARN from AWS App Runner
# SERVICE_ARN=$(aws apprunner list-services --query "ServiceSummaryList[?ServiceName=='${{ secrets.APP_RUNNER_SERVICE_NAME_BACKEND }}'].ServiceArn | [0]" --output text)

# if [ -z "$SERVICE_ARN" ]; then
# echo "Error: Service ARN not found for service name ${{ secrets.APP_RUNNER_SERVICE_NAME_BACKEND }}."
# exit 1
# fi

# # Retry logic with exponential backoff
# RETRY_COUNT=0
# MAX_RETRIES=15
# BACKOFF_TIME=5 # Initial backoff time in seconds

# while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
# if aws apprunner update-service \
# --service-arn $SERVICE_ARN \
# --source-configuration {CodeRepository={RepositoryUrl=${{ secrets.REPOSITORY_URL }}, SourceCodeVersion={Type=BRANCH, Value=master}, SourceDirectory=linguaphoto}; then
# echo "Service updated successfully."
# exit 0
# else
# RETRY_COUNT=$((RETRY_COUNT + 1))
# echo "Update failed. Attempt $RETRY_COUNT of $MAX_RETRIES. Retrying in $BACKOFF_TIME seconds..."
# sleep $BACKOFF_TIME
# BACKOFF_TIME=$((BACKOFF_TIME * 2)) # Exponential backoff
# fi
# done

# echo "Failed to update the service after $MAX_RETRIES attempts."
# exit 1

# Job for deploying the frontend service
deploy-frontend:
Expand Down

0 comments on commit 43a45ff

Please sign in to comment.