operations: Add Makefiles and version-bumping script.

This commit is contained in:
Jonathan Bernard 2021-10-25 09:34:00 -05:00
parent 7c9bdfe8f8
commit e055bee0f3
4 changed files with 101 additions and 1 deletions

32
Makefile Executable file
View File

@ -0,0 +1,32 @@
VERSION:=$(shell git describe --always)
TARGET_ENV ?= dev
build: dist/hff-entry-forms-api.tar.gz dist/hff-entry-forms-web.tar.gz
clean:
-rm -r dist
-rm -r web/dist
-docker container prune
-docker image prune
update-version:
operations/update-version.sh
dist/hff-entry-forms-web.tar.gz:
-mkdir dist
TARGET_ENV=$(TARGET_ENV) make -C web build
tar czf dist/hff-entry-forms-web-${VERSION}.tar.gz -C web/dist .
cp dist/hff-entry-forms-web-${VERSION}.tar.gz dist/hff-entry-forms-web.tar.gz
deploy-api:
make -C api build-image push-image
cd operations/terraform && terraform apply -target module.${TARGET_ENV}_env.aws_ecs_task_definition.hff_entry_forms_api -target module.${TARGET_ENV}_env.aws_ecs_service.hff_entry_forms_api
deploy-web: dist/hff-entry-forms-web.tar.gz
mkdir -p temp-deploy/hff-entry-forms-web-${VERSION}
tar xzf dist/hff-entry-forms-web-${VERSION}.tar.gz -C temp-deploy/hff-entry-forms-web-${VERSION}
aws s3 sync temp-deploy/hff-entry-forms-web-${VERSION} s3://forms.hopefamilyfellowship.com/$(TARGET_ENV)/webroot
TARGET_ENV=${TARGET_ENV} operations/invalidate-cdn-cache.sh
rm -r temp-deploy
deploy: deploy-api deploy-web

View File

@ -22,7 +22,7 @@ hff_entry_forms_api: $(SOURCES)
# Run the API on this machine. Note that configuration is taken by default # Run the API on this machine. Note that configuration is taken by default
# from the `hff_entry_forms_api.config.json` file, but environment variables # from the `hff_entry_forms_api.config.json` file, but environment variables
# specified when running make can be used to override these (to change the # specified when running make can be used to override these (to change the
# DB_CONN_STRING, for example). # INTEGRATION_TOKEN, for example).
serve: hff_entry_forms_api serve: hff_entry_forms_api
./hff_entry_forms_api serve --debug ./hff_entry_forms_api serve --debug

63
operations/update-version.sh Executable file
View File

@ -0,0 +1,63 @@
#!/bin/bash
#
# Script to update the version number, commit the changes to the version files,
# and tag the new commit.
set -e
origDir=$(pwd)
rootDir=$(git rev-parse --show-toplevel)
cd "$rootDir"
currentBranch=$(git rev-parse --abbrev-ref HEAD)
if [ "$currentBranch" != "develop" ]; then
printf "You are currently on the '%s' branch. Is this intended (yes/no)? " "$currentBranch"
read -r confirmation
if [ "$confirmation" != "yes" ]; then exit 1; fi
fi
lastVersion=$(jq -r .version web/package.json)
printf "Last version: %s\n" "$lastVersion"
printf "New version: "
read -r newVersion
printf "New version will be \"%s\". Is this correct (yes/no)? " "$newVersion"
read -r confirmation
if [ "$confirmation" != "yes" ]; then
printf "\n"
"$origDir/$0"
exit
fi
printf ">> Updating /web/package.json with \"version\": \"%s\"\n" "$newVersion"
printf "jq \".version = \\\"%s\\\"\" web/package.json > temp.json\n" "$newVersion"
jq ".version = \"${newVersion}\"" web/package.json > temp.json
printf "mv temp.json web/package.json\n"
mv temp.json web/package.json
printf ">> Updating /web/package-lock.json with \"version\": \"%s\"\n" "$newVersion"
printf "jq \".version = \\\"%s\\\"\" web/package-lock.json > temp.json\n" "$newVersion"
jq ".version = \"${newVersion}\"" web/package-lock.json > temp.json
printf "mv temp.json web/package-lock.json\n"
mv temp.json web/package-lock.json
printf ">> Updating /api/src/hff_entry_forms_apipkg/version.nim with PM_API_VERSION* = \"%s\"" "$newVersion"
printf "sed -i \"s/%s/%s/\" api/src/hff_entry_forms_apipkg/version.nim" "$lastVersion" "$newVersion"
sed -i "s/${lastVersion}/${newVersion}/" api/src/hff_entry_forms_apipkg/version.nim
printf ">> Updating /api/hff_entry_forms_api.nimble with version = \"%s\"" "$newVersion"
printf "sed -i \"s/%s/%s/\" api/hff_entry_forms_api.nimble" "$lastVersion" "$newVersion"
sed -i "s/${lastVersion}/${newVersion}/" api/hff_entry_forms_api.nimble
printf ">> Committing new version.\n"
printf "git add web/package.json web/package-lock.json api/src/hff_entry_forms_apipkg/version.nim"
git add web/package.json web/package-lock.json api/src/hff_entry_forms_apipkg/version.nimnim api/hff_entry_forms_api.nimble
printf "git commit -m \"Update package version to %s\"\n" "$newVersion"
git commit -m "Update package version to ${newVersion}"
printf ">> Tagging commit.\n"
printf "git tag -m \"Version %s\" \"%s\"\n" "$newVersion" "$newVersion"
git tag -m "Version ${newVersion}" "${newVersion}"

5
web/Makefile Executable file
View File

@ -0,0 +1,5 @@
build:
npm run build-${TARGET_ENV}
serve:
npm run serve