Created
December 18, 2016 12:37
-
-
Save Ehekatl/93b4ac1621771f2889cd99c7b7cfc2ec to your computer and use it in GitHub Desktop.
git2go static compile environment on Amazon Linux with docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM lambdalinux/baseimage-amzn:latest | |
CMD ["/sbin/my_init"] | |
RUN yum update -y && yum install -y yum-plugin-ovl && yum install -y \ | |
gcc \ | |
make \ | |
cmake \ | |
git \ | |
libcurl-devel \ | |
openssl-static \ | |
zlib-devel \ | |
libssh2-devel \ | |
wget \ | |
tar | |
ENV GOLANG_VERSION=1.7 | |
ENV LIBSSH2_VERSION=1.8.0 | |
ENV GOLANG_DOWNLOAD_URL=https://s3.cn-north-1.amazonaws.com.cn/strikingly-morpheus/public/go$GOLANG_VERSION.linux-amd64.tar.gz \ | |
GOLANG_DOWNLOAD_SHA256=702ad90f705365227e902b42d91dd1a40e48ca7f67a2f4b2fd052aaa4295cd95 \ | |
LIBGIT=/libgit2 \ | |
LIBGIT_BRANCH=maint/v0.24 \ | |
LIBGIT_BUILD=/libgit2/build | |
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ | |
&& echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ | |
&& tar -C /usr/local -xzf golang.tar.gz \ | |
&& rm golang.tar.gz | |
ENV GOPATH /go | |
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH | |
# libssh2 version need > 1.6.0, compile it with both static and dynamic version for link libgit2 | |
RUN curl -fSL "https://www.libssh2.org/download/libssh2-$LIBSSH2_VERSION.tar.gz" -o libssh2.tar.gz \ | |
&& tar -C /tmp -xzf libssh2.tar.gz \ | |
&& mkdir -p "/tmp/libssh2-$LIBSSH2_VERSION/bin" && cd "/tmp/libssh2-$LIBSSH2_VERSION/bin" \ | |
&& cmake .. \ | |
-DBUILD_SHARED_LIBS=OFF \ | |
-DCMAKE_INSTALL_PREFIX=/usr \ | |
&& cmake --build . \ | |
&& cmake --build . --target install \ | |
&& rm -rf * \ | |
&& cmake .. \ | |
-DBUILD_SHARED_LIBS=ON \ | |
-DCMAKE_INSTALL_PREFIX=/usr \ | |
&& cmake --build . \ | |
&& cmake --build . --target install | |
# Install gb and static compile libgit2 | |
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" \ | |
&& go get github.com/constabulary/gb/... \ | |
&& git clone -b "$LIBGIT_BRANCH" https://github.com/libgit2/libgit2.git $LIBGIT \ | |
&& mkdir -p $LIBGIT_BUILD && cd $LIBGIT_BUILD && cmake .. \ | |
-DTHREADSAFE=ON \ | |
-DBUILD_CLAR=OFF \ | |
-DBUILD_SHARED_LIBS=OFF \ | |
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ | |
-DCMAKE_INSTALL_PREFIX=/usr \ | |
-DCMAKE_C_FLAGS=-fPIC \ | |
&& cmake --build . \ | |
&& cmake --build . --target install | |
RUN echo "/usr/lib64" >> /etc/ld.so.conf.d/libssh2.conf \ | |
&& echo "/usr/lib" >> /etc/ld.so.conf.d/libgit2.conf | |
# Get LD falgs from pkg-config --static --libs $LIBGIT_BUILD/libgit2.pc | |
# Use pre-compiled static libssh2.a here | |
ENV CGO_ENABLED=1 \ | |
CGO_LDFLAGS="-Wl,-z,relro -L/usr/lib -L/usr/lib64 -lgit2 -lcurl /usr/lib64/libssh2.a -lrt -lssl -lcrypto -ldl -lgssapi_krb5 -lkrb5 -lcom_err -lk5crypto -lz" \ | |
CGO_CFLAGS="-I/libgit2/include -I/usr/include" \ | |
PKG_CONFIG_PATH="/usr/lib64/pkgconfig:/usr/lib/pkgconfig" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment