Skip to content

Instantly share code, notes, and snippets.

@cristofer-dev
Last active March 4, 2018 23:01
Show Gist options
  • Save cristofer-dev/cad71e5dd0bafec4e6e8427b9e9e6828 to your computer and use it in GitHub Desktop.
Save cristofer-dev/cad71e5dd0bafec4e6e8427b9e9e6828 to your computer and use it in GitHub Desktop.
Build instructions for deploy react app
#!/bin/bash
# obtenemos el HASH del commit de MASTER
master=$(cat .git/refs/heads/master)
echo $master
if [ ${#master} = 0 ]; then
echo "Imposible encontrar .git/refs/heads/master"
fi
# Obtenemos el HASH del commit que le llego al BUILD
hash=$(echo $CODEBUILD_SOURCE_VERSION | cut -c1-7)
echo $hash
# Si ambos HASH son iguales, deployamos a PRO caso contrario a DEV
if [ $master = $CODEBUILD_SOURCE_VERSION ] && [ ! ${#master} = 0 ] ; then
echo "Build to PRODUCTION"
STAGE="PRO"
bucket=$bucketPro
cdn=$cdnPro
else
echo "Build to DEV"
STAGE="DEV"
bucket=$bucketDev
cdn=$cdnDev
fi
npm install
npm run build
cd build
# Upload build to s3
aws s3 sync . s3://$bucket --delete --acl public-read \
# Forzando al CDN a recargar sus fuentes
aws cloudfront create-invalidation --distribution-id $cdn --paths /
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment