Skip to content

Commit

Permalink
Merge pull request #2751 from transcom/cg_diagnostic
Browse files Browse the repository at this point in the history
Create a diagnostic target for the project.
  • Loading branch information
Chris Gilmer committed Oct 4, 2019
2 parents 1b55fe4 + 6619710 commit 386d029
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
21 changes: 17 additions & 4 deletions Makefile
Expand Up @@ -98,12 +98,25 @@ else
endif
touch .check_bash_version.stamp

.PHONY: check_node_version
check_node_version: .check_node_version.stamp ## Check that the correct Node version is installed
.check_node_version.stamp: scripts/check-node-version
scripts/check-node-version
touch .check_node_version.stamp

.PHONY: check_docker_size
check_docker_size: ## Check the amount of disk space used by docker
scripts/check-docker-size

.PHONY: deps
deps: prereqs check_hosts check_go_version check_gopath check_bash_version ensure_pre_commit client_deps bin/rds-combined-ca-bundle.pem ## Run all checks and install all depdendencies

.PHONY: test
test: client_test server_test e2e_test ## Run all tests

.PHONY: diagnostic
diagnostic: prereqs check_hosts check_go_version check_gopath check_bash_version check_node_version check_docker_size ## Run diagnostic scripts on environment

#
# ----- END CHECK TARGETS -----
#
Expand All @@ -113,17 +126,17 @@ test: client_test server_test e2e_test ## Run all tests
#

.PHONY: client_deps_update
client_deps_update: ## Update client dependencies
client_deps_update: .check_node_version.stamp ## Update client dependencies
yarn upgrade

.PHONY: client_deps
client_deps: .check_hosts.stamp .client_deps.stamp ## Install client dependencies
client_deps: .check_hosts.stamp .check_node_version.stamp .client_deps.stamp ## Install client dependencies
.client_deps.stamp: yarn.lock
yarn install
scripts/copy-swagger-ui
touch .client_deps.stamp

.client_build.stamp: $(shell find src -type f)
.client_build.stamp: .check_node_version.stamp $(shell find src -type f)
yarn build
touch .client_build.stamp

Expand Down Expand Up @@ -293,7 +306,7 @@ server_run:
# This command runs the server behind gin, a hot-reload server
# Note: Gin is not being used as a proxy so assigning odd port and laddr to keep in IPv4 space.
# Note: The INTERFACE envar is set to configure the gin build, milmove_gin, local IP4 space with default port 8080.
server_run_default: .check_hosts.stamp .check_go_version.stamp .check_gopath.stamp bin/gin build/index.html server_generate db_dev_run
server_run_default: .check_hosts.stamp .check_go_version.stamp .check_gopath.stamp .check_node_version.stamp bin/gin build/index.html server_generate db_dev_run
INTERFACE=localhost DEBUG_LOGGING=true \
$(AWS_VAULT) ./bin/gin \
--build ./cmd/milmove \
Expand Down
4 changes: 2 additions & 2 deletions scripts/check-bash-version
Expand Up @@ -23,9 +23,9 @@ check_shell /usr/local/bin/bash
# Knocks off everything after the last decimal
SHORT_VERSION=${BASH_VERSION%.*}
if [[ $SHORT_VERSION = *$VERSION* ]]; then
echo "$BASH_VERSION installed"
echo "Bash $BASH_VERSION installed"
else
echo "$VERSION.x is required to run this project! Found $BASH_VERSION"
echo "Bash $VERSION.x is required to run this project! Found $BASH_VERSION"
echo "Run 'brew install bash', add '/usr/local/bin/bash' to your /etc/shells file, and restart your terminal"
exit 1
fi
25 changes: 25 additions & 0 deletions scripts/check-docker-size
@@ -0,0 +1,25 @@
#! /usr/bin/env bash

#
# Script to check the available disk space Docker has used
#

set -eu -o pipefail

# Location of the reserved docker disk space
DOCKER_RAW=~/Library/Containers/com.docker.docker/Data/vms/0/Docker.raw

# Listing the actual used size by docker requires du
SIZE_ACTUAL=$(/usr/bin/du "${DOCKER_RAW}" | cut -f1)

# Listing the logical size reserved by docker requires stat
SIZE_RESERVED=$(/usr/bin/stat -f%z "${DOCKER_RAW}")

# Compare the size to get percentage used
# Give an integer number so the if-statement will work in bash
PERCENT_USED=$(python -c "print('{0:.0f}'.format((${SIZE_ACTUAL} / (1024 * 1024 * 2)) / (${SIZE_RESERVED} / (1024 * 1024 * 1024)) * 100))")
echo "Docker is using $PERCENT_USED% of its available disk space!"
if [[ ${PERCENT_USED} -gt 90 ]]; then
echo "Consider running 'docker system prune --volumes' to free up space"
exit 1
fi
8 changes: 5 additions & 3 deletions scripts/check-go-version
Expand Up @@ -4,10 +4,12 @@ set -eu -o pipefail

VERSION="go1.12"

if [[ $(go version) = *$VERSION* ]]; then
echo "$VERSION installed"
GOLANG_VERSION=$(go version)
if [[ $GOLANG_VERSION = *$VERSION* ]]; then
echo "Golang $GOLANG_VERSION installed"
else
echo "$VERSION is required to run this project!"
echo "Golang $VERSION is required to run this project! Found $GOLANG_VERSION"
echo "Run 'brew install go@1.12 && brew link --force go@1.12' to install"
exit 1
fi

15 changes: 15 additions & 0 deletions scripts/check-node-version
@@ -0,0 +1,15 @@
#! /usr/bin/env bash

set -eu -o pipefail

VERSION="v10.16"

NODE_VERSION=$(node --version)
if [[ $NODE_VERSION = *$VERSION* ]]; then
echo "Node $NODE_VERSION installed"
else
echo "Node $VERSION is required to run this project! Found $NODE_VERSION"
echo "Run 'brew install node@10 && brew link --force node@10' to install"
exit 1
fi

0 comments on commit 386d029

Please sign in to comment.