Skip to content

Commit

Permalink
Final code for dotnet sample app deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeel Mehta committed Dec 27, 2024
1 parent badccaf commit f50c6b5
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions .github/workflows/dotnet-sample-app-s3-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ jobs:
'ap-southeast-2','ap-southeast-3','ap-southeast-4','ca-central-1','eu-central-1','eu-central-2','eu-north-1',
'eu-south-1','eu-south-2','eu-west-1','eu-west-2','eu-west-3','il-central-1','me-central-1','me-south-1', 'sa-east-1',
'us-east-1','us-east-2', 'us-west-1', 'us-west-2' ]
dotnet-version: [ '6.0', '8.0' ]
runs-on: ubuntu-latest
env:
DEFAULT_VERSION: '8.0'
DOTNET_VERSION: ${{ matrix.dotnet-version }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -42,13 +46,68 @@ jobs:
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ secrets.E2E_TEST_ROLE_ARN }}
aws-region: ${{ matrix.aws-region }}

- name: Update .NET version if not default
working-directory: sample-apps/dotnet
run: |
if [ "${DOTNET_VERSION}" != "${DEFAULT_VERSION}" ]; then
echo "Updating .NET version from ${DEFAULT_VERSION} to ${DOTNET_VERSION}"
# Function to update version in files
update_version() {
local file=$1
if [ ! -f "$file" ]; then
echo "Error: File $file not found"
exit 1
fi
# Update TargetFramework in csproj files
if [[ $file == *.csproj ]]; then
sed -i "s/<TargetFramework>netcoreapp${DEFAULT_VERSION}<\/TargetFramework>/<TargetFramework>netcoreapp${DOTNET_VERSION}<\/TargetFramework>/g" "$file"
# Update version in Dockerfiles
elif [[ $file == */Dockerfile ]]; then
# Update SDK version
sed -i "s/mcr.microsoft.com\/dotnet\/sdk:${DEFAULT_VERSION}/mcr.microsoft.com\/dotnet\/sdk:${DOTNET_VERSION}/g" "$file"
# Update ASP.NET runtime version
sed -i "s/mcr.microsoft.com\/dotnet\/aspnet:${DEFAULT_VERSION}/mcr.microsoft.com\/dotnet\/aspnet:${DOTNET_VERSION}/g" "$file"
fi

if [ $? -ne 0 ]; then
echo "Error: Failed to update version in $file"
exit 1
fi
echo "Successfully updated $file"
}

# Update all relevant files
update_version "asp_frontend_service/Dockerfile"
update_version "asp_remote_service/Dockerfile"
update_version "asp_frontend_service/asp_frontend_service.csproj"
update_version "asp_remote_service/asp_remote_service.csproj"


# Verify changes
echo "Verifying changes..."
echo "=== Frontend Dockerfile ==="
grep -n "FROM.*${DOTNET_VERSION}" asp_frontend_service/Dockerfile
echo "=== Remote Dockerfile ==="
grep -n "FROM.*${DOTNET_VERSION}" asp_remote_service/Dockerfile
echo "=== Frontend csproj ==="
grep -n "TargetFramework" asp_frontend_service/asp_frontend_service.csproj
echo "=== Remote csproj ==="
grep -n "TargetFramework" asp_remote_service/asp_remote_service.csproj

else
echo "Using default version ${DEFAULT_VERSION}, no changes needed"
fi

- name: Build Sample App Zip
working-directory: sample-apps/dotnet
run: zip -r dotnet-sample-app.zip .
run: zip -r dotnet-sample-app-${DOTNET_VERSION}.zip .

- name: Upload to S3
working-directory: sample-apps/dotnet
run: aws s3api put-object --bucket aws-appsignals-sample-app-prod-${{ matrix.aws-region }} --body ./dotnet-sample-app.zip --key dotnet-sample-app.zip
run: aws s3api put-object --bucket aws-appsignals-sample-app-prod-${{ matrix.aws-region }} --body ./dotnet-sample-app-${DOTNET_VERSION}.zip --key dotnet-sample-app-${DOTNET_VERSION}.zip

- name: Upload Windows Script to S3
working-directory: sample-apps/dotnet
Expand Down

0 comments on commit f50c6b5

Please sign in to comment.