Skip to content

Commit

Permalink
Merge pull request #8 from Cimpress-MCP/static_link
Browse files Browse the repository at this point in the history
  • Loading branch information
calvn authored Jun 28, 2016
2 parents 3f9919e + 0a56119 commit af9a2c8
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ remove-dangling:

run-build-image:
@echo " ===> Building..."
@docker run --rm --name git2consul-builder -v $(CURDIR):/app -v $(CURDIR)/build/bin:/build/bin cimpress/git2consul-builder
@docker run --rm --name git2consul-builder -v $(CURDIR):/app -v $(CURDIR)/build/bin:/build/bin --entrypoint /app/build/build.sh cimpress/git2consul-builder
.PHONY: run-build-image
7 changes: 5 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
FROM alpine:edge
MAINTAINER Calvin Leung Huang <https://github.com/cleung2010>

RUN apk --no-cache --no-progress add ca-certificates git libssh2 openssl \
RUN echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories

RUN apk update
RUN apk --no-cache --no-progress add ca-certificates git go gcc musl-dev make cmake http-parser@testing perl \
&& rm -rf /var/cache/apk/*

COPY . /build
WORKDIR /app

RUN /build/configure.sh

ENTRYPOINT ["/build/build.sh"]
ENTRYPOINT ["/app/build/build.sh"]
15 changes: 12 additions & 3 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ set -e
export GOPATH=/tmp/go
export PATH=${PATH}:${GOPATH}/bin
export BUILDPATH=${GOPATH}/src/github.com/Cimpress-MCP/go-git2consul
export PKG_CONFIG_PATH="/usr/lib/pkgconfig/:/usr/local/lib/pkgconfig/"
export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/tmp/libgit2/install/lib/pkgconfig:/tmp/openssl/install/lib/pkgconfig:/tmp/libssh2/build/src"

FLAGS=$(pkg-config --static --libs --cflags libssh2 libgit2) || exit 1
export CGO_LDFLAGS="/tmp/libgit2/build/libgit2.a /tmp/openssl/libcrypto.a /tmp/openssl/libssl.a /tmp/libssh2/build/src/libssh2.a -L/tmp/libgit2/build ${FLAGS}"
export CGO_CFLAGS="-I/tmp/libgit2/include"

# Get git commit information
GIT_COMMIT=$(git rev-parse HEAD)
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)

# Build git2consul
cd ${BUILDPATH}
go get -v
GOOS=linux GOARCH=amd64 go build -o /build/bin/git2consul.linux.amd64 .
go get -v -d
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -v -linkmode=external -extldflags '-static'" -o /build/bin/git2consul.linux.amd64 .
# GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -o /build/bin/git2consul.darwin.amd64 .
8 changes: 4 additions & 4 deletions build/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export GOPATH=/tmp/go
export PATH=${PATH}:${GOPATH}/bin
export BUILDPATH=${GOPATH}/src/github.com/Cimpress-MCP/go-git2consul
export PKG_CONFIG_PATH="/usr/lib/pkgconfig/:/usr/local/lib/pkgconfig/"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/tmp/libgit2/install/lib/pkgconfig:/tmp/openssl/install/lib/pkgconfig:/tmp/libssh2/build/src"

# Install build deps
apk --no-cache --no-progress --virtual build-deps add go gcc musl-dev make cmake openssl-dev libssh2-dev

# Install libgit2
# Install libraries
/build/install-openssl.sh
/build/install-libssh2.sh
/build/install-libgit2.sh

# Set up go environment
Expand Down
13 changes: 10 additions & 3 deletions build/install-libgit2.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
#!/bin/sh
set -x
set -e

# Set temp environment vars
export LIBGIT2REPO=https://github.com/libgit2/libgit2.git
export LIBGIT2BRANCH=v0.24.0
export LIBGIT2PATH=/tmp/libgit2
export PKG_CONFIG_PATH="/usr/lib/pkgconfig/:/usr/local/lib/pkgconfig/"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/tmp/libgit2/install/lib/pkgconfig:/tmp/openssl/install/lib/pkgconfig:/tmp/libssh2/build/src"

# Compile & Install libgit2 (v0.23)
git clone -b ${LIBGIT2BRANCH} --depth 1 -- ${LIBGIT2REPO} ${LIBGIT2PATH}

mkdir -p ${LIBGIT2PATH}/build
cd ${LIBGIT2PATH}/build
cmake -DBUILD_CLAR=OFF ..
cmake -DTHREADSAFE=ON \
-DBUILD_CLAR=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_FLAGS=-fPIC \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_INSTALL_PREFIX=../install \
..
cmake --build . --target install

# Cleanup
rm -r ${LIBGIT2PATH}
# rm -r ${LIBGIT2PATH}
26 changes: 26 additions & 0 deletions build/install-libssh2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
set -x

# Set temp environment vars
export REPO=https://github.com/libssh2/libssh2
export BRANCH=libssh2-1.7.0
export REPO_PATH=/tmp/libssh2
export PKG_CONFIG_PATH="/usr/lib/pkgconfig/:/usr/local/lib/pkgconfig/"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/tmp/libgit2/install/lib/pkgconfig:/tmp/openssl/install/lib/pkgconfig:/tmp/libssh2/build/src"

# Compile & Install libgit2 (v0.23)
git clone -b ${BRANCH} --depth 1 -- ${REPO} ${REPO_PATH}

mkdir -p ${REPO_PATH}/build
cd ${REPO_PATH}/build
cmake -DTHREADSAFE=ON \
-DBUILD_CLAR=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_FLAGS=-fPIC \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_INSTALL_PREFIX=../install \
..
cmake --build . --target install

# Cleanup
# rm -r ${LIBGIT2PATH}
21 changes: 21 additions & 0 deletions build/install-openssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -x
set -e

# Set temp environment vars
export REPO=https://github.com/openssl/openssl.git
export BRANCH=OpenSSL_1_0_2h
export BUILD_PATH=/tmp/openssl

# Compile & Install libgit2 (v0.23)
git clone -b ${BRANCH} --depth 1 -- ${REPO} ${BUILD_PATH}

mkdir -p ${BUILD_PATH}/install/lib
cd ${BUILD_PATH}
./config threads no-shared --prefix=${BUILD_PATH}/install -fPIC -DOPENSSL_PIC &&
make depend &&
make &&
make install

# Cleanup
# rm -r ${LIBGIT2PATH}

0 comments on commit af9a2c8

Please sign in to comment.