Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CI scripts #114

Merged
merged 6 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/deploy-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Deploy
on:
push:
branches: [main]

env:
REGION: us-west-2

jobs:
test:
name: Test
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there's no way to reuse scripts: actions/starter-workflows#245

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 [email protected]
# 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
dotnet tool install -g Amazon.Lambda.Tools
chmod 700 deployBackend.sh
./deployBackend.sh -c -e test || exit 1
# 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 [email protected]
# 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
dotnet tool install -g Amazon.Lambda.Tools
chmod 700 deploy.sh
./deploy.sh -e prod || exit 1
5 changes: 3 additions & 2 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 test || exit 1
# Install frontend packages
- name: Install packages
run: |
Expand Down
File renamed without changes.
50 changes: 48 additions & 2 deletions deployBackend.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
9 changes: 0 additions & 9 deletions deployCI.sh

This file was deleted.