From 6d053b434963c9e7e813cccb2abbdf5edf9bb98a Mon Sep 17 00:00:00 2001 From: andreram Date: Tue, 13 Apr 2021 16:14:07 -0400 Subject: [PATCH 1/4] remove old script --- .github/workflows/test-workflow.yml | 5 +-- deployBackend.sh | 50 +++++++++++++++++++++++++++-- deployCI.sh | 9 ------ 3 files changed, 51 insertions(+), 13 deletions(-) delete mode 100644 deployCI.sh diff --git a/.github/workflows/test-workflow.yml b/.github/workflows/test-workflow.yml index 4523be6e..8f1d0d0d 100644 --- a/.github/workflows/test-workflow.yml +++ b/.github/workflows/test-workflow.yml @@ -30,8 +30,9 @@ jobs: - name: Build backend run: | cd $GITHUB_WORKSPACE - chmod 700 deployCI.sh - ./deployCI.sh + dotnet tool install -g Amazon.Lambda.Tools + chmod 700 deployBackend.sh + ./deployBackend.sh -c -e dev # Install frontend packages - name: Install packages run: | diff --git a/deployBackend.sh b/deployBackend.sh index 3482e396..30d2939a 100644 --- a/deployBackend.sh +++ b/deployBackend.sh @@ -1,3 +1,31 @@ +while getopts "p:e:c" opt; do + case $opt in + p) + userProfile=$OPTARG + echo "User profile set to: $userProfile" + ;; + e) + export DEPLOY_ENVIRONMENT=$OPTARG + echo "Deploy environment: $DEPLOY_ENVIRONMENT" + copy /b src/Project/ProjectStack.cs +,, + ;; + c) + clean=true + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + + + + # Run the commented command manually if you haven't before # dotnet tool install -g Amazon.Lambda.Tools cd Handler/src/Handler @@ -6,5 +34,23 @@ dotnet build -c Release dotnet lambda package cd ../../.. echo "***Deploying backend***" -cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never -echo "Done" +if [ $userProfile ] +then + cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never --profile $userProfile + if [ $clean ] + then + dbinitName=`aws lambda list-functions --profile $userProfile | awk '/ProjectStack-databaseInit/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'` + dropTablesName=`aws lambda list-functions --profile $userProfile | awk '/ProjectStack-databaseDropAll/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'` + aws lambda invoke --function-name $dropTablesName --profile $userProfile response.json + aws lambda invoke --function-name $dbinitName --profile $userProfile response.json + fi +else + cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never + if [ $clean ] + then + dbinitName=`aws lambda list-functions | awk '/ProjectStack-databaseInit/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'` + dropTablesName=`aws lambda list-functions | awk '/ProjectStack-databaseDropAll/ {print $2}' | grep -v arn | tr -d , | sed -e 's/^"//' -e 's/"$//'` + aws lambda invoke --function-name $dropTablesName sresponse.json + aws lambda invoke --function-name $dbinitName response.json + fi +fi diff --git a/deployCI.sh b/deployCI.sh deleted file mode 100644 index 0ec72629..00000000 --- a/deployCI.sh +++ /dev/null @@ -1,9 +0,0 @@ -dotnet tool install -g Amazon.Lambda.Tools -cd Handler/src/Handler -echo "***Building backend***" -dotnet build -c Release -dotnet lambda package -cd ../../.. -echo "***Deploying backend***" -cdk deploy ProjectStack --outputs-file Frontend/src/endpoint.json --require-approval never -echo "Done" From 4ae750cec9529dfb97fe94a4600525d1babfbc5b Mon Sep 17 00:00:00 2001 From: andreram Date: Tue, 13 Apr 2021 17:26:22 -0400 Subject: [PATCH 2/4] Add deploy script --- .github/workflows/deploy-workflow.yml | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/deploy-workflow.yml diff --git a/.github/workflows/deploy-workflow.yml b/.github/workflows/deploy-workflow.yml new file mode 100644 index 00000000..e3b770be --- /dev/null +++ b/.github/workflows/deploy-workflow.yml @@ -0,0 +1,79 @@ +name: Deploy +on: + push: + branches: [main] + +env: + REGION: us-west-2 + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + # Sets up AWS profile. + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.CI_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.CI_SECRET_ACCESS_KEY }} + aws-region: ${{ env.REGION }} + # Install CDK + - name: Install CDK + run: sudo npm install -g aws-cdk@1.95.1 + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + # Build and deploy the backend + - name: Build backend + run: | + cd $GITHUB_WORKSPACE + chmod 700 deployBackend.sh + ./deployBackend.sh -c -e test + # Install frontend packages + - name: Install packages + run: | + sudo npm install -g yarn + cd Frontend + yarn install + # Run E2E tests + - name: Cypress tests + uses: cypress-io/github-action@v2 + with: + working-directory: ./Frontend + browser: chrome + headless: true + start: yarn start || exit 1 + wait-on: 'http://localhost:3000' + deploy: + name: Deploy + needs: test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + # Sets up AWS profile. + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.PROD_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.PROD_SECRET_ACCESS_KEY }} + aws-region: ${{ env.REGION }} + # Install CDK + - name: Install CDK + run: sudo npm install -g aws-cdk@1.95.1 + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + # Build and deploy to production + - name: Build and deploy + run: | + cd $GITHUB_WORKSPACE + chmod 700 deploy.sh + ./deploy.sh -e prod \ No newline at end of file From 11b0f8d933860f548434d0e8c8f4166bcbb52acf Mon Sep 17 00:00:00 2001 From: andreram Date: Tue, 13 Apr 2021 18:38:31 -0400 Subject: [PATCH 3/4] minor --- .github/workflows/deploy-workflow.yml | 2 ++ .github/workflows/test-workflow.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-workflow.yml b/.github/workflows/deploy-workflow.yml index e3b770be..b3bc13c3 100644 --- a/.github/workflows/deploy-workflow.yml +++ b/.github/workflows/deploy-workflow.yml @@ -32,6 +32,7 @@ jobs: - name: Build backend run: | cd $GITHUB_WORKSPACE + dotnet tool install -g Amazon.Lambda.Tools chmod 700 deployBackend.sh ./deployBackend.sh -c -e test # Install frontend packages @@ -75,5 +76,6 @@ jobs: - name: Build and deploy run: | cd $GITHUB_WORKSPACE + dotnet tool install -g Amazon.Lambda.Tools chmod 700 deploy.sh ./deploy.sh -e prod \ No newline at end of file diff --git a/.github/workflows/test-workflow.yml b/.github/workflows/test-workflow.yml index 8f1d0d0d..20041008 100644 --- a/.github/workflows/test-workflow.yml +++ b/.github/workflows/test-workflow.yml @@ -32,7 +32,7 @@ jobs: cd $GITHUB_WORKSPACE dotnet tool install -g Amazon.Lambda.Tools chmod 700 deployBackend.sh - ./deployBackend.sh -c -e dev + ./deployBackend.sh -c -e test # Install frontend packages - name: Install packages run: | From 2b2a294db65b7128803ef8638c26d96edce9b936 Mon Sep 17 00:00:00 2001 From: andreram Date: Tue, 13 Apr 2021 19:24:27 -0400 Subject: [PATCH 4/4] typo in folder --- .github/workflows/deploy-workflow.yml | 4 ++-- .github/workflows/test-workflow.yml | 2 +- {TestDatabseInit => TestDatabaseInit}/dbInit.sql | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename {TestDatabseInit => TestDatabaseInit}/dbInit.sql (100%) diff --git a/.github/workflows/deploy-workflow.yml b/.github/workflows/deploy-workflow.yml index b3bc13c3..e3674f76 100644 --- a/.github/workflows/deploy-workflow.yml +++ b/.github/workflows/deploy-workflow.yml @@ -34,7 +34,7 @@ jobs: cd $GITHUB_WORKSPACE dotnet tool install -g Amazon.Lambda.Tools chmod 700 deployBackend.sh - ./deployBackend.sh -c -e test + ./deployBackend.sh -c -e test || exit 1 # Install frontend packages - name: Install packages run: | @@ -78,4 +78,4 @@ jobs: cd $GITHUB_WORKSPACE dotnet tool install -g Amazon.Lambda.Tools chmod 700 deploy.sh - ./deploy.sh -e prod \ No newline at end of file + ./deploy.sh -e prod || exit 1 \ No newline at end of file diff --git a/.github/workflows/test-workflow.yml b/.github/workflows/test-workflow.yml index 20041008..8fd9c8ef 100644 --- a/.github/workflows/test-workflow.yml +++ b/.github/workflows/test-workflow.yml @@ -32,7 +32,7 @@ jobs: cd $GITHUB_WORKSPACE dotnet tool install -g Amazon.Lambda.Tools chmod 700 deployBackend.sh - ./deployBackend.sh -c -e test + ./deployBackend.sh -c -e test || exit 1 # Install frontend packages - name: Install packages run: | diff --git a/TestDatabseInit/dbInit.sql b/TestDatabaseInit/dbInit.sql similarity index 100% rename from TestDatabseInit/dbInit.sql rename to TestDatabaseInit/dbInit.sql