Skip to content

Commit

Permalink
Build wal-g binary for alpine
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored and the-redback committed Mar 1, 2019
1 parent 24dd6e0 commit cd0fbf0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PKG_FILES = $(wildcard internal/**/*.go internal/**/**/*.go internal/*.go)
TEST_FILES = $(wildcard test/*.go testtools/*.go)
PKG := github.com/wal-g/wal-g

.PHONY: test fmt lint all install clean
.PHONY: test fmt lint all install clean alpine

ifdef GOTAGS
override GOTAGS := -tags $(GOTAGS)
Expand Down Expand Up @@ -34,3 +34,18 @@ clean:

build: $(CMD_FILES) $(PKG_FILES)
(cd cmd/wal-g && go build $(GOTAGS) -ldflags "-s -w -X main.BuildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X main.GitRevision=`git rev-parse --short HEAD` -X main.WalgVersion=`git tag -l --points-at HEAD`")

alpine: $(CMD_FILES) $(PKG_FILES)
rm -rf .brotli.tmp
rm -rf ./vendor/github.com/google/brotli/dist
docker build --pull -t wal-g/golang:1.11-alpine ./docker/go-alpine
docker run \
--rm \
-u $$(id -u):$$(id -g) \
-v /tmp:/.cache \
-v "$$(pwd):/go/src/$(PKG)" \
-w /go/src/$(PKG) \
-e GOOS=linux \
-e GOARCH=amd64 \
wal-g/golang:1.11-alpine \
./build-alpine.sh
37 changes: 37 additions & 0 deletions build-alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
set -e -x

if ! which dep > /dev/null; then
go get -u github.com/golang/dep/cmd/dep # install dependencies management system
fi

make deps # install dependencies

test -d tmp || mkdir tmp

cp -rf vendor/github.com/google/brotli/* tmp/
cp -rf submodules/brotli/* vendor/github.com/google/brotli/

readonly CWD=$PWD

cd vendor/github.com/google/brotli/go/cbrotli

readonly LIB_DIR=../../dist # dist will contain binaries and it is in the google/brotli/.gitignore

# patch cgo.go to force usage of static libraries for linking
sed -i -e "s|#cgo LDFLAGS: -lbrotlicommon|#cgo CFLAGS: -I../../c/include|" cgo.go
sed -i -e "s|\(#cgo LDFLAGS:\) \(-lbrotli.*\)|\1 -L$LIB_DIR \2-static -lbrotlicommon-static|" cgo.go
sed -i -e "/ -lm$/ n; /brotlienc/ s|$| -lm|" cgo.go

mkdir -p ${LIB_DIR}

cd ${LIB_DIR}
../configure-cmake --disable-debug
make

cd ${CWD}
make

rm -rf vendor/github.com/google/brotli/*
mv tmp/* vendor/github.com/google/brotli/
rm -rf tmp/
4 changes: 4 additions & 0 deletions docker/go-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM golang:1.11-alpine

RUN apk add --update --no-cache ca-certificates cmake bash build-base git

0 comments on commit cd0fbf0

Please sign in to comment.