Skip to content

Commit 691012a

Browse files
authored
Better release builds (textileio#600)
* Use make for build release work, streamline release Signed-off-by: Aaron Sutula <hi@asutula.com> * add build commands and use them for docker Signed-off-by: Aaron Sutula <hi@asutula.com>
1 parent 585db6f commit 691012a

11 files changed

Lines changed: 92 additions & 64 deletions

File tree

.bingo/Variables.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ $(BUF): .bingo/buf.mod
2222
@echo "(re)installing $(GOBIN)/buf-v0.20.5"
2323
@cd .bingo && $(GO) build -modfile=buf.mod -o=$(GOBIN)/buf-v0.20.5 "github.com/bufbuild/buf/cmd/buf"
2424

25+
GOMPLATE := $(GOBIN)/gomplate-v3.8.0
26+
$(GOMPLATE): .bingo/gomplate.mod
27+
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
28+
@echo "(re)installing $(GOBIN)/gomplate-v3.8.0"
29+
@cd .bingo && $(GO) build -modfile=gomplate.mod -o=$(GOBIN)/gomplate-v3.8.0 "github.com/hairyhenderson/gomplate/v3/cmd/gomplate"
30+
2531
GOVVV := $(GOBIN)/govvv-v0.3.0
2632
$(GOVVV): .bingo/govvv.mod
2733
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.

.bingo/gomplate.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
2+
3+
go 1.14
4+
5+
require github.com/hairyhenderson/gomplate/v3 v3.8.0 // cmd/gomplate

.bingo/variables.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ fi
1010

1111
BUF="${gobin}/buf-v0.20.5"
1212

13+
GOMPLATE="${gobin}/gomplate-v3.8.0"
14+
1315
GOVVV="${gobin}/govvv-v0.3.0"
1416

1517
GOX="${gobin}/gox-v1.0.1"

.github/workflows/release.yml

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Upload artifacts to release
2828
uses: AButler/upload-release-assets@v2.0
2929
with:
30-
files: 'powergate-docker-${{steps.latesttag.outputs.tag}}.zip'
30+
files: "powergate-docker-${{steps.latesttag.outputs.tag}}.zip"
3131
repo-token: ${{ secrets.GITHUB_TOKEN }}
3232
release-platform-builds:
3333
name: Release Builds
@@ -52,46 +52,14 @@ jobs:
5252
run: |
5353
export PATH=${PATH}:`go env GOPATH`/bin
5454
go get -v -t -d ./...
55-
- name: Build govvv
55+
- name: Build release artifacts
5656
run: |
57-
go build -modfile .bingo/govvv.mod -o=. github.com/ahmetb/govvv
58-
- name: Build gox
59-
run: |
60-
go build -modfile .bingo/gox.mod -o=. github.com/mitchellh/gox
61-
- name: Compile
62-
run: |
63-
VERSION=${GITHUB_REF##*/}
64-
./gox -osarch="linux/amd64 linux/386 linux/arm darwin/amd64 windows/amd64" -output="pow-{{.OS}}-{{.Arch}}" -ldflags="$(./govvv -flags -version $(VERSION) -pkg $(go list ./buildinfo))" ./cmd/pow
65-
- name: Collect artifacts
66-
run: |
67-
VERSION=${GITHUB_REF##*/}
68-
OUT=release/cli
69-
mkdir -p ${OUT}
70-
mkdir -p tmp
71-
cp LICENSE tmp/
72-
cp README.md tmp/
73-
cp dist/install tmp/
74-
cd tmp
75-
declare -a arr=("darwin-amd64" "linux-amd64" "linux-386" "linux-arm" "windows-amd64.exe")
76-
for i in "${arr[@]}"
77-
do
78-
OSARCH=${i%.*}
79-
EXT=$([[ "$i" = *.* ]] && echo ".${i##*.}" || echo '')
80-
cp ../pow-${i} pow${EXT}
81-
if [ "${EXT}" == ".exe" ]; then
82-
zip pow_${VERSION}_${OSARCH}.zip LICENSE README.md pow${EXT}
83-
mv pow_${VERSION}_${OSARCH}.zip ../${OUT}/
84-
else
85-
tar -czvf pow_${VERSION}_${OSARCH}.tar.gz LICENSE README.md install pow
86-
mv pow_${VERSION}_${OSARCH}.tar.gz ../${OUT}/
87-
fi
88-
done
89-
cd .. && rm -rf tmp
90-
echo $(ls ./release/cli)
57+
POW_VERSION=${GITHUB_REF##*/} make build-releases
58+
echo $(ls ./build/dist/)
9159
- name: Upload multiple assets to release
9260
uses: AButler/upload-release-assets@v2.0
9361
with:
94-
files: 'release/cli/pow_*;iplocation/maxmind/GeoLite2-City.mmdb'
62+
files: "build/dist/*;iplocation/maxmind/GeoLite2-City.mmdb"
9563
repo-token: ${{ secrets.GITHUB_TOKEN }}
9664
publish_js_grpc_lib:
9765
name: Publish JS gRPC bindings
@@ -111,19 +79,19 @@ jobs:
11179
- name: Set up Node
11280
uses: actions/setup-node@v1
11381
with:
114-
node-version: '12.x'
115-
registry-url: 'https://registry.npmjs.org'
82+
node-version: "12.x"
83+
registry-url: "https://registry.npmjs.org"
11684
- name: Install protoc
11785
uses: arduino/setup-protoc@master
11886
with:
119-
version: '3.11.2'
87+
version: "3.11.2"
12088
- name: Make version number
12189
id: makeversion
12290
uses: frabert/replace-string-action@v1.1
12391
with:
124-
pattern: 'v'
92+
pattern: "v"
12593
string: ${{steps.latesttag.outputs.tag}}
126-
replace-with: ''
94+
replace-with: ""
12795
- name: Generate JS gRPC bindings
12896
run: |
12997
./scripts/gen-js-protos.sh ${{steps.makeversion.outputs.replaced}} . ./js-grpc
@@ -152,9 +120,9 @@ jobs:
152120
id: makeversion
153121
uses: frabert/replace-string-action@v1.1
154122
with:
155-
pattern: 'v'
123+
pattern: "v"
156124
string: ${{steps.latesttag.outputs.tag}}
157-
replace-with: ''
125+
replace-with: ""
158126
- name: Generate Python gRPC bindings
159127
run: |
160128
./scripts/gen-py-protos.sh ${{steps.makeversion.outputs.replaced}} . ./py-grpc

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ myfile2
2828
pconfig.pow
2929

3030
tags
31+
32+
build/

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ WORKDIR /app
66
COPY go.mod go.sum ./
77
RUN go mod download
88
COPY . .
9-
RUN go build -modfile .bingo/govvv.mod -o=. github.com/ahmetb/govvv
10-
RUN pkg="$(go list ./buildinfo)" && govvvflags="$(./govvv -flags -pkg $pkg)" && CGO_ENABLED=0 GOOS=linux go build -ldflags="$govvvflags" -o powd cmd/powd/main.go
11-
RUN pkg="$(go list ./buildinfo)" && govvvflags="$(./govvv -flags -pkg $pkg)" && CGO_ENABLED=0 GOOS=linux go build -ldflags="$govvvflags" -o pow cmd/pow/main.go
12-
9+
RUN BUILD_FLAGS="CGO_ENABLED=0 GOOS=linux" make build-powd
10+
RUN BUILD_FLAGS="CGO_ENABLED=0 GOOS=linux" make build-pow
1311

1412
FROM alpine
1513
COPY --from=builder /app/iplocation/maxmind/GeoLite2-City.mmdb /app/GeoLite2-City.mmdb

Makefile

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,73 @@
1-
.DEFAULT_GOAL=build
1+
.DEFAULT_GOAL=install
22

33
include .bingo/Variables.mk
44

5-
BUILD_FLAGS=CGO_ENABLED=0
6-
GOVVV_FLAGS=$(shell $(GOVVV) -flags -pkg $(shell go list ./buildinfo))
5+
BUILD_FLAGS?=CGO_ENABLED=0
6+
POW_VERSION?="none"
7+
GOVVV_FLAGS=$(shell $(GOVVV) -flags -version $(POW_VERSION) -pkg $(shell go list ./buildinfo))
78

89
build: $(GOVVV)
9-
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./...
10+
$(BUILD_FLAGS) go build -ldflags="${GOVVV_FLAGS}" ./...
1011
.PHONY: build
1112

1213
build-pow: $(GOVVV)
13-
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./cmd/pow
14+
$(BUILD_FLAGS) go build -ldflags="${GOVVV_FLAGS}" ./cmd/pow
1415
.PHONY: build-pow
1516

1617
build-powd: $(GOVVV)
17-
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./cmd/powd
18+
$(BUILD_FLAGS) go build -ldflags="${GOVVV_FLAGS}" ./cmd/powd
1819
.PHONY: build-powd
1920

2021
build-powbench: $(GOVVV)
21-
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./cmd/powbench
22+
$(BUILD_FLAGS) go build -ldflags="${GOVVV_FLAGS}" ./cmd/powbench
2223
.PHONY: build-powbench
2324

25+
install: $(GOVVV)
26+
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./...
27+
.PHONY: install
28+
29+
install-pow: $(GOVVV)
30+
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./cmd/pow
31+
.PHONY: install-pow
32+
33+
install-powd: $(GOVVV)
34+
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./cmd/powd
35+
.PHONY: install-powd
36+
37+
install-powbench: $(GOVVV)
38+
$(BUILD_FLAGS) go install -ldflags="${GOVVV_FLAGS}" ./cmd/powbench
39+
.PHONY: install-powbench
40+
41+
define gen_release_files
42+
$(GOX) -osarch=$(3) -output="build/$(2)/$(2)_${POW_VERSION}_{{.OS}}-{{.Arch}}/$(2)" -ldflags="${GOVVV_FLAGS}" $(1)
43+
mkdir -p build/dist; \
44+
cd build/$(2); \
45+
for release in *; do \
46+
cp ../../LICENSE ../../README.md $${release}/; \
47+
if [[ $${release} != *"windows"* ]]; then \
48+
POW_FILE=$(2) $(GOMPLATE) -f ../../dist/install.tmpl -o "$${release}/install"; \
49+
tar -czvf ../dist/$${release}.tar.gz $${release}; \
50+
else \
51+
zip -r ../dist/$${release}.zip $${release}; \
52+
fi; \
53+
done
54+
endef
55+
56+
build-pow-release: $(GOX) $(GOVVV) $(GOMPLATE)
57+
$(call gen_release_files,./cmd/pow,pow,"linux/amd64 linux/386 linux/arm darwin/amd64 windows/amd64")
58+
.PHONY: build-release
59+
60+
build-powd-release: $(GOX) $(GOVVV) $(GOMPLATE)
61+
$(call gen_release_files,./cmd/powd,powd,"linux/amd64 darwin/amd64")
62+
.PHONY: build-release
63+
64+
build-powbench-release: $(GOX) $(GOVVV) $(GOMPLATE)
65+
$(call gen_release_files,./cmd/powbench,powbench,"linux/amd64 linux/386 linux/arm darwin/amd64 windows/amd64")
66+
.PHONY: build-release
67+
68+
build-releases: build-pow-release build-powd-release build-powbench-release
69+
.PHONY: build-releases
70+
2471
docs-pow:
2572
rm -rf ./cli-docs/pow
2673
go run ./cmd/pow/main.go docs ./cli-docs/pow

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ We have a CLI that supports most of Powergate features.
6868

6969
To build and install the CLI, run:
7070
```bash
71-
$ make build-pow
71+
$ make install-pow
7272
```
7373
The binary will be placed automatically in `$GOPATH/bin` which in general is in `$PATH`, so you can immediately run `pow` in your terminal.
7474

@@ -130,9 +130,9 @@ Powergate needs an offline geo-location database to resolve miners country using
130130
You can copy this file from the GitHub repo at `iplocation/maxmind/GeoLite2-City.mmdb`. If you run Powergate using Docker, this database is bundeled in the image so isn't necessary to have extra considerations.
131131

132132
### Server
133-
To build the Powergate server, run:
133+
To build and install the Powergate server, run:
134134
```bash
135-
make build-powd
135+
make install-powd
136136
```
137137
You can run the `-h` flag to see the configurable flags:
138138
```bash

cmd/powbench/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Powergate `powbench` is an utility tool that allows to run benchmark scenarios a
55
To build and install `powbench`, from the root of the Powergate repo, run:
66

77
```bash
8-
> make build-powbench
8+
> make install-powbench
99
> powbench -h
1010
Usage of powbench:
1111
--maxParallel int Max parallel file storage (default 1)

dist/install renamed to dist/install.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ set -Eeuo pipefail
88

99
INSTALL_DIR="$(dirname "$0")"
1010

11-
pow="$INSTALL_DIR/pow"
11+
file="$INSTALL_DIR/{{ .Env.POW_FILE }}"
1212
binpaths="/usr/local/bin /usr/bin"
1313

1414
# This variable contains a nonzero length string in case the script fails
1515
# because of missing write permissions.
1616
is_write_perm_missing=""
1717

1818
for binpath in $binpaths; do
19-
if mv "$pow" "$binpath/$pow" 2>/dev/null; then
20-
echo "Moved $pow to $binpath"
19+
if mv "$file" "$binpath/$file" 2>/dev/null; then
20+
echo "Moved $file to $binpath"
2121
exit 0
2222
else
2323
if test -d "$binpath" && ! test -w "$binpath"; then
@@ -26,7 +26,7 @@ for binpath in $binpaths; do
2626
fi
2727
done
2828

29-
echo "We cannot install $pow in one of the directories $binpaths"
29+
echo "We cannot install $file in one of the directories $binpaths"
3030

3131
if test -n "$is_write_perm_missing"; then
3232
echo "It seems that we do not have the necessary write permissions."

0 commit comments

Comments
 (0)