From e055bee0f3101ed165f063992fef862cd27ce86d Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 25 Oct 2021 09:34:00 -0500 Subject: [PATCH] operations: Add Makefiles and version-bumping script. --- Makefile | 32 ++++++++++++++++++ api/Makefile | 2 +- operations/update-version.sh | 63 ++++++++++++++++++++++++++++++++++++ web/Makefile | 5 +++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100755 Makefile create mode 100755 operations/update-version.sh create mode 100755 web/Makefile diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..9b5daa6 --- /dev/null +++ b/Makefile @@ -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 diff --git a/api/Makefile b/api/Makefile index dd67ce2..6820907 100644 --- a/api/Makefile +++ b/api/Makefile @@ -22,7 +22,7 @@ hff_entry_forms_api: $(SOURCES) # 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 # 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 ./hff_entry_forms_api serve --debug diff --git a/operations/update-version.sh b/operations/update-version.sh new file mode 100755 index 0000000..3dd7a66 --- /dev/null +++ b/operations/update-version.sh @@ -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}" + diff --git a/web/Makefile b/web/Makefile new file mode 100755 index 0000000..ca13b5a --- /dev/null +++ b/web/Makefile @@ -0,0 +1,5 @@ +build: + npm run build-${TARGET_ENV} + +serve: + npm run serve