Skip to content

Commit 5685f63

Browse files
committed
Build into local directories rather than $GOPATH/bin
This makes it a bit easier to setup the project and allows it to be outside of $GOPATH/src. Issue: [ch9453]
1 parent 2ca733f commit 5685f63

File tree

9 files changed

+55
-97
lines changed

9 files changed

+55
-97
lines changed

Makefile

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
GOPATH ?= $(HOME)/odev/go
2-
GOBIN ?= $(GOPATH)/bin
31

42
# Default values if not already set
53
ANSIBLE_VERSION ?= 2.9.*
6-
PGOROOT ?= $(GOPATH)/src/github.com/crunchydata/postgres-operator
4+
PGOROOT ?= $(CURDIR)
75
PGO_BASEOS ?= centos7
86
PGO_CMD ?= kubectl
97
PGO_IMAGE_PREFIX ?= crunchydata
@@ -73,10 +71,12 @@ ifeq ("$(PGO_BASEOS)", "centos8")
7371
endif
7472

7573
DEBUG_BUILD ?= false
76-
GCFLAGS=
74+
GO_BUILD = $(GO_CMD) build
75+
GO_CMD = $(GO_ENV) go
76+
7777
# Disable optimizations if creating a debug build
7878
ifeq ("$(DEBUG_BUILD)", "true")
79-
GCFLAGS=all=-N -l
79+
GO_BUILD += -gcflags='all=-N -l'
8080
endif
8181

8282
# To build a specific image, run 'make <name>-image' (e.g. 'make pgo-apiserver-image')
@@ -92,76 +92,65 @@ images = pgo-apiserver \
9292
crunchy-postgres-exporter \
9393
postgres-operator
9494

95-
.PHONY: all installrbac setup setupnamespaces cleannamespaces bounce \
96-
deployoperator runmain runapiserver cli-docs clean push pull \
97-
release default
95+
.PHONY: all installrbac setup setupnamespaces cleannamespaces \
96+
deployoperator cli-docs clean push pull release
9897

9998

10099
#======= Main functions =======
101100
all: linuxpgo $(images:%=%-image)
102101

103102
installrbac:
104-
cd deploy && ./install-rbac.sh
103+
PGOROOT='$(PGOROOT)' ./deploy/install-rbac.sh
105104

106105
setup:
107-
./bin/get-deps.sh
106+
PGOROOT='$(PGOROOT)' ./bin/get-deps.sh
108107

109108
setupnamespaces:
110-
cd deploy && ./setupnamespaces.sh
109+
PGOROOT='$(PGOROOT)' ./deploy/setupnamespaces.sh
111110

112111
cleannamespaces:
113-
cd deploy && ./cleannamespaces.sh
114-
115-
bounce:
116-
$(PGO_CMD) \
117-
--namespace=$(PGO_OPERATOR_NAMESPACE) \
118-
get pod \
119-
--selector=name=postgres-operator \
120-
-o=jsonpath="{.items[0].metadata.name}" \
121-
| xargs $(PGO_CMD) --namespace=$(PGO_OPERATOR_NAMESPACE) delete pod
112+
PGOROOT='$(PGOROOT)' ./deploy/cleannamespaces.sh
122113

123114
deployoperator:
124-
cd deploy && ./deploy.sh
115+
PGOROOT='$(PGOROOT)' ./deploy/deploy.sh
125116

126117

127118
#======= Binary builds =======
128119
build-pgo-apiserver:
129-
go install -gcflags='$(GCFLAGS)' apiserver.go
130-
cp $(GOBIN)/apiserver bin/
120+
$(GO_BUILD) -o bin/apiserver apiserver.go
131121

132122
build-pgo-backrest:
133-
go install -gcflags='$(GCFLAGS)' pgo-backrest/pgo-backrest.go
134-
cp $(GOBIN)/pgo-backrest bin/pgo-backrest/
123+
$(GO_BUILD) -o bin/pgo-backrest/pgo-backrest pgo-backrest/pgo-backrest.go
135124

136125
build-pgo-rmdata:
137-
go install -gcflags='$(GCFLAGS)' pgo-rmdata/pgo-rmdata.go
138-
cp $(GOBIN)/pgo-rmdata bin/pgo-rmdata/
126+
$(GO_BUILD) -o bin/pgo-rmdata/pgo-rmdata pgo-rmdata/pgo-rmdata.go
139127

140128
build-pgo-scheduler:
141-
go install -gcflags='$(GCFLAGS)' pgo-scheduler/pgo-scheduler.go
142-
cp $(GOBIN)/pgo-scheduler bin/pgo-scheduler/
129+
$(GO_BUILD) -o bin/pgo-scheduler/pgo-scheduler pgo-scheduler/pgo-scheduler.go
143130

144131
build-postgres-operator:
145-
go install -gcflags='$(GCFLAGS)' postgres-operator.go
146-
cp $(GOBIN)/postgres-operator bin/postgres-operator/
132+
$(GO_BUILD) -o bin/postgres-operator postgres-operator.go
147133

148134
build-pgo-client:
149-
go install -gcflags='$(GCFLAGS)' pgo/pgo.go
150-
cp $(GOBIN)/pgo bin/pgo
135+
$(GO_BUILD) -o bin/pgo pgo/pgo.go
151136

152137
build-pgo-%:
153138
$(info No binary build needed for $@)
154139

155140
build-crunchy-postgres-exporter:
156141
$(info No binary build needed for $@)
157142

158-
linuxpgo: build-pgo-client
143+
linuxpgo: GO_ENV += GOOS=linux GOARCH=amd64
144+
linuxpgo:
145+
$(GO_BUILD) -o bin/pgo pgo/pgo.go
159146

147+
macpgo: GO_ENV += GOOS=darwin GOARCH=amd64
160148
macpgo:
161-
cd pgo && env GOOS=darwin GOARCH=amd64 go build pgo.go && mv pgo $(GOBIN)/pgo-mac
149+
$(GO_BUILD) -o bin/pgo-mac pgo/pgo.go
162150

151+
winpgo: GO_ENV += GOOS=windows GOARCH=386
163152
winpgo:
164-
cd pgo && env GOOS=windows GOARCH=386 go build pgo.go && mv pgo.exe $(GOBIN)/pgo.exe
153+
$(GO_BUILD) -o bin/pgo.exe pgo/pgo.go
165154

166155

167156
#======= Image builds =======
@@ -221,11 +210,19 @@ cli-docs:
221210
cd $(PGOROOT)/docs/content/operatorcli/cli && go run $(PGOROOT)/pgo/generatedocs.go
222211

223212
clean: clean-deprecated
224-
rm -rf $(GOPATH)/pkg/* $(GOBIN)/postgres-operator $(GOBIN)/apiserver $(GOBIN)/*pgo
213+
rm -f bin/apiserver
214+
rm -f bin/postgres-operator
215+
rm -f bin/pgo bin/pgo-mac bin/pgo.exe
216+
rm -f bin/pgo-backrest/pgo-backrest
217+
rm -f bin/pgo-rmdata/pgo-rmdata
218+
rm -f bin/pgo-scheduler/pgo-scheduler
225219

226220
clean-deprecated:
227221
@# packages used to be downloaded into the vendor directory
228222
[ ! -d vendor ] || rm -r vendor
223+
@# executables used to be compiled into the $GOBIN directory
224+
[ ! -n '$(GOBIN)' ] || rm -f $(GOBIN)/postgres-operator $(GOBIN)/apiserver $(GOBIN)/*pgo
225+
[ ! -d bin/postgres-operator ] || rm -r bin/postgres-operator
229226

230227
push: $(images:%=push-%) ;
231228

@@ -243,9 +240,9 @@ release: linuxpgo macpgo winpgo
243240
cp -r $(PGOROOT)/examples $(RELTMPDIR)
244241
cp -r $(PGOROOT)/deploy $(RELTMPDIR)
245242
cp -r $(PGOROOT)/conf $(RELTMPDIR)
246-
cp $(GOBIN)/pgo $(RELTMPDIR)
247-
cp $(GOBIN)/pgo-mac $(RELTMPDIR)
248-
cp $(GOBIN)/pgo.exe $(RELTMPDIR)
243+
cp bin/pgo $(RELTMPDIR)
244+
cp bin/pgo-mac $(RELTMPDIR)
245+
cp bin/pgo.exe $(RELTMPDIR)
249246
cp $(PGOROOT)/examples/pgo-bash-completion $(RELTMPDIR)
250247
tar czvf $(RELFILE) -C $(RELTMPDIR) .
251248

bin/.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
apiserver
2-
pgo
1+
/apiserver
2+
/pgo
3+
/pgo-mac
4+
/pgo.exe
5+
/postgres-operator

bin/get-deps.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ BINDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1818
EVTDIR="$BINDIR/pgo-event"
1919
POSTGRES_EXPORTER_VERSION=0.8.0
2020

21-
# Precondition checks
22-
if [ "$GOPATH" = "" ]; then
23-
# Alternatively, take dep approach of go env GOPATH later in the process
24-
echo "GOPATH not defined, exiting..." >&2
25-
exit 1
26-
fi
27-
if ! (echo $PATH | egrep -q "$GOPATH/bin") ; then
28-
echo '$GOPATH/bin not part of $PATH, exiting...' >&2
29-
exit 2
30-
fi
31-
3221

3322
# Idempotent installations
3423
if (yum repolist | egrep -q '^epel/') ; then

bin/postgres-operator/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin/postgres-operator/README.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

deploy/upgrade-pgo.sh

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,12 @@ read -n1 -rsp $'Press any key to continue the upgrade or Ctrl+C to exit...\n'
3131
# Remove the current Operator
3232
$DIR/cleanup.sh
3333

34-
# Set up the defined namespaces for use with the new Operator version
35-
$DIR/setupnamespaces.sh
36-
37-
# Install the correct RBAC
38-
$DIR/install-rbac.sh
39-
4034
# Deploy the new Operator
41-
$DIR/deploy.sh
42-
43-
# Store the current location of the PGO client
44-
MYPGO=`which pgo`
45-
# Store the expected location of the PGO client
46-
BASHPGO="${GOBIN}/pgo"
47-
48-
if [ "$MYPGO" != "$BASHPGO" ]; then
49-
50-
echo "Current location\(${MYPG}O\) does not match the expected location \(${BASHPGO}\). You will need to manually install the updated Posgres Operator client in your preferred location."
35+
make -C "$(dirname $DIR)" setupnamespaces installrbac deployoperator build-pgo-client
5136

52-
else
53-
# install the new PGO client
54-
go install $PGOROOT/pgo/pgo.go
55-
cp $GOBIN/pgo $PGOROOT/bin/pgo
37+
if [ ! "$(command -v pgo)" -ef "$(dirname $DIR)/bin/pgo" ]; then
38+
echo "Current location ($(command -v pgo)) does not match the expected location ($(dirname $DIR)/bin/pgo)." \
39+
'You will need to manually install the updated Postgres Operator client in your preferred location.'
5640
fi
5741

5842
# Final instructions

docs/content/contributing/developer-setup.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ The following environment variables are expected by the steps in this guide:
2121

2222
Variable | Example | Description
2323
-------- | ------- | -----------
24-
`GOPATH` | $HOME/odev | Golang project directory
25-
`PGOROOT` | $GOPATH/src/github.com/crunchydata/postgres-operator | Operator repository location
24+
`PGOROOT` | $HOME/postgres-operator | Operator repository location
2625
`PGO_CONF_DIR` | $PGOROOT/installers/ansible/roles/pgo-operator/files | Operator Config Template Directory
2726
`PGO_BASEOS` | {{< param centosBase >}} | Base OS for container images
2827
`PGO_CMD` | kubectl | Cluster management tool executable
@@ -38,9 +37,7 @@ Variable | Example | Description
3837
## Other requirements
3938

4039
* The development host has been created, has access to `yum` updates, and has a regular user account with `sudo` rights to run `yum`.
41-
* `GOPATH` points to a directory containing `src`,`pkg`, and `bin` directories.
42-
* The development host has `$GOPATH/bin` added to its `PATH` environment variable. Development tools will be installed to this path. Defining a `GOBIN` environment variable other than `$GOPATH/bin` may yield unexpected results.
43-
* The development host has `git` installed and has cloned the postgres-operator repository to `$GOPATH/src/github.com/crunchydata/postgres-operator`. Makefile targets below are run from the repository directory.
40+
* The development host has `git` installed and has cloned the [postgres-operator](https://github.com/CrunchyData/postgres-operator.git) repository. Makefile targets below are run from the repository directory.
4441
* Deploying the Operator will require deployment access to a Kubernetes or OpenShift cluster
4542
* Once you have cloned the git repository, you will need to download the CentOS 7 repository files and GPG keys and place them in the `$PGOROOT/conf` directory. You can do so with the following code:
4643

@@ -61,7 +58,6 @@ Configuring build dependencies is automated via the `setup` target in the projec
6158

6259
The setup target ensures the presence of:
6360

64-
* `GOPATH` and `PATH` as described in the prerequisites
6561
* EPEL yum repository
6662
* [`go`](https://golang.org/) compiler version 1.13+
6763
* NSQ messaging binaries
@@ -109,7 +105,7 @@ This assumes you have Docker installed and running on your development host.
109105
By default, the Makefile will use buildah to build the container images, to override this default to use docker to build the images, set the IMGBUILDER variable to `docker`
110106

111107

112-
After a full compile, you will have a `pgo` binary in `$HOME/odev/bin` and the Operator images in your local Docker registry.
108+
After a full compile, you will have a `pgo` binary in `$PGOROOT/bin` and the Operator images in your local Docker registry.
113109

114110
# Deployment
115111

docs/content/installation/other/bash.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ weight: 100
77

88
A full installation of the Operator includes the following steps:
99

10-
- create a project structure
10+
- get the Operator project
1111
- configure your environment variables
1212
- configure Operator templates
1313
- create security resources
@@ -23,24 +23,18 @@ The Operator can be deployed by multiple methods including:
2323
* Openshift Console installation using OLM
2424

2525

26-
## Default Installation - Create Project Structure
26+
## Default Installation - Get Project
2727

28-
The Operator follows a golang project structure, you can create a structure as follows on your local Linux host:
28+
The Operator project is hosted on GitHub. You can get a copy using `git clone`:
2929

30-
mkdir -p $HOME/odev/src/github.com/crunchydata $HOME/odev/bin $HOME/odev/pkg
31-
cd $HOME/odev/src/github.com/crunchydata
32-
git clone https://github.com/CrunchyData/postgres-operator.git
30+
git clone -b v{{< param operatorVersion >}} https://github.com/CrunchyData/postgres-operator.git
3331
cd postgres-operator
34-
git checkout v{{< param operatorVersion >}}
35-
36-
37-
This creates a directory structure under your HOME directory name *odev* and clones the current Operator version to that structure.
3832

3933
## Default Installation - Configure Environment
4034

4135
Environment variables control aspects of the Operator installation. You can copy a sample set of Operator environment variables and aliases to your *.bashrc* file to work with.
4236

43-
cat $HOME/odev/src/github.com/crunchydata/postgres-operator/examples/envs.sh >> $HOME/.bashrc
37+
cat ./examples/envs.sh >> $HOME/.bashrc
4438
source $HOME/.bashrc
4539

4640
## Default Installation - Namespace Creation

examples/envs.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
export GOPATH=$HOME/odev
2-
export GOBIN=$GOPATH/bin
3-
export PATH=$PATH:$GOBIN
41
# NAMESPACE is the list of namespaces the Operator will watch
52
export NAMESPACE=pgouser1,pgouser2
63

@@ -15,7 +12,7 @@ export PGO_OPERATOR_NAMESPACE=pgo
1512
export PGO_CMD=kubectl
1613

1714
# the directory location of the Operator scripts
18-
export PGOROOT=$GOPATH/src/github.com/crunchydata/postgres-operator
15+
export PGOROOT=$HOME/postgres-operator
1916

2017
# the directory location of the Json Config Templates
2118
export PGO_CONF_DIR=$PGOROOT/installers/ansible/roles/pgo-operator/files

0 commit comments

Comments
 (0)