Merge pull request #118 from ThriveCommunityChurch/config_update #19
This file contains hidden or 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 to AWS App Runner | |
| on: | |
| push: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| env: | |
| AWS_REGION: us-east-2 | |
| ECR_REPOSITORY: thrive-fl/thrivechurchofficialapi | |
| APP_RUNNER_SERVICE: thrive-api | |
| jobs: | |
| deploy: | |
| name: Build and Deploy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Build, tag, and push image to Amazon ECR | |
| id: build-image | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| run: | | |
| # Generate image tag in yyyy.mm.dd.build# format | |
| DATE_TAG=$(date +'%Y.%m.%d') | |
| IMAGE_TAG="${DATE_TAG}.${{ github.run_number }}" | |
| # Build the Docker image | |
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./API/ThriveChurchOfficialAPI | |
| # Push the image | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| # Output the image URI for App Runner | |
| echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
| - name: Deploy to App Runner | |
| env: | |
| IMAGE_URI: ${{ steps.build-image.outputs.image }} | |
| run: | | |
| # Check if service exists | |
| SERVICE_ARN=$(aws apprunner list-services --query "ServiceSummaryList[?ServiceName=='${{ env.APP_RUNNER_SERVICE }}'].ServiceArn" --output text) | |
| if [ -z "$SERVICE_ARN" ] || [ "$SERVICE_ARN" == "None" ]; then | |
| echo "App Runner service does not exist yet. Please create it manually in the AWS Console first." | |
| exit 1 | |
| fi | |
| echo "Updating App Runner service to use image: $IMAGE_URI" | |
| # Get the current service configuration to preserve all settings | |
| CURRENT_CONFIG=$(aws apprunner describe-service --service-arn $SERVICE_ARN) | |
| # Extract and update the source configuration, preserving all existing settings | |
| # This keeps environment variables, secrets, and other ImageConfiguration intact | |
| UPDATED_SOURCE_CONFIG=$(echo $CURRENT_CONFIG | jq --arg NEW_IMAGE "$IMAGE_URI" ' | |
| .Service.SourceConfiguration | | |
| .ImageRepository.ImageIdentifier = $NEW_IMAGE | | |
| del(.CodeRepository) | | |
| del(.AutoDeploymentsEnabled) | |
| ') | |
| # Update the service with the new image while preserving all other settings | |
| # Only output the operation ID (safe) - suppress all other output that contains env vars | |
| aws apprunner update-service \ | |
| --service-arn $SERVICE_ARN \ | |
| --source-configuration "$UPDATED_SOURCE_CONFIG" \ | |
| --query 'OperationId' \ | |
| --output text | |
| echo "App Runner service updated for: ${{ env.APP_RUNNER_SERVICE }}" | |