diff --git a/contrib/docker-build/Makefile b/contrib/docker-build/Makefile new file mode 100644 index 00000000000..c47a6e5a5d1 --- /dev/null +++ b/contrib/docker-build/Makefile @@ -0,0 +1,4 @@ +install: + @docker-compose up + @sudo chown $(USER) ../../dgraph/dgraph + @mv ../../dgraph/dgraph $(GOPATH)/bin diff --git a/contrib/docker-build/README.md b/contrib/docker-build/README.md new file mode 100644 index 00000000000..415e04bedb3 --- /dev/null +++ b/contrib/docker-build/README.md @@ -0,0 +1,13 @@ +# Docker build script + +This directory contains a Makefile that can be used to build Dgraph inside the +official Dgraph Docker container. This is useful for situations when the host +system cannot be used to build a binary that will work with the container (for +example, if the host system has a different version of glibc). + +## Usage + +Run `make install` in this directory. The script will ask you for your password +in order to change ownership of the compiled binary. By default, files written +by Docker will be owned by root. This script also takes care of moving the +binary to $GOPATH/bin. diff --git a/contrib/docker-build/build.sh b/contrib/docker-build/build.sh new file mode 100755 index 00000000000..d8b66d25d23 --- /dev/null +++ b/contrib/docker-build/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export DEBIAN_FRONTEND=noninteractive +apt-get update +apt-get install -y build-essential git golang +cd /dgraph/dgraph +make diff --git a/contrib/docker-build/docker-compose.yml b/contrib/docker-build/docker-compose.yml new file mode 100644 index 00000000000..da1339b06a8 --- /dev/null +++ b/contrib/docker-build/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.5" +services: + build: + image: dgraph/dgraph:latest + container_name: build + working_dir: /data/build + labels: + cluster: test + service: build + volumes: + - type: bind + source: ../../ + target: /dgraph + command: /dgraph/contrib/docker-build/build.sh diff --git a/dgraph/Makefile b/dgraph/Makefile index f15a6faba7f..e65fc8aea56 100644 --- a/dgraph/Makefile +++ b/dgraph/Makefile @@ -14,6 +14,7 @@ # limitations under the License. # +USER_ID = $(shell id -u) BIN = dgraph BUILD ?= $(shell git rev-parse --short HEAD) BUILD_CODENAME = unnamed @@ -90,14 +91,18 @@ install: jemalloc jemalloc: @if [ -z "$(HAS_JEMALLOC)" ] ; then \ - mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; \ - echo "Downloading jemalloc" ; \ - curl -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; \ - tar xjf ./jemalloc.tar.bz2 ; \ - cd jemalloc-5.2.1 ; \ - ./configure --with-jemalloc-prefix='je_' ; \ - make ; \ - echo "==== Need sudo access to install jemalloc" ; \ - sudo make install ; \ + mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; \ + echo "Downloading jemalloc" ; \ + curl -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; \ + tar xjf ./jemalloc.tar.bz2 ; \ + cd jemalloc-5.2.1 ; \ + ./configure --with-jemalloc-prefix='je_' ; \ + make ; \ + if [ "$(USER_ID)" = "0" ]; then \ + make install ; \ + else \ + echo "==== Need sudo access to install jemalloc" ; \ + sudo make install ; \ + fi \ fi