Skip to content

Commit

Permalink
build: Add rules for CI
Browse files Browse the repository at this point in the history
In CI, we want to perform the build of the project (which means
building, linting and checking go modules) and make sure that after
that, the git tree is still clean.

The CI will also run the tests using the testing postgres docker image
we added in an earlier commit.
  • Loading branch information
krnowak committed Nov 18, 2019
1 parent f86224d commit bb34bca
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Makefile
@@ -1,6 +1,7 @@
GO111MODULE=on
export GO111MODULE

SHELL = /bin/bash
VERSION ?= $(shell git describe --tags --always --dirty)
DOCKER_CMD ?= "docker"
DOCKER_REPO ?= "quay.io/flatcar"
Expand All @@ -14,6 +15,30 @@ all: backend tools frontend
check:
go test -p 1 ./...

container_id:
set -e; \
docker build \
--file Dockerfile.postgres-test \
--tag kinvolk/nebraska-postgres-test \
.; \
trap "rm -f container_id.tmp container_id" ERR; \
docker run \
--privileged \
--detach \
--publish 127.0.0.1:5432:5432 \
kinvolk/nebraska-postgres-test \
>container_id.tmp; \
docker exec \
$$(cat container_id.tmp) \
/wait_for_db_ready.sh; \
mv container_id.tmp container_id

.PHONY: check-backend-with-container
check-backend-with-container: container_id
set -e; \
trap "docker kill $$(cat container_id); docker rm $$(cat container_id); rm -f container_id" EXIT; \
go test -p 1 ./...

.PHONY: frontend
frontend:
cd frontend && npm install && npm run build
Expand All @@ -34,6 +59,16 @@ backend: tools/go-bindata tools/golangci-lint
go mod tidy
go build -o bin/nebraska ./cmd/nebraska

.PHONY: test-clean-work-tree-backend
test-clean-work-tree-backend:
@if ! git diff --quiet -- go.mod go.sum pkg cmd updaters tools/tools.go; then \
echo; \
echo 'Working tree of backend code is not clean'; \
echo; \
git status; \
exit 1; \
fi

.PHONY: tools
tools:
go build -o bin/initdb ./cmd/initdb
Expand Down Expand Up @@ -63,3 +98,6 @@ container-postgres:

.PHONY: container
container: container-nebraska container-postgres

.PHONY: backend-ci
backend-ci: backend test-clean-work-tree-backend check-backend-with-container

0 comments on commit bb34bca

Please sign in to comment.