Skip to content

Instantly share code, notes, and snippets.

@hmarcelodn
Created December 22, 2021 22:18
Show Gist options
  • Select an option

  • Save hmarcelodn/94a90a58ee5d8681e1f70d99b2996572 to your computer and use it in GitHub Desktop.

Select an option

Save hmarcelodn/94a90a58ee5d8681e1f70d99b2996572 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create release revision
AWS_VERSION_LABEL="${AWS_ENVIRONMENT_SUFFIX}-release-`date +%Y%m%d-%H%M%S`"
AWS_BUNDLE_NAME="${AWS_VERSION_LABEL}.zip"
# Download Environment Variables
echo "Downloading frontend environment variables for ${AWS_ENVIRONMENT_SUFFIX}..."
aws s3 cp s3://${AWS_S3_BUCKET_NAME}/environment/.env.frontend.${AWS_ENVIRONMENT_SUFFIX} ./apps/mudbay-storeopsportal-fe/.env
# Build Code Base
echo "Building..."
(cd ./apps/mudbay-storeopsportal-be && npm install && tsc)
cp -R ./apps/mudbay-storeopsportal-be/dist/ ./dist
cp -R ./apps/mudbay-storeopsportal-be/node_modules/ ./dist
cp ./apps/mudbay-storeopsportal-be/package.json ./dist
cp ./apps/mudbay-storeopsportal-be/.npmrc ./dist
cp -R ./apps/mudbay-storeopsportal-be/src/graphql/schema/ ./dist/graphql/schema/
mkdir -p ./dist/client
mkdir -p ./dist/certificates
(cd ./apps/mudbay-storeopsportal-fe && npm install && npm run build)
cp -R ./apps/mudbay-storeopsportal-fe/build/* ./dist/client
cp -R ./apps/mudbay-storeopsportal-fe/public ./dist/client/public
cp ./apps/mudbay-storeopsportal-fe/package.json ./dist/client/package.json
cp -R ./.ebextensions ./dist
cp -R ./.elasticbeanstalk ./dist
# Download the backend environment variables
echo "Downloading backend environment variables for ${AWS_ENVIRONMENT_SUFFIX}..."
aws s3 cp s3://${AWS_S3_BUCKET_NAME}/environment/.env.backend.${AWS_ENVIRONMENT_SUFFIX} ./dist/.env
echo "Downloading Salesforce certificates..."
aws s3 cp s3://${AWS_S3_BUCKET_NAME}/salesforce/key.pem ./dist/certificates/key.pem
# Zip the solution
echo "Zipping dist folder"
(cd ./dist ; zip -r ../${AWS_BUNDLE_NAME} . *)
# Listing Items
ls -la
# Deployment
echo "Uploading bundle to S3..."
aws s3 cp ${AWS_BUNDLE_NAME} s3://${AWS_S3_BUCKET_NAME}/
echo "Creating EB application version..."
aws elasticbeanstalk create-application-version \
--application-name ${AWS_EB_APPLICATION_NAME} \
--version-label ${AWS_VERSION_LABEL} \
--source-bundle S3Bucket="${AWS_S3_BUCKET_NAME}",S3Key="${AWS_BUNDLE_NAME}" > /dev/null
# echo "Updating EB environment to the new version..."
aws elasticbeanstalk update-environment \
--application-name ${AWS_EB_APPLICATION_NAME} \
--environment-name ${AWS_EB_ENVIRONMENT_NAME} \
--version-label ${AWS_VERSION_LABEL} > /dev/null
# Create a Sentry Release
curl -sL https://sentry.io/get-cli/ | bash
sentry-cli releases new -p ${SENTRY_PROJECT} ${AWS_VERSION_LABEL}
sentry-cli releases set-commits --auto ${AWS_VERSION_LABEL}
sentry-cli releases finalize ${AWS_VERSION_LABEL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment