Skip to content

Commit 18a8ca1

Browse files
authored
Merge pull request sorintlab#715 from sgotti/use_makefile
Use a Makefile for all build tasks
2 parents d416efe + cad12a8 commit 18a8ca1

File tree

12 files changed

+68
-131
lines changed

12 files changed

+68
-131
lines changed

.agola/config.jsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ local task_build_go(version, arch) = {
3333
steps: [
3434
{ type: 'clone' },
3535
{ type: 'restore_cache', keys: ['cache-sum-{{ md5sum "go.sum" }}', 'cache-date-'], dest_dir: '/go/pkg/mod/cache' },
36-
{ type: 'run', command: './build' },
37-
{ type: 'run', command: './test' },
36+
{ type: 'run', command: 'make' },
37+
{ type: 'run', command: 'make test' },
3838
{ type: 'run', name: 'build integration tests binary', command: 'go test -c ./tests/integration/ -o bin/integration-tests' },
3939
{ type: 'save_cache', key: 'cache-sum-{{ md5sum "go.sum" }}', contents: [{ source_dir: '/go/pkg/mod/cache' }] },
4040
{ type: 'save_cache', key: 'cache-date-{{ year }}-{{ month }}-{{ day }}', contents: [{ source_dir: '/go/pkg/mod/cache' }] },

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ env:
1313
install: true
1414

1515
script:
16-
GO111MODULE=on ./test
16+
- GO111MODULE=on make test

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
PROJDIR=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
2+
3+
# change to project dir so we can express all as relative paths
4+
$(shell cd $(PROJDIR))
5+
6+
REPO_PATH=github.com/sorintlab/stolon
7+
8+
VERSION ?= $(shell scripts/git-version.sh)
9+
10+
LD_FLAGS="-w -X $(REPO_PATH)/cmd.Version=$(VERSION)"
11+
12+
$(shell mkdir -p bin )
13+
14+
15+
.PHONY: all
16+
all: build
17+
18+
.PHONY: build
19+
build: sentinel keeper proxy stolonctl
20+
21+
.PHONY: test
22+
test: build
23+
./test
24+
25+
.PHONY: sentinel keeper proxy stolonctl docker
26+
27+
keeper:
28+
GO111MODULE=on go build -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/stolon-keeper $(REPO_PATH)/cmd/keeper
29+
30+
sentinel:
31+
CGO_ENABLED=0 GO111MODULE=on go build -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/stolon-sentinel $(REPO_PATH)/cmd/sentinel
32+
33+
proxy:
34+
CGO_ENABLED=0 GO111MODULE=on go build -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/stolon-proxy $(REPO_PATH)/cmd/proxy
35+
36+
stolonctl:
37+
CGO_ENABLED=0 GO111MODULE=on go build -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/stolonctl $(REPO_PATH)/cmd/stolonctl
38+
39+
.PHONY: docker
40+
docker: build
41+
if [ -z $${PGVERSION} ]; then echo 'PGVERSION is undefined'; exit 1; fi; \
42+
if [ -z $${TAG} ]; then echo 'TAG is undefined'; exit 1; fi; \
43+
export TEMPFILE="$$(mktemp)"; \
44+
sed -e "s/\$${PGVERSION}/$${PGVERSION}/" examples/kubernetes/image/docker/Dockerfile.template > $${TEMPFILE}; \
45+
docker build -t $${TAG} -f $${TEMPFILE} .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Anyway it's quite easy to reset a cluster from scratch keeping the current maste
7373
To build stolon we usually test and support the latest two major versions of Go like in the [Go release policy](https://golang.org/doc/devel/release.html#policy).
7474

7575
```
76-
./build
76+
make
7777
```
7878

7979
## High availability

build

Lines changed: 0 additions & 70 deletions
This file was deleted.

examples/kubernetes/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ Additional images are available:
1414

1515
* `master-pg10`: automatically built after every commit to the master branch.
1616

17-
In the [image](image/docker) directory you'll find a Makefile to build the image used in this example (starting from the official postgreSQL images). The Makefile generates the Dockefile from a template Dockerfile where you have to define the wanted postgres version and image tag (`PGVERSION` and `TAG` mandatory variables).
17+
In the [image](image/docker) directory you'll find a Dockerfile to build the image used in this example (starting from the official postgreSQL images).
18+
19+
To build the image used in this example just execute (from the project root) `make` with the `docker` target providing the mandatory `PGVERSION` and `TAG` variables.
20+
1821
For example, if you want to build an image named `stolon:master-pg10` that uses postgresql 10 you should execute:
1922

2023
```
21-
make PGVERSION=10 TAG=stolon:master-pg10
24+
make PGVERSION=10 TAG=stolon:master-pg10 docker
2225
```
2326

2427
Once the image is built you should push it to the docker registry used by your kubernetes infrastructure.
@@ -112,7 +115,7 @@ stolon-proxy-service <none> stolon-cluster=
112115

113116
#### Connect to the proxy service
114117

115-
The password for the stolon user will be the value specified in your `secret.yaml` above (or `password1` if you did not change it).
118+
The password for the stolon user will be the value specified in your `secret.yaml` above (or `password1` if you did not change it).
116119

117120
```
118121
psql --host 10.247.50.217 --port 5432 postgres -U stolon -W
@@ -209,4 +212,3 @@ For PostgreSQL major version upgrade, see [PostgreSQL upgrade](postgresql_upgrad
209212
For any PostgreSQL upgrade, check PostgreSQL release note for any additional upgrade note.
210213

211214
For stolon upgrade: TODO
212-

examples/kubernetes/image/docker/Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

examples/swarm/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ Additional images are available:
1414

1515
* `master-pg10`: automatically built after every commit to the master branch.
1616

17-
In the [image](../kubernetes/image/docker) directory you'll find a Makefile to build the image used in this example (starting from the official postgreSQL images). The Makefile generates the Dockefile from a template Dockerfile where you have to define the wanted postgres version and image tag (`PGVERSION` and `TAG` mandatory variables).
17+
In the [image](../kubernetes/image/docker) directory you'll find a Dockerfile to build the image used in this example (starting from the official postgreSQL images).
18+
19+
To build the image used in this example just execute (from the project root) `make` with the `docker` target providing the mandatory `PGVERSION` and `TAG` variables.
20+
1821
For example, if you want to build an image named `stolon:master-pg10` that uses postgresql 10 you should execute:
1922

2023
```
21-
make PGVERSION=10.3 TAG=stolon:master-pg10
24+
make PGVERSION=10 TAG=stolon:master-pg10 docker
2225
```
2326

2427
Once the image is built you should push it to the docker registry used by your swarm infrastructure.

scripts/build-binary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function main {
6262
export GOARCH="amd64"
6363

6464
pushd stolon >/dev/null
65-
./build
65+
make
6666
popd >/dev/null
6767

6868
TARGET="stolon-${VER}-${GOOS}-${GOARCH}"

scripts/semaphore-k8s.sh

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,10 @@ touch $HOME/.kube/config
2727
export KUBECONFIG=$HOME/.kube/config
2828
sudo -E minikube start --vm-driver=none
2929

30-
# Fix build to work with the right import path also when building github forked repositories
31-
if [[ ! -e ~/workspace/src/github.com/sorintlab/stolon ]]; then
32-
mkdir -p ~/workspace/src/github.com/sorintlab
33-
ln -s /home/runner/stolon ~/workspace/src/github.com/sorintlab/stolon
34-
fi
35-
3630
## Temporary hack disable checksum verification since semaphore has go 1.11.0 that had a bug causing different checksums than the right one generated by go 1.11.2
3731
rm go.sum
3832

39-
./build
40-
41-
42-
pushd examples/kubernetes/image/docker
43-
44-
make PGVERSION=10 TAG=stolon:master-pg10
45-
46-
popd
33+
make PGVERSION=10 TAG=stolon:master-pg10 docker
4734

4835
./bin/stolonctl --cluster-name kube-stolon --store-backend kubernetes --kube-resource-kind configmap init -y
4936

@@ -63,7 +50,7 @@ COUNT=0
6350
while [ $COUNT -lt 120 ]; do
6451
OUT=$(./bin/stolonctl --cluster-name kube-stolon --store-backend kubernetes --kube-resource-kind configmap clusterdata read | jq .cluster.status.phase)
6552
if [ "$OUT" == '"normal"' ]; then
66-
OK=true
53+
OK=true
6754
break
6855
fi
6956

@@ -82,4 +69,3 @@ if [ "$OK" != "true" ]; then
8269
fi
8370

8471
echo "stolon cluster successfully setup"
85-

scripts/semaphore.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs
2929
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main 11" > /etc/apt/sources.list.d/pgdg.list'
3030
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
3131
sudo apt-get update
32-
sudo apt-get -y install postgresql-9.5 postgresql-9.6 postgresql-10 postgresql-11 eatmydata
33-
34-
# Fix build to work with the right import path also when building github forked repositories
35-
if [[ ! -e ~/workspace/src/github.com/sorintlab/stolon ]]; then
36-
mkdir -p ~/workspace/src/github.com/sorintlab
37-
ln -s /home/runner/stolon ~/workspace/src/github.com/sorintlab/stolon
38-
fi
32+
sudo apt-get -y install postgresql-9.5 postgresql-9.6 postgresql-10 postgresql-11
3933

4034
# Run tests
4135
export ETCD_BIN="${PWD}/etcd/etcd-v3.2.11-linux-amd64/etcd"
@@ -58,8 +52,7 @@ export PARALLEL=5
5852
## Temporary hack disable checksum verification since semaphore has go 1.11.0 that had a bug causing different checksums than the right one generated by go 1.11.2
5953
rm go.sum
6054

61-
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+"$LD_LIBRARY_PATH:"}/usr/lib/libeatmydata
62-
LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so
55+
make
6356

6457
# Test with postgresql 9.5
6558
echo "===== Testing with postgreSQL 9.5 ====="

test

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Test script code thanks to coreos/etcd
44
#
5-
# Run all etcd tests
5+
# Run all tests
66
# ./test
77
# ./test -v
88
#
@@ -22,8 +22,6 @@ fi
2222
ORG_PATH="github.com/sorintlab"
2323
REPO_PATH="${ORG_PATH}/stolon"
2424

25-
./build
26-
2725
# test all packages excluding integration tests
2826
IGNORE_PKGS="(vendor/|tests/integration)"
2927
PACKAGES=$(find . -name \*_test.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
@@ -38,12 +36,12 @@ echo "Running tests..."
3836
COVER=${COVER:-"-cover"}
3937

4038
# Use only of specific go version to run gofmt since it'll break when we'll use go 1.10 and go 1.11
41-
GOFMT_VERSION="go1.11"
39+
GOFMT_VERSION="go1.13"
4240

4341
MAJOR_GOVERSION=$( echo -n $(go version) | grep -o 'go1\.[0-9]*' || true )
4442
if [ "${MAJOR_GOVERSION}" == "${GOFMT_VERSION}" ]; then
4543
echo "Checking gofmt..."
46-
fmtRes=$(gofmt -l $(find . -type f -name '*.go' ! -path './vendor/*'))
44+
fmtRes=$(gofmt -l $(find . -type f -name '*.go' ! -path './vendor/*' ! -path '*/\.*'))
4745
if [ -n "${fmtRes}" ]; then
4846
echo -e "gofmt checking failed:\n${fmtRes}"
4947
exit 255

0 commit comments

Comments
 (0)