forked from cyralinc/terraform-provider-cyral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (61 loc) · 3.06 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOFMT=gofmt
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOINSTALL=$(GOCMD) install
PROTOC=protoc
# Get latest version (tag). It is important to notice that the following
# commands restricts the build to those git-initialized folders. Thus,
# git clone the provider and run make on the same directory and avoid
# copying the source files to directories not initialized by git.
vVERSION:=$(shell git tag --sort v:refname | tail -n1)
VERSION:=$(shell git tag --sort v:refname | tail -n1 | sed 's/v//g')
VERSION+sha:=$(VERSION)+$(shell git rev-parse --short HEAD)
HOSTNAME=local
NAMESPACE=terraform
NAME=cyral
BINARY=terraform-provider-$(NAME)_$(vVERSION)
all: local/clean local/install local/test
local/build:
$(GOFMT) -w .
mkdir -p out/
# Build for both MacOS and Linux
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o out/darwin_amd64/$(BINARY) .
GOOS=linux GOARCH=amd64 $(GOBUILD) -o out/linux_amd64/$(BINARY) .
local/install: local/build
# Store in local registry to be used by Terraform 13 and 14
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
cp out/darwin_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
cp out/linux_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
docker/test:
docker-compose run -e CYRAL_TF_CONTROL_PLANE=$(CYRAL_TF_CONTROL_PLANE) -e CYRAL_TF_CLIENT_ID=$(CYRAL_TF_CLIENT_ID) \
-e CYRAL_TF_CLIENT_SECRET=$(CYRAL_TF_CLIENT_SECRET) -e TF_ACC=true \
app $(GOTEST) github.com/cyralinc/terraform-provider-cyral/... -v -race
docker/build:
docker-compose run app $(GOFMT) -w .
docker-compose run -e GOOS=darwin -e GOARCH=amd64 app $(GOBUILD) -o out/darwin_amd64/terraform-provider-cyral_v$(VERSION) .
docker-compose run -e GOOS=linux -e GOARCH=amd64 app $(GOBUILD) -o out/linux_amd64/terraform-provider-cyral_v$(VERSION) .
# Store in local registry to be used by Terraform 13 and 14
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
cp out/darwin_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
cp out/linux_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
clean: local/clean
local/clean:
$(GOCLEAN) -i github.com/cyralinc/terraform-provider-cyral/...
rm -f $(BINARY)
rm -rf ./out
rm -rf ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}
docker/clean:
docker-compose run app $(GOCLEAN) -i github.com/cyralinc/terraform-provider-cyral/...
rm -rf ./out
rm -rf ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}
local/test:
$(GOTEST) github.com/cyralinc/terraform-provider-cyral/... -v -race -timeout 20m
docker-compose/build: docker-compose/lint
docker-compose build --build-arg VERSION="$(VERSION+sha)" build
docker-compose/lint:
docker-compose run lint