Browse Source

init code

xueshaojie 2 years ago
parent
commit
ac37bac959

+ 42 - 0
Dockerfile.build.aarch64

@@ -0,0 +1,42 @@
+FROM debian:buster
+
+RUN sed -i s/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list && \
+    sed -i s/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list
+
+RUN apt-get clean
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+ADD go.tgz /usr/local/
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+ADD aarch64-linux-musl-cross.tgz /usr/local
+ENV PATH ${PATH}:/usr/local/aarch64-linux-musl-cross/bin
+
+RUN mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH arm64
+ENV CC /usr/bin/aarch64-linux-musl-gcc
+ENV LD /usr/bin/aarch64-linux-musl-ld
+ENV AR /usr/bin/aarch64-linux-musl-ar
+ENV CXX /usr/bin/aarch64-linux-musl-g++
+ENV CGO_CFLAGS '-g -O2 -Wno-return-local-addr'
+ENV CGO_ENABLED 1

+ 40 - 0
Dockerfile.build.arm

@@ -0,0 +1,40 @@
+FROM debian:buster
+
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+RUN curl -o /tmp/go.tgz https://go.dev/dl/go1.18.linux-amd64.tar.gz && \
+    tar zxf /tmp/go.tgz -C /usr/local/ && rm -f /tmp/go.tgz
+
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+RUN apt-get install -y \
+    gcc-arm-linux-gnueabihf \
+    g++-arm-linux-gnueabihf \
+    --no-install-recommends
+
+RUN mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH arm
+ENV CC /usr/bin/arm-linux-gnueabihf-gcc
+ENV LD /usr/bin/arm-linux-gnueabihf-ld
+ENV AR /usr/bin/arm-linux-gnueabihf-ar
+ENV CGO_ENABLED 1

+ 42 - 0
Dockerfile.build.base-aarch64.aarch64

@@ -0,0 +1,42 @@
+FROM debian:buster
+
+RUN sed -i s/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list && \
+    sed -i s/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list
+
+RUN apt-get clean
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+ADD go-arm64.tgz /usr/local/
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+RUN apt-get install -y \
+    musl \
+    musl-tools \
+    --no-install-recommends && \
+    mkdir -p $GOPATH/bin || true
+
+
+ENV GOOS linux
+ENV GOARCH arm64
+ENV CC /usr/bin/musl-gcc
+ENV LD /usr/bin/ld
+ENV AR /usr/bin/ar
+ENV CGO_ENABLED 1

+ 42 - 0
Dockerfile.build.base-aarch64.x86_64

@@ -0,0 +1,42 @@
+FROM debian:buster
+
+RUN sed -i s/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list && \
+    sed -i s/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g /etc/apt/sources.list
+
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+#RUN curl -o /tmp/go.tgz https://go.dev/dl/go1.18.linux-amd64.tar.gz && \
+    #tar zxf /tmp/go.tgz -C /usr/local/ && rm -f /tmp/go.tgz
+
+ADD go-arm64.tgz /usr/local/
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+ADD x86_64-linux-musl-cross.tgz /usr/local
+
+RUN mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH amd64
+ENV CC /usr/local/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc
+ENV LD /usr/local/x86_64-linux-musl-cross/bin/x86_64-linux-musl-ld
+ENV AR /usr/local/x86_64-linux-musl-cross/bin/x86_64-linux-musl-ar
+ENV CGO_CFLAGS '-g -O2 -Wno-return-local-addr'
+ENV CGO_ENABLED 1

+ 38 - 0
Dockerfile.build.i686

@@ -0,0 +1,38 @@
+FROM debian:buster
+
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+RUN curl -o /tmp/go.tgz https://go.dev/dl/go1.18.linux-amd64.tar.gz && \
+    tar zxf /tmp/go.tgz -C /usr/local/ && rm -f /tmp/go.tgz
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+RUN apt-get install -y \
+    gcc-i686-linux-gnu \
+    g++-i686-linux-gnu \
+    --no-install-recommends && \
+    mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH 386
+ENV CC /usr/bin/i686-linux-gnu-gcc
+ENV LD /usr/bin/i686-linux-gnu-ld
+ENV AR /usr/bin/i686-linux-gnu-ar
+ENV CGO_ENABLED 1

+ 38 - 0
Dockerfile.build.mips64el

@@ -0,0 +1,38 @@
+FROM debian:buster
+
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+RUN curl -o /tmp/go.tgz https://go.dev/dl/go1.18.linux-amd64.tar.gz && \
+    tar zxf /tmp/go.tgz -C /usr/local/ && rm -f /tmp/go.tgz
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+RUN apt-get install -y \
+    gcc-mips64el-linux-gnuabi64 \
+    g++-mips64el-linux-gnuabi64 \
+    --no-install-recommends && \
+    mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH mips64le
+ENV CC /usr/bin/mips64el-linux-gnuabi64-gcc
+ENV LD /usr/bin/mips64el-linux-gnuabi64-ld
+ENV AR /usr/bin/mips64el-linux-gnuabi64-ar
+ENV CGO_ENABLED 1

+ 38 - 0
Dockerfile.build.ppc64

@@ -0,0 +1,38 @@
+FROM debian:buster
+
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+RUN curl -o /tmp/go.tgz https://go.dev/dl/go1.18.linux-amd64.tar.gz && \
+    tar zxf /tmp/go.tgz -C /usr/local/ && rm -f /tmp/go.tgz
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+RUN apt-get install -y \
+    gcc-powerpc64-linux-gnu \
+    g++-powerpc64-linux-gnu \
+    --no-install-recommends && \
+    mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH ppc64
+ENV CC /usr/bin/powerpc64-linux-gnu-gcc
+ENV LD /usr/bin/powerpc64-linux-gnu-ld
+ENV AR /usr/bin/powerpc64-linux-gnu-ar
+ENV CGO_ENABLED 1

+ 38 - 0
Dockerfile.build.ppc64le

@@ -0,0 +1,38 @@
+FROM debian:buster
+
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+RUN curl -o /tmp/go.tgz https://go.dev/dl/go1.18.linux-amd64.tar.gz && \
+    tar zxf /tmp/go.tgz -C /usr/local/ && rm -f /tmp/go.tgz
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+RUN apt-get install -y \
+    gcc-powerpc64le-linux-gnu \
+    g++-powerpc64le-linux-gnu \
+    --no-install-recommends && \
+    mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH ppc64le
+ENV CC /usr/bin/powerpc64le-linux-gnu-gcc
+ENV LD /usr/bin/powerpc64le-linux-gnu-ld
+ENV AR /usr/bin/powerpc64le-linux-gnu-ar
+ENV CGO_ENABLED 1

+ 38 - 0
Dockerfile.build.x86_64

@@ -0,0 +1,38 @@
+FROM debian:buster
+
+RUN apt-get update -y && \
+    apt-get install -y \
+    curl \
+    git \
+    make \
+    automake \
+    autoconf \
+    tar \
+    ca-certificates \
+    build-essential \
+    --no-install-recommends
+
+# prepare env
+
+ADD go.tgz /usr/local/
+ENV GOROOT /usr/local/go
+ENV GOPATH /go
+ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin
+ENV GO111MODULE on
+ENV GOPROXY https://goproxy.cn,direct
+
+# cross complie env
+
+RUN apt-get install -y gcc g++ --no-install-recommends && \
+    mkdir -p $GOPATH/bin || true
+
+ENV GOOS linux
+ENV GOARCH amd64
+ENV CC /usr/bin/gcc
+ENV LD /usr/bin/ld
+ENV AR /usr/bin/ar
+ENV CGO_ENABLED 1
+
+#CGO_ENABLED=1 GOOS=linux GOARCH=x86_64 CC=/tmp/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc CXX=/tmp/x86_64-linux-musl-cross/bin/x86_64-linux-musl-c++ go build -o chaosd -a -ldflags '-extldflags "-static"' .
+#CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=/usr/bin/x86_64-linux-gnu-gcc CXX=/usr/bin/x86_64-linux-gnu-g++ AR=/usr/bin/x86_64-linux-gnu-ar LD=/usr/bin/x86_64-linux-gnu-ld go build -o chaosd -a -ldflags '-extldflags "-static"' .
+#CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=/root/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc CXX=/root/aarch64-linux-musl-cross/bin/aarch64-linux-musl-g++ AR=/root/aarch64-linux-musl-cross/bin/aarch64-linux-musl-ar LD=/root/aarch64-linux-musl-cross/bin/aarch64-linux-musl-ld go build -o chaosd -a -ldflags '-extldflags "-static"' .

+ 58 - 0
Makefile

@@ -0,0 +1,58 @@
+.PHONY: image-build default check ca
+
+PWD := $(shell pwd)
+
+PKG=notice
+BUILD_DIR := /go/src/$(PKG)
+VERSION := $(shell cat VERSION.txt)
+GIT_COMMIT := $(shell git rev-parse --short HEAD)
+GO_LD_FLAGS := -w -extldflags "-static"
+
+ARCH := x86_64
+VERS := $(VERSION)-$(GIT_COMMIT)
+
+DOCKER_IMAGE := golang-1.18:$(ARCH)
+
+DOCKER_BUILD := \
+	docker run --rm -v $(PWD)/bin:/target -v $(PWD):$(BUILD_DIR) -e GOARM=$(ARMVER) \
+		-w $(BUILD_DIR) $(DOCKER_IMAGE) go build -ldflags="$(GO_LD_FLAGS)"
+
+ifeq ($(ARMVER),)
+DOCKER_BUILD = \
+	docker run --rm -v $(PWD)/bin:/target -v $(PWD):$(BUILD_DIR) \
+		-w $(BUILD_DIR) $(DOCKER_IMAGE) go mod tidy && go build -ldflags="$(GO_LD_FLAGS)"
+endif
+
+check:
+	echo arch:$(ARCH) armversion:$(ARMVER)
+	echo docker_build: $(DOCKER_BUILD)
+
+default: ca
+
+ca: image-build
+	$(DOCKER_BUILD) -o /target/$(PKG)-$(VERS)-$(ARCH)$(ARMVER); \
+
+# 本机OS:arm64   docker镜像所使用的OS:x86_64   
+arm64-x86_64-image-build:
+	if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
+		docker buildx build -t $(DOCKER_IMAGE) --platform=linux/amd64 -o type=docker -f Dockerfile.build.$(ARCH) .; \
+	fi
+
+# 本机OS:arm64   docker镜像所使用的OS:arm64  
+arm64-arm64-image-build:
+	if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
+		docker build -t $(DOCKER_IMAGE) -f Dockerfile.build.base-aarch64.$(ARCH) .; \
+	fi
+
+# 默认本机的OS:x86_64  docker镜像所使用的OS:x86_64 
+x86_64-image-build:
+	if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
+		docker build -t $(DOCKER_IMAGE) -f Dockerfile.build.$(ARCH) .; \
+
+	fi
+
+# 默认本机的OS:x86_64  docker镜像所使用的OS:arm64 
+arm64-image-build:
+	if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
+		docker buildx build -t $(DOCKER_IMAGE) --platform=linux/arm64 -o type=docker -f Dockerfile.build.base-aarch64.$(ARCH) .; \
+	fi

+ 14 - 1
README.md

@@ -1,2 +1,15 @@
-# go_tools
+Go不同平台的Dockerfile
 
+示例
+
+# 本机OS:arm64   docker镜像所使用的OS:x86_64   构建arm64镜像已验证,x86_64的镜像未验证。
+make arm64-x86_64-image-build
+
+# 本机OS:arm64   docker镜像所使用的OS:arm64  构建arm64和x64的镜像已验证
+make arm64-arm64-image-build
+
+# 默认本机的OS:x86_64  docker镜像所使用的OS:x86_64 
+make x86_64-image-build
+
+# 默认本机的OS:x86_64  docker镜像所使用的OS:arm64 
+make arm64-image-build

BIN
aarch64-linux-musl-cross.tgz


BIN
go-arm64.tgz


BIN
go.tgz


BIN
x86_64-linux-musl-cross.tgz