From 14ba013e6ce065e649b3818a1dcd6141ae8b3f37 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Wed, 2 Jan 2019 20:54:36 -0800 Subject: [PATCH] Build wal-g binary for alpine Signed-off-by: Tamal Saha --- Makefile | 18 +++++++++++++++++- build-alpine.sh | 37 +++++++++++++++++++++++++++++++++++++ docker/go-alpine/Dockerfile | 4 ++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 build-alpine.sh create mode 100644 docker/go-alpine/Dockerfile diff --git a/Makefile b/Makefile index c686e9a7e..388a8b033 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ CMD_FILES = $(wildcard cmd/wal-g/*.go) 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) @@ -33,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 diff --git a/build-alpine.sh b/build-alpine.sh new file mode 100755 index 000000000..e7a4e949e --- /dev/null +++ b/build-alpine.sh @@ -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/ diff --git a/docker/go-alpine/Dockerfile b/docker/go-alpine/Dockerfile new file mode 100644 index 000000000..629615c21 --- /dev/null +++ b/docker/go-alpine/Dockerfile @@ -0,0 +1,4 @@ +FROM golang:1.11-alpine + +RUN apk add --update --no-cache ca-certificates cmake bash build-base git +