Skip to content

Commit

Permalink
build(make): encapsulate tasks in Make
Browse files Browse the repository at this point in the history
Adds a Makefile for simplifying the use of potentially complicated commands in both CI and local development.

Refs #390, #395
  • Loading branch information
thewilkybarkid committed Aug 10, 2021
1 parent b56c95a commit 7021c95
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 20 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/deploy_prereview-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,31 @@ jobs:
lfs: true

- name: 'Build dev image'
run: docker-compose --file docker-compose.yml --file docker-compose.dev.yml build prereview
run: make build
env:
TARGET: 'dev'

- name: 'Lint'
run: docker-compose --file docker-compose.yml --file docker-compose.dev.yml run --entrypoint "npm run" prereview lint
run: make lint

- name: 'Test'
run: docker-compose --file docker-compose.yml --file docker-compose.dev.yml run --entrypoint "npm run" prereview test
run: make test

- name: 'Build image'
run: docker-compose build prereview
run: make build
env:
TARGET: 'prod'

- name: 'Smoke test'
run: .github/smoke-test.sh
run: make smoke-test

- name: 'Build integration test image'
run: docker-compose --file docker-compose.yml --file docker-compose.integration.yml build playwright
run: make build
env:
TARGET: 'integration'

- name: 'Run integration tests'
run: docker-compose --file docker-compose.yml --file docker-compose.integration.yml run playwright
run: make integration-test

- name: 'Store integration test results'
if: ${{ failure() }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/deploy_prereview-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
lfs: true

- name: 'Build image'
run: docker-compose build prereview
run: make build
env:
TARGET: 'prod'

- name: 'Smoke test'
run: .github/smoke-test.sh
Expand Down
14 changes: 14 additions & 0 deletions .scripts/smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e

function finish() {
echo "Stopping all containers"
make logs stop
}

trap finish EXIT

export IMAGE_TAG="${IMAGE_TAG:-local}"
export TARGET="${TARGET:-prod}"

make start wait-healthy
11 changes: 0 additions & 11 deletions .github/smoke-test.sh → .scripts/wait-healthy.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
#!/usr/bin/env bash
set -e

function finish() {
echo "Stopping all containers"
docker-compose logs
docker-compose down
}

trap finish EXIT

export IMAGE_TAG="${IMAGE_TAG:-local}"

docker-compose up --detach
container=prereview

timeout --foreground 20 bash << EOT
Expand Down
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.DEFAULT_GOAL: help
.PHONY: help build run dev prod start logs stop wait-healthy lint test integration-test smoke-test

ifeq (${TARGET},)
TARGET := dev
endif

DOCKER_COMPOSE = docker-compose --file docker-compose.yml --file docker-compose.$(TARGET).yml
IMAGE_TAG := local

export IMAGE_TAG

help: ## Display this help text
@grep -E '^[a-zA-Z_\\:-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | sed 's/\\:/:/g' | awk 'BEGIN {FS = ":[^:]*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.env:
cp env.example .env

build:
$(DOCKER_COMPOSE) build

run: .env build
${DOCKER_COMPOSE} up --abort-on-container-exit --exit-code-from prereview

dev: export TARGET = dev
dev: run ## Run the dev image

prod: export TARGET = prod
prod: run ## Run the prod image

start: .env build
start:
${DOCKER_COMPOSE} up --detach

logs:
${DOCKER_COMPOSE} logs

stop:
${DOCKER_COMPOSE} down

wait-healthy: ## Wait for the app to be healthy
.scripts/wait-healthy.sh prereview

lint: export TARGET = dev
lint: build ## Run the linter
${DOCKER_COMPOSE} run --rm --no-deps --entrypoint "npm run" prereview lint

test: export TARGET = dev
test: build ## Run the tests
${DOCKER_COMPOSE} run --rm --no-deps --entrypoint "npm run" prereview test

integration-test: export TARGET = integration
integration-test: build ## Run the integration tests
rm -rf integration/results
${DOCKER_COMPOSE} run --rm playwright

smoke-test: build ## Run the smoke tests
.scripts/smoke-test.sh
4 changes: 4 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "3"
services:
prereview:
image: prereview.azurecr.io/prereview:${IMAGE_TAG:-local}
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: "3"
services:
prereview:
container_name: prereview
image: prereview.azurecr.io/prereview:${IMAGE_TAG:-local}
build:
context: .
target: prod
Expand Down

0 comments on commit 7021c95

Please sign in to comment.