diff --git a/go1.14/Makefile b/go1.14/Debian7/Makefile similarity index 82% rename from go1.14/Makefile rename to go1.14/Debian7/Makefile index 12f52c8b..e9bb58bb 100644 --- a/go1.14/Makefile +++ b/go1.14/Debian7/Makefile @@ -1,4 +1,4 @@ -IMAGES := base main darwin arm mips ppc s390x +IMAGES := base amd64 build: @$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;) diff --git a/go1.14/Debian7/Makefile.common b/go1.14/Debian7/Makefile.common new file mode 100644 index 00000000..9f5cdd32 --- /dev/null +++ b/go1.14/Debian7/Makefile.common @@ -0,0 +1,26 @@ +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(SELF_DIR)/../Makefile.common + +NAME := golang-crossbuild +VERSION := 1.14.6 +DEBIAN_VERSION ?= 7 +SUFFIX := -$(shell basename $(CURDIR)) +TAG_EXTENSION ?= + +export DEBIAN_VERSION TAG_EXTENSION + +build: + @echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" + @go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile + @docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ + --build-arg REPOSITORY=$(REPOSITORY) \ + --build-arg VERSION=$(VERSION) \ + --build-arg DEBIAN_VERSION=$(DEBIAN_VERSION) \ + --build-arg TAG_EXTENSION=$(TAG_EXTENSION) \ + --build-arg IMAGE="$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ + --build-arg VCS_REF="$(VCS_REF)" \ + --build-arg VCS_URL="$(VCS_URL)" \ + --build-arg BUILD_DATE="$(BUILD_DATE)" \ + . + +.PHONY: build diff --git a/go1.14/Makefile.debian7 b/go1.14/Debian7/Makefile.debian7 similarity index 100% rename from go1.14/Makefile.debian7 rename to go1.14/Debian7/Makefile.debian7 diff --git a/go1.14/arm/.dockerignore b/go1.14/Debian7/amd64/.dockerignore similarity index 100% rename from go1.14/arm/.dockerignore rename to go1.14/Debian7/amd64/.dockerignore diff --git a/go1.14/Debian7/amd64/Dockerfile.tmpl b/go1.14/Debian7/amd64/Dockerfile.tmpl new file mode 100644 index 00000000..df1aaac6 --- /dev/null +++ b/go1.14/Debian7/amd64/Dockerfile.tmpl @@ -0,0 +1,70 @@ +ARG REPOSITORY +ARG VERSION +ARG TAG_EXTENSION= +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base${TAG_EXTENSION} + +RUN \ + dpkg --add-architecture amd64 \ + && apt-get -o Acquire::Check-Valid-Until=false update \ + && apt-get upgrade -qq -y \ + && apt-get install -y --no-install-recommends --allow-unauthenticated \ + clang:amd64 \ + g++:amd64 \ + gcc:amd64 \ + gcc-multilib:amd64 \ + libc6 \ + libc-bin \ + libc6-dev:amd64 \ +# libc6:amd64 \ +# libc-bin:amd64 \ + libdb5.1-dev:amd64 \ + libdb5.1:amd64 \ + libmagic1:amd64 \ + linux-libc-dev:amd64 \ + patch \ + xz-utils \ + librpm-dev:amd64 \ + libpopt-dev:amd64 \ + libxml2-dev:amd64 \ + libxml2:amd64 \ + libsystemd-journal-dev:amd64 \ + libsystemd-daemon-dev:amd64 \ + libsystemd-id128-dev:amd64 \ + libsystemd-daemon0:amd64 \ + libsystemd-id128-0:amd64 \ + libsystemd-journal0:amd64 \ + libpopt0:amd64 \ + librpm3:amd64 \ + librpmio3:amd64 \ + librpmbuild3:amd64 \ + librpmsign1:amd64 \ + libdb-dev:amd64 \ + libbz2-dev:amd64 \ + libz-dev:amd64 \ + libreadline-dev:amd64 \ + libselinux1-dev:amd64 \ + libsqlite3-dev:amd64 \ + liblzma5:amd64 \ + zlib1g:amd64 \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ +# && file helloWorld | cut -d "," -f 2 | grep -c 'Intel 80386' \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/arm/Makefile b/go1.14/Debian7/amd64/Makefile similarity index 100% rename from go1.14/arm/Makefile rename to go1.14/Debian7/amd64/Makefile diff --git a/go1.14/Debian7/amd64/rootfs/compilers.yaml b/go1.14/Debian7/amd64/rootfs/compilers.yaml new file mode 100644 index 00000000..e89908f2 --- /dev/null +++ b/go1.14/Debian7/amd64/rootfs/compilers.yaml @@ -0,0 +1,11 @@ +--- + +windows: + 386: + CC: i686-w64-mingw32-gcc + CXX: i686-w64-mingw32-g++ + +linux: + 386: + CC: gcc + CXX: g++ diff --git a/go1.14/Debian7/amd64/rootfs/helloWorld.c b/go1.14/Debian7/amd64/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian7/amd64/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/base/.dockerignore b/go1.14/Debian7/base/.dockerignore similarity index 100% rename from go1.14/base/.dockerignore rename to go1.14/Debian7/base/.dockerignore diff --git a/go1.14/base/Dockerfile.tmpl b/go1.14/Debian7/base/Dockerfile.tmpl similarity index 75% rename from go1.14/base/Dockerfile.tmpl rename to go1.14/Debian7/base/Dockerfile.tmpl index e17716d4..635795b8 100644 --- a/go1.14/base/Dockerfile.tmpl +++ b/go1.14/Debian7/base/Dockerfile.tmpl @@ -1,15 +1,17 @@ ARG DEBIAN_VERSION FROM debian:${DEBIAN_VERSION} -{{if or (eq .DEBIAN_VERSION "7") (eq .DEBIAN_VERSION "8") -}} +{{if (le .DEBIAN_VERSION "8") -}} # Replace sources.list in order to use archive.debian.org. COPY sources-debian{{.DEBIAN_VERSION}}.list /etc/apt/sources.list {{- end}} RUN \ - apt-get -o Acquire::Check-Valid-Until=false update \ - && apt-get dist-upgrade -y \ - && apt-get install -y --no-install-recommends --allow-unauthenticated \ + apt-get -qq -o Acquire::Check-Valid-Until=false update \ + && apt-get dist-upgrade -qq -y \ + && apt-get install -y \ + --no-install-recommends \ + --allow-unauthenticated \ build-essential \ ca-certificates \ curl \ @@ -21,9 +23,9 @@ RUN \ bison \ && rm -rf /var/lib/apt/lists/* -ARG GOLANG_VERSION=1.14.4 +ARG GOLANG_VERSION=1.14.6 ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz -ARG GOLANG_DOWNLOAD_SHA256=aed845e4185a0b2a3c3d5e1d0a35491702c55889192bb9c30e67a3de6849c067 +ARG GOLANG_DOWNLOAD_SHA256=5c566ddc2e0bcfc25c26a5dc44a440fcc0177f7350c1f01952b34d5989a0d287 RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ diff --git a/go1.14/base/Makefile b/go1.14/Debian7/base/Makefile similarity index 100% rename from go1.14/base/Makefile rename to go1.14/Debian7/base/Makefile diff --git a/go1.14/base/rootfs/entrypoint.go b/go1.14/Debian7/base/rootfs/entrypoint.go similarity index 100% rename from go1.14/base/rootfs/entrypoint.go rename to go1.14/Debian7/base/rootfs/entrypoint.go diff --git a/go1.14/Debian7/base/sources-debian7.list b/go1.14/Debian7/base/sources-debian7.list new file mode 100644 index 00000000..13cf3e0c --- /dev/null +++ b/go1.14/Debian7/base/sources-debian7.list @@ -0,0 +1,2 @@ +deb http://archive.debian.org/debian wheezy main +deb [arch=amd64] http://archive.debian.org/debian-security wheezy/updates main diff --git a/go1.14/Debian7/base/sources-debian8.list b/go1.14/Debian7/base/sources-debian8.list new file mode 100644 index 00000000..e489281c --- /dev/null +++ b/go1.14/Debian7/base/sources-debian8.list @@ -0,0 +1,2 @@ +deb http://archive.debian.org/debian jessie main +deb [arch=amd64] http://security.debian.org/debian-security jessie/updates main diff --git a/go1.14/Debian8/Makefile b/go1.14/Debian8/Makefile new file mode 100644 index 00000000..e9bb58bb --- /dev/null +++ b/go1.14/Debian8/Makefile @@ -0,0 +1,10 @@ +IMAGES := base amd64 + +build: + @$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;) + +# Requires login at https://docker.elastic.co:7000/. +push: + @$(foreach var,$(IMAGES),$(MAKE) -C $(var) push || exit 1;) + +.PHONY: build push diff --git a/go1.14/Debian8/Makefile.common b/go1.14/Debian8/Makefile.common new file mode 100644 index 00000000..44059a1b --- /dev/null +++ b/go1.14/Debian8/Makefile.common @@ -0,0 +1,26 @@ +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(SELF_DIR)/../Makefile.common + +NAME := golang-crossbuild +VERSION := 1.14.6 +DEBIAN_VERSION ?= 8 +SUFFIX := -$(shell basename $(CURDIR)) +TAG_EXTENSION ?= + +export DEBIAN_VERSION TAG_EXTENSION + +build: + @echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" + @go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile + @docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ + --build-arg REPOSITORY=$(REPOSITORY) \ + --build-arg VERSION=$(VERSION) \ + --build-arg DEBIAN_VERSION=$(DEBIAN_VERSION) \ + --build-arg TAG_EXTENSION=$(TAG_EXTENSION) \ + --build-arg IMAGE="$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ + --build-arg VCS_REF="$(VCS_REF)" \ + --build-arg VCS_URL="$(VCS_URL)" \ + --build-arg BUILD_DATE="$(BUILD_DATE)" \ + . + +.PHONY: build diff --git a/go1.14/Makefile.debian8 b/go1.14/Debian8/Makefile.debian8 similarity index 100% rename from go1.14/Makefile.debian8 rename to go1.14/Debian8/Makefile.debian8 diff --git a/go1.14/main/.dockerignore b/go1.14/Debian8/amd64/.dockerignore similarity index 100% rename from go1.14/main/.dockerignore rename to go1.14/Debian8/amd64/.dockerignore diff --git a/go1.14/Debian8/amd64/Dockerfile.tmpl b/go1.14/Debian8/amd64/Dockerfile.tmpl new file mode 100644 index 00000000..6b27294f --- /dev/null +++ b/go1.14/Debian8/amd64/Dockerfile.tmpl @@ -0,0 +1,53 @@ +ARG REPOSITORY +ARG VERSION +ARG TAG_EXTENSION= +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base${TAG_EXTENSION} + +RUN \ + dpkg --add-architecture amd64 \ + && apt-get -o Acquire::Check-Valid-Until=false update \ + && apt-get install -y --no-install-recommends --allow-unauthenticated \ + clang \ + g++ \ + gcc \ + gcc-multilib \ + #libc6-dev-amd64-cross \ + #libc6-dev \ + #libc6-dev-amd64 \ + #linux-libc-dev:amd64 \ + mingw-w64 \ + mingw-w64-tools \ + patch \ + xz-utils \ + librpm-dev:amd64 \ + libc-dev:amd64 \ + libpopt-dev:amd64 \ + linux-libc-dev:amd64 \ + libxml2-dev:amd64 \ + libxml2:amd64 \ + libicu-dev:amd64 \ + #libicu57:amd64 \ + icu-devtools:amd64 \ + libsystemd-dev:amd64 \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && file helloWorld | cut -d "," -f 2 | grep -c 'x86-64' \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/darwin/Makefile b/go1.14/Debian8/amd64/Makefile similarity index 100% rename from go1.14/darwin/Makefile rename to go1.14/Debian8/amd64/Makefile diff --git a/go1.14/main/rootfs/compilers.yaml b/go1.14/Debian8/amd64/rootfs/compilers.yaml similarity index 68% rename from go1.14/main/rootfs/compilers.yaml rename to go1.14/Debian8/amd64/rootfs/compilers.yaml index 02af3c42..1dd4b616 100644 --- a/go1.14/main/rootfs/compilers.yaml +++ b/go1.14/Debian8/amd64/rootfs/compilers.yaml @@ -8,14 +8,6 @@ windows: CC: x86_64-w64-mingw32-gcc CXX: x86_64-w64-mingw32-g++ -darwin: - 386: - CC: o32-clang - CXX: o32-clang++ - amd64: - CC: o64-clang - CXX: o64-clang++ - linux: 386: CC: gcc diff --git a/go1.14/Debian8/amd64/rootfs/helloWorld.c b/go1.14/Debian8/amd64/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian8/amd64/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/mips/.dockerignore b/go1.14/Debian8/base/.dockerignore similarity index 100% rename from go1.14/mips/.dockerignore rename to go1.14/Debian8/base/.dockerignore diff --git a/go1.14/Debian8/base/Dockerfile.tmpl b/go1.14/Debian8/base/Dockerfile.tmpl new file mode 100644 index 00000000..635795b8 --- /dev/null +++ b/go1.14/Debian8/base/Dockerfile.tmpl @@ -0,0 +1,51 @@ +ARG DEBIAN_VERSION +FROM debian:${DEBIAN_VERSION} + +{{if (le .DEBIAN_VERSION "8") -}} +# Replace sources.list in order to use archive.debian.org. +COPY sources-debian{{.DEBIAN_VERSION}}.list /etc/apt/sources.list +{{- end}} + +RUN \ + apt-get -qq -o Acquire::Check-Valid-Until=false update \ + && apt-get dist-upgrade -qq -y \ + && apt-get install -y \ + --no-install-recommends \ + --allow-unauthenticated \ + build-essential \ + ca-certificates \ + curl \ + git \ + gnupg \ + make \ + file \ + flex \ + bison \ + && rm -rf /var/lib/apt/lists/* + +ARG GOLANG_VERSION=1.14.6 +ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz +ARG GOLANG_DOWNLOAD_SHA256=5c566ddc2e0bcfc25c26a5dc44a440fcc0177f7350c1f01952b34d5989a0d287 + +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 + +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" +WORKDIR $GOPATH + +COPY rootfs / + +WORKDIR / +RUN go get -d . \ + && go build -o /crossbuild /entrypoint.go \ + && rm -rf /go/* /root/.cache/* /entrypoint.go + +ENV GOLANG_CROSSBUILD=1 +VOLUME /app +WORKDIR /app +ENTRYPOINT ["/crossbuild"] diff --git a/go1.14/main/Makefile b/go1.14/Debian8/base/Makefile similarity index 100% rename from go1.14/main/Makefile rename to go1.14/Debian8/base/Makefile diff --git a/go1.14/Debian8/base/rootfs/entrypoint.go b/go1.14/Debian8/base/rootfs/entrypoint.go new file mode 100644 index 00000000..0e5c2985 --- /dev/null +++ b/go1.14/Debian8/base/rootfs/entrypoint.go @@ -0,0 +1,175 @@ +// +build linux + +package main + +import ( + "fmt" + "io" + "io/ioutil" + "log" + "os" + "os/exec" + "sort" + "strings" + + "github.com/spf13/cobra" + "gopkg.in/yaml.v2" +) + +var rootCmd = &cobra.Command{ + Use: "crossbuild", + Short: "crossbuild is simple tool for cross-compiling Go binaries", + Long: `crossbuild is a containerized tool for cross-compiling Go binaries +by mounting the project inside of a container equipped with cross-compilers. + +The root of your project's repo should be mounted at the appropriate location +on the GOPATH which is set to /go. + +While executing the build command the following variables with be added to the +environment: GOOS, GOARCH, GOARM, PLATFORM_ID, CC, and CXX. +`, + RunE: doBuild, + SilenceUsage: true, +} + +func init() { + rootCmd.PersistentFlags().StringVarP(&buildCommand, "build-cmd", "c", + "make build", "Build command to execute.") + + rootCmd.PersistentFlags().StringSliceVarP(&platforms, "platforms", "p", nil, + "Target platform for the binary in GOOS/GOARCH format (e.g. windows/amd64).") + rootCmd.MarkPersistentFlagRequired("platforms") +} + +func main() { + log.SetFlags(0) + + if err := rootCmd.Execute(); err != nil { + log.Fatal(err) + } +} + +var ( + buildCommand string + platforms []string +) + +func doBuild(_ *cobra.Command, _ []string) error { + for _, p := range platforms { + env, err := buildEnvironment(p) + if err != nil { + return fmt.Errorf("failed constructing the build environment for %v: %v", p, err) + } + + if err = execBuildCommand(env); err != nil { + return fmt.Errorf("failed building for %v: %v", p, err) + } + } + + return nil +} + +func isDirEmpty(name string) (bool, error) { + f, err := os.Open(name) + if err != nil { + return false, err + } + defer f.Close() + + _, err = f.Readdirnames(1) + if err == io.EOF { + return true, nil + } + return false, err +} + +func buildEnvironment(platform string) (map[string]string, error) { + parts := strings.SplitN(platform, "/", 2) + if len(parts) != 2 { + return nil, fmt.Errorf("invalid platform %v", platform) + } + + platformID := strings.Join(parts, "-") + goos := parts[0] + arch := parts[1] + goarch := arch + goarm := "" + + if strings.HasPrefix(arch, "armv") { + goarch = "arm" + goarm = strings.TrimPrefix(arch, "armv") + } + + env := map[string]string{ + "GOOS": goos, + "GOARCH": goarch, + "GOARM": goarm, + "PLATFORM_ID": platformID, + } + + if err := loadCompilerSettings(goos, arch, env); err != nil { + return nil, fmt.Errorf("failed while loading compiler settings: %v", err) + } + + return env, nil +} + +type Compilers struct { + GOOS map[string]struct { + Arch map[string]struct { + Env map[string]string `yaml:",inline"` + } `yaml:",inline"` + } `yaml:",inline"` +} + +func loadCompilerSettings(goos, arch string, env map[string]string) error { + data, err := ioutil.ReadFile("/compilers.yaml") + if err != nil { + if os.IsNotExist(err) { + return nil + } + return fmt.Errorf("failed to read /compilers.yaml: %v", err) + } + + var compilers Compilers + if err = yaml.Unmarshal(data, &compilers); err != nil { + return fmt.Errorf("failed to parse /compilers.yaml: %v", err) + } + + arches, found := compilers.GOOS[goos] + if !found { + return fmt.Errorf("%v is not supported by this image", goos) + } + + settings, found := arches.Arch[arch] + if !found { + return fmt.Errorf("%v/%v is not supported by this image", goos, arch) + } + + for k, v := range settings.Env { + env[k] = v + } + + return nil +} + +func execBuildCommand(env map[string]string) error { + cmd := exec.Command("sh", "-c", buildCommand) + cmd.Env = os.Environ() + logEnv := make([]string, 0, len(env)) + for k, v := range env { + kv := k + "=" + v + cmd.Env = append(cmd.Env, kv) + logEnv = append(logEnv, kv) + } + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Stdin = os.Stdin + + var b strings.Builder + sort.Strings(logEnv) + fmt.Fprintf(&b, ">> Building using: cmd='%v', env=[%v]", buildCommand, strings.Join(logEnv, ", ")) + + log.Println(b.String()) + return cmd.Run() +} diff --git a/go1.14/Debian8/base/sources-debian7.list b/go1.14/Debian8/base/sources-debian7.list new file mode 100644 index 00000000..13cf3e0c --- /dev/null +++ b/go1.14/Debian8/base/sources-debian7.list @@ -0,0 +1,2 @@ +deb http://archive.debian.org/debian wheezy main +deb [arch=amd64] http://archive.debian.org/debian-security wheezy/updates main diff --git a/go1.14/Debian8/base/sources-debian8.list b/go1.14/Debian8/base/sources-debian8.list new file mode 100644 index 00000000..e489281c --- /dev/null +++ b/go1.14/Debian8/base/sources-debian8.list @@ -0,0 +1,2 @@ +deb http://archive.debian.org/debian jessie main +deb [arch=amd64] http://security.debian.org/debian-security jessie/updates main diff --git a/go1.14/Debian9/Makefile b/go1.14/Debian9/Makefile new file mode 100644 index 00000000..96bdfb36 --- /dev/null +++ b/go1.14/Debian9/Makefile @@ -0,0 +1,10 @@ +IMAGES := base i386 amd64 darwin arm64 armel armhf mips mips64 mipsel mips64el ppc64 ppc64el s390x + +build: + @$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;) + +# Requires login at https://docker.elastic.co:7000/. +push: + @$(foreach var,$(IMAGES),$(MAKE) -C $(var) push || exit 1;) + +.PHONY: build push diff --git a/go1.14/Debian9/Makefile.common b/go1.14/Debian9/Makefile.common new file mode 100644 index 00000000..9c08e833 --- /dev/null +++ b/go1.14/Debian9/Makefile.common @@ -0,0 +1,26 @@ +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(SELF_DIR)/../Makefile.common + +NAME := golang-crossbuild +VERSION := 1.14.6 +DEBIAN_VERSION ?= 9 +SUFFIX := -$(shell basename $(CURDIR)) +TAG_EXTENSION ?= + +export DEBIAN_VERSION TAG_EXTENSION + +build: + @echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" + @go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile + @docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ + --build-arg REPOSITORY=$(REPOSITORY) \ + --build-arg VERSION=$(VERSION) \ + --build-arg DEBIAN_VERSION=$(DEBIAN_VERSION) \ + --build-arg TAG_EXTENSION=$(TAG_EXTENSION) \ + --build-arg IMAGE="$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ + --build-arg VCS_REF="$(VCS_REF)" \ + --build-arg VCS_URL="$(VCS_URL)" \ + --build-arg BUILD_DATE="$(BUILD_DATE)" \ + . + +.PHONY: build diff --git a/go1.14/Makefile.debian9 b/go1.14/Debian9/Makefile.debian9 similarity index 100% rename from go1.14/Makefile.debian9 rename to go1.14/Debian9/Makefile.debian9 diff --git a/go1.14/ppc/.dockerignore b/go1.14/Debian9/amd64/.dockerignore similarity index 100% rename from go1.14/ppc/.dockerignore rename to go1.14/Debian9/amd64/.dockerignore diff --git a/go1.14/Debian9/amd64/Dockerfile.tmpl b/go1.14/Debian9/amd64/Dockerfile.tmpl new file mode 100644 index 00000000..6b27294f --- /dev/null +++ b/go1.14/Debian9/amd64/Dockerfile.tmpl @@ -0,0 +1,53 @@ +ARG REPOSITORY +ARG VERSION +ARG TAG_EXTENSION= +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base${TAG_EXTENSION} + +RUN \ + dpkg --add-architecture amd64 \ + && apt-get -o Acquire::Check-Valid-Until=false update \ + && apt-get install -y --no-install-recommends --allow-unauthenticated \ + clang \ + g++ \ + gcc \ + gcc-multilib \ + #libc6-dev-amd64-cross \ + #libc6-dev \ + #libc6-dev-amd64 \ + #linux-libc-dev:amd64 \ + mingw-w64 \ + mingw-w64-tools \ + patch \ + xz-utils \ + librpm-dev:amd64 \ + libc-dev:amd64 \ + libpopt-dev:amd64 \ + linux-libc-dev:amd64 \ + libxml2-dev:amd64 \ + libxml2:amd64 \ + libicu-dev:amd64 \ + #libicu57:amd64 \ + icu-devtools:amd64 \ + libsystemd-dev:amd64 \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && file helloWorld | cut -d "," -f 2 | grep -c 'x86-64' \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/mips/Makefile b/go1.14/Debian9/amd64/Makefile similarity index 100% rename from go1.14/mips/Makefile rename to go1.14/Debian9/amd64/Makefile diff --git a/go1.14/Debian9/amd64/rootfs/compilers.yaml b/go1.14/Debian9/amd64/rootfs/compilers.yaml new file mode 100644 index 00000000..1dd4b616 --- /dev/null +++ b/go1.14/Debian9/amd64/rootfs/compilers.yaml @@ -0,0 +1,17 @@ +--- + +windows: + 386: + CC: i686-w64-mingw32-gcc + CXX: i686-w64-mingw32-g++ + amd64: + CC: x86_64-w64-mingw32-gcc + CXX: x86_64-w64-mingw32-g++ + +linux: + 386: + CC: gcc + CXX: g++ + amd64: + CC: gcc + CXX: g++ diff --git a/go1.14/Debian9/amd64/rootfs/helloWorld.c b/go1.14/Debian9/amd64/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/amd64/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/s390x/.dockerignore b/go1.14/Debian9/arm64/.dockerignore similarity index 100% rename from go1.14/s390x/.dockerignore rename to go1.14/Debian9/arm64/.dockerignore diff --git a/go1.14/arm/Dockerfile.tmpl b/go1.14/Debian9/arm64/Dockerfile.tmpl similarity index 54% rename from go1.14/arm/Dockerfile.tmpl rename to go1.14/Debian9/arm64/Dockerfile.tmpl index 9a29dd58..9e0a8522 100644 --- a/go1.14/arm/Dockerfile.tmpl +++ b/go1.14/Debian9/arm64/Dockerfile.tmpl @@ -4,18 +4,12 @@ FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base RUN \ dpkg --add-architecture arm64 \ -# && dpkg --add-architecture armhf \ -# && dpkg --add-architecture armel \ && apt-get update -qq \ && apt-get install -qq -y \ --no-install-recommends \ --allow-unauthenticated \ crossbuild-essential-arm64 \ - crossbuild-essential-armel \ - crossbuild-essential-armhf \ linux-libc-dev-arm64-cross \ - linux-libc-dev-armel-cross \ - linux-libc-dev-armhf-cross \ librpm-dev:arm64 \ libc-dev:arm64 \ libpopt-dev:arm64 \ @@ -26,30 +20,18 @@ RUN \ libicu57:arm64 \ icu-devtools:arm64 \ libsystemd-dev:arm64 \ -# librpm-dev:armhf \ -# libc-dev:armhf \ -# libpopt-dev:armhf \ -# linux-libc-dev:armhf \ -# libxml2-dev:armhf \ -# libxml2:armhf \ -# libicu-dev:armhf \ -# libicu57:armhf \ -# icu-devtools:armhf \ -# libsystemd-dev:armhf \ -# librpm-dev:armel \ -# libc-dev:armel \ -# libpopt-dev:armel \ -# linux-libc-dev:armel \ -# libxml2-dev:armel \ -# libxml2:armel \ -# libicu-dev:armel \ -# libicu57:armel \ -# icu-devtools:armel \ -# libsystemd-dev:armel \ && rm -rf /var/lib/apt/lists/* COPY rootfs / +# Basic test +RUN cd / \ + && aarch64-linux-gnu-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && file helloWorld | cut -d "," -f 2 | grep -c 'ARM aarch64'\ + && rm helloWorld.c helloWorld + # Build-time metadata as defined at http://label-schema.org. ARG BUILD_DATE ARG IMAGE diff --git a/go1.14/ppc/Makefile b/go1.14/Debian9/arm64/Makefile similarity index 100% rename from go1.14/ppc/Makefile rename to go1.14/Debian9/arm64/Makefile diff --git a/go1.14/Debian9/arm64/rootfs/compilers.yaml b/go1.14/Debian9/arm64/rootfs/compilers.yaml new file mode 100644 index 00000000..80fab65d --- /dev/null +++ b/go1.14/Debian9/arm64/rootfs/compilers.yaml @@ -0,0 +1,6 @@ +--- + +linux: + arm64: + CC: aarch64-linux-gnu-gcc + CXX: aarch64-linux-gnu-g++ diff --git a/go1.14/Debian9/arm64/rootfs/helloWorld.c b/go1.14/Debian9/arm64/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/arm64/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/armel/.dockerignore b/go1.14/Debian9/armel/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/armel/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/Debian9/armel/Dockerfile.tmpl b/go1.14/Debian9/armel/Dockerfile.tmpl new file mode 100644 index 00000000..70e74aef --- /dev/null +++ b/go1.14/Debian9/armel/Dockerfile.tmpl @@ -0,0 +1,44 @@ +ARG REPOSITORY +ARG VERSION +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base + +RUN \ + dpkg --add-architecture armel \ + && apt-get update -qq \ + && apt-get install -qq -y \ + --no-install-recommends \ + --allow-unauthenticated \ + crossbuild-essential-armel \ + linux-libc-dev-armel-cross \ + librpm-dev:armel \ + libc-dev:armel \ + libpopt-dev:armel \ + linux-libc-dev:armel \ + libxml2-dev:armel \ + libxml2:armel \ + libicu-dev:armel \ + libicu57:armel \ + icu-devtools:armel \ + libsystemd-dev:armel \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && arm-linux-gnueabi-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'soft-float ABI' \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/s390x/Makefile b/go1.14/Debian9/armel/Makefile similarity index 100% rename from go1.14/s390x/Makefile rename to go1.14/Debian9/armel/Makefile diff --git a/go1.14/arm/rootfs/compilers.yaml b/go1.14/Debian9/armel/rootfs/compilers.yaml similarity index 64% rename from go1.14/arm/rootfs/compilers.yaml rename to go1.14/Debian9/armel/rootfs/compilers.yaml index 6269add7..7fe88894 100644 --- a/go1.14/arm/rootfs/compilers.yaml +++ b/go1.14/Debian9/armel/rootfs/compilers.yaml @@ -1,9 +1,6 @@ --- linux: - armv7: - CC: arm-linux-gnueabihf-gcc - CXX: arm-linux-gnueabihf-g++ armv6: # Using debian armel for ARMv6. # This is the same as ARMv5 so it will use softfp instead of hardfp. @@ -12,6 +9,3 @@ linux: armv5: CC: arm-linux-gnueabi-gcc CXX: arm-linux-gnueabi-g++ - arm64: - CC: aarch64-linux-gnu-gcc - CXX: aarch64-linux-gnu-g++ diff --git a/go1.14/Debian9/armel/rootfs/helloWorld.c b/go1.14/Debian9/armel/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/armel/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/armhf/.dockerignore b/go1.14/Debian9/armhf/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/armhf/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/Debian9/armhf/Dockerfile.tmpl b/go1.14/Debian9/armhf/Dockerfile.tmpl new file mode 100644 index 00000000..7b5fcb45 --- /dev/null +++ b/go1.14/Debian9/armhf/Dockerfile.tmpl @@ -0,0 +1,44 @@ +ARG REPOSITORY +ARG VERSION +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base + +RUN \ + dpkg --add-architecture armhf \ + && apt-get update -qq \ + && apt-get install -qq -y \ + --no-install-recommends \ + --allow-unauthenticated \ + crossbuild-essential-armhf \ + linux-libc-dev-armhf-cross \ + librpm-dev:armhf \ + libc-dev:armhf \ + libpopt-dev:armhf \ + linux-libc-dev:armhf \ + libxml2-dev:armhf \ + libxml2:armhf \ + libicu-dev:armhf \ + libicu57:armhf \ + icu-devtools:armhf \ + libsystemd-dev:armhf \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && arm-linux-gnueabihf-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'hard-float ABI' \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/Debian9/armhf/Makefile b/go1.14/Debian9/armhf/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/armhf/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/armhf/rootfs/compilers.yaml b/go1.14/Debian9/armhf/rootfs/compilers.yaml new file mode 100644 index 00000000..0607a506 --- /dev/null +++ b/go1.14/Debian9/armhf/rootfs/compilers.yaml @@ -0,0 +1,6 @@ +--- + +linux: + armv7: + CC: arm-linux-gnueabihf-gcc + CXX: arm-linux-gnueabihf-g++ diff --git a/go1.14/Debian9/armhf/rootfs/helloWorld.c b/go1.14/Debian9/armhf/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/armhf/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/base/.dockerignore b/go1.14/Debian9/base/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/base/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/Debian9/base/Dockerfile.tmpl b/go1.14/Debian9/base/Dockerfile.tmpl new file mode 100644 index 00000000..635795b8 --- /dev/null +++ b/go1.14/Debian9/base/Dockerfile.tmpl @@ -0,0 +1,51 @@ +ARG DEBIAN_VERSION +FROM debian:${DEBIAN_VERSION} + +{{if (le .DEBIAN_VERSION "8") -}} +# Replace sources.list in order to use archive.debian.org. +COPY sources-debian{{.DEBIAN_VERSION}}.list /etc/apt/sources.list +{{- end}} + +RUN \ + apt-get -qq -o Acquire::Check-Valid-Until=false update \ + && apt-get dist-upgrade -qq -y \ + && apt-get install -y \ + --no-install-recommends \ + --allow-unauthenticated \ + build-essential \ + ca-certificates \ + curl \ + git \ + gnupg \ + make \ + file \ + flex \ + bison \ + && rm -rf /var/lib/apt/lists/* + +ARG GOLANG_VERSION=1.14.6 +ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz +ARG GOLANG_DOWNLOAD_SHA256=5c566ddc2e0bcfc25c26a5dc44a440fcc0177f7350c1f01952b34d5989a0d287 + +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 + +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" +WORKDIR $GOPATH + +COPY rootfs / + +WORKDIR / +RUN go get -d . \ + && go build -o /crossbuild /entrypoint.go \ + && rm -rf /go/* /root/.cache/* /entrypoint.go + +ENV GOLANG_CROSSBUILD=1 +VOLUME /app +WORKDIR /app +ENTRYPOINT ["/crossbuild"] diff --git a/go1.14/Debian9/base/Makefile b/go1.14/Debian9/base/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/base/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/base/rootfs/entrypoint.go b/go1.14/Debian9/base/rootfs/entrypoint.go new file mode 100644 index 00000000..0e5c2985 --- /dev/null +++ b/go1.14/Debian9/base/rootfs/entrypoint.go @@ -0,0 +1,175 @@ +// +build linux + +package main + +import ( + "fmt" + "io" + "io/ioutil" + "log" + "os" + "os/exec" + "sort" + "strings" + + "github.com/spf13/cobra" + "gopkg.in/yaml.v2" +) + +var rootCmd = &cobra.Command{ + Use: "crossbuild", + Short: "crossbuild is simple tool for cross-compiling Go binaries", + Long: `crossbuild is a containerized tool for cross-compiling Go binaries +by mounting the project inside of a container equipped with cross-compilers. + +The root of your project's repo should be mounted at the appropriate location +on the GOPATH which is set to /go. + +While executing the build command the following variables with be added to the +environment: GOOS, GOARCH, GOARM, PLATFORM_ID, CC, and CXX. +`, + RunE: doBuild, + SilenceUsage: true, +} + +func init() { + rootCmd.PersistentFlags().StringVarP(&buildCommand, "build-cmd", "c", + "make build", "Build command to execute.") + + rootCmd.PersistentFlags().StringSliceVarP(&platforms, "platforms", "p", nil, + "Target platform for the binary in GOOS/GOARCH format (e.g. windows/amd64).") + rootCmd.MarkPersistentFlagRequired("platforms") +} + +func main() { + log.SetFlags(0) + + if err := rootCmd.Execute(); err != nil { + log.Fatal(err) + } +} + +var ( + buildCommand string + platforms []string +) + +func doBuild(_ *cobra.Command, _ []string) error { + for _, p := range platforms { + env, err := buildEnvironment(p) + if err != nil { + return fmt.Errorf("failed constructing the build environment for %v: %v", p, err) + } + + if err = execBuildCommand(env); err != nil { + return fmt.Errorf("failed building for %v: %v", p, err) + } + } + + return nil +} + +func isDirEmpty(name string) (bool, error) { + f, err := os.Open(name) + if err != nil { + return false, err + } + defer f.Close() + + _, err = f.Readdirnames(1) + if err == io.EOF { + return true, nil + } + return false, err +} + +func buildEnvironment(platform string) (map[string]string, error) { + parts := strings.SplitN(platform, "/", 2) + if len(parts) != 2 { + return nil, fmt.Errorf("invalid platform %v", platform) + } + + platformID := strings.Join(parts, "-") + goos := parts[0] + arch := parts[1] + goarch := arch + goarm := "" + + if strings.HasPrefix(arch, "armv") { + goarch = "arm" + goarm = strings.TrimPrefix(arch, "armv") + } + + env := map[string]string{ + "GOOS": goos, + "GOARCH": goarch, + "GOARM": goarm, + "PLATFORM_ID": platformID, + } + + if err := loadCompilerSettings(goos, arch, env); err != nil { + return nil, fmt.Errorf("failed while loading compiler settings: %v", err) + } + + return env, nil +} + +type Compilers struct { + GOOS map[string]struct { + Arch map[string]struct { + Env map[string]string `yaml:",inline"` + } `yaml:",inline"` + } `yaml:",inline"` +} + +func loadCompilerSettings(goos, arch string, env map[string]string) error { + data, err := ioutil.ReadFile("/compilers.yaml") + if err != nil { + if os.IsNotExist(err) { + return nil + } + return fmt.Errorf("failed to read /compilers.yaml: %v", err) + } + + var compilers Compilers + if err = yaml.Unmarshal(data, &compilers); err != nil { + return fmt.Errorf("failed to parse /compilers.yaml: %v", err) + } + + arches, found := compilers.GOOS[goos] + if !found { + return fmt.Errorf("%v is not supported by this image", goos) + } + + settings, found := arches.Arch[arch] + if !found { + return fmt.Errorf("%v/%v is not supported by this image", goos, arch) + } + + for k, v := range settings.Env { + env[k] = v + } + + return nil +} + +func execBuildCommand(env map[string]string) error { + cmd := exec.Command("sh", "-c", buildCommand) + cmd.Env = os.Environ() + logEnv := make([]string, 0, len(env)) + for k, v := range env { + kv := k + "=" + v + cmd.Env = append(cmd.Env, kv) + logEnv = append(logEnv, kv) + } + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Stdin = os.Stdin + + var b strings.Builder + sort.Strings(logEnv) + fmt.Fprintf(&b, ">> Building using: cmd='%v', env=[%v]", buildCommand, strings.Join(logEnv, ", ")) + + log.Println(b.String()) + return cmd.Run() +} diff --git a/go1.14/Debian9/base/sources-debian7.list b/go1.14/Debian9/base/sources-debian7.list new file mode 100644 index 00000000..13cf3e0c --- /dev/null +++ b/go1.14/Debian9/base/sources-debian7.list @@ -0,0 +1,2 @@ +deb http://archive.debian.org/debian wheezy main +deb [arch=amd64] http://archive.debian.org/debian-security wheezy/updates main diff --git a/go1.14/Debian9/base/sources-debian8.list b/go1.14/Debian9/base/sources-debian8.list new file mode 100644 index 00000000..e489281c --- /dev/null +++ b/go1.14/Debian9/base/sources-debian8.list @@ -0,0 +1,2 @@ +deb http://archive.debian.org/debian jessie main +deb [arch=amd64] http://security.debian.org/debian-security jessie/updates main diff --git a/go1.14/darwin/Dockerfile.tmpl b/go1.14/Debian9/darwin/Dockerfile.tmpl similarity index 81% rename from go1.14/darwin/Dockerfile.tmpl rename to go1.14/Debian9/darwin/Dockerfile.tmpl index c5a0048a..ccc9ea51 100644 --- a/go1.14/darwin/Dockerfile.tmpl +++ b/go1.14/Debian9/darwin/Dockerfile.tmpl @@ -28,6 +28,18 @@ ENV PATH $OSXCROSS_PATH/bin:$PATH COPY rootfs / +# Basic test +RUN cd / \ + && o64-clang helloWorld.c -o helloWorld \ + && file helloWorld \ + && file helloWorld | grep -c 'Mach-O 64-bit x86_64' + +RUN cd / \ + && o32-clang helloWorld.c -o helloWorld \ + && file helloWorld \ + && file helloWorld | grep -c 'Mach-O i386' \ + && rm helloWorld.c helloWorld + # Build-time metadata as defined at http://label-schema.org. ARG BUILD_DATE ARG IMAGE diff --git a/go1.14/Debian9/darwin/Makefile b/go1.14/Debian9/darwin/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/darwin/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/darwin/rootfs/compilers.yaml b/go1.14/Debian9/darwin/rootfs/compilers.yaml similarity index 100% rename from go1.14/darwin/rootfs/compilers.yaml rename to go1.14/Debian9/darwin/rootfs/compilers.yaml diff --git a/go1.14/Debian9/darwin/rootfs/helloWorld.c b/go1.14/Debian9/darwin/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/darwin/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/i386/.dockerignore b/go1.14/Debian9/i386/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/i386/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/main/Dockerfile.tmpl b/go1.14/Debian9/i386/Dockerfile.tmpl similarity index 57% rename from go1.14/main/Dockerfile.tmpl rename to go1.14/Debian9/i386/Dockerfile.tmpl index 24525ecf..41f93036 100644 --- a/go1.14/main/Dockerfile.tmpl +++ b/go1.14/Debian9/i386/Dockerfile.tmpl @@ -7,21 +7,34 @@ RUN \ dpkg --add-architecture i386 \ && apt-get -o Acquire::Check-Valid-Until=false update \ && apt-get install -y --no-install-recommends --allow-unauthenticated \ - clang \ - g++ \ - gcc \ - gcc-multilib \ - libc6-dev \ - libc6-dev-i386 \ + clang:i386 \ + g++:i386 \ + gcc:i386 \ + gcc-multilib:i386 \ + libc6-dev:i386 \ linux-libc-dev:i386 \ - mingw-w64 \ - mingw-w64-tools \ patch \ xz-utils \ + librpm-dev:i386 \ + libpopt-dev:i386 \ + libxml2-dev:i386 \ + libxml2:i386 \ + libicu-dev:i386 \ +# libicu57:i386 \ + icu-devtools:i386 \ + libsystemd-dev:i386 \ && rm -rf /var/lib/apt/lists/* COPY rootfs / +# Basic test +RUN cd / \ + && gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && file helloWorld | cut -d "," -f 2 | grep -c 'Intel 80386' \ + && rm helloWorld.c helloWorld + # Build-time metadata as defined at http://label-schema.org. ARG BUILD_DATE ARG IMAGE diff --git a/go1.14/Debian9/i386/Makefile b/go1.14/Debian9/i386/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/i386/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/i386/rootfs/compilers.yaml b/go1.14/Debian9/i386/rootfs/compilers.yaml new file mode 100644 index 00000000..e89908f2 --- /dev/null +++ b/go1.14/Debian9/i386/rootfs/compilers.yaml @@ -0,0 +1,11 @@ +--- + +windows: + 386: + CC: i686-w64-mingw32-gcc + CXX: i686-w64-mingw32-g++ + +linux: + 386: + CC: gcc + CXX: g++ diff --git a/go1.14/Debian9/i386/rootfs/helloWorld.c b/go1.14/Debian9/i386/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/i386/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/mips/.dockerignore b/go1.14/Debian9/mips/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/mips/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/Debian9/mips/Dockerfile.tmpl b/go1.14/Debian9/mips/Dockerfile.tmpl new file mode 100644 index 00000000..c3ad829a --- /dev/null +++ b/go1.14/Debian9/mips/Dockerfile.tmpl @@ -0,0 +1,46 @@ +ARG REPOSITORY +ARG VERSION +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base + +RUN \ + dpkg --add-architecture mips \ + && apt-get update -qq \ + && apt-get install -qq -y \ + --no-install-recommends \ + --allow-unauthenticated \ + dpkg-cross \ + gcc-mips-linux-gnu \ + g++-mips-linux-gnu \ + librpm-dev:mips \ + libc-dev:mips \ + libpopt-dev:mips \ + linux-libc-dev:mips \ + libxml2-dev:mips \ + libxml2:mips \ + libicu-dev:mips \ + libicu57:mips \ + icu-devtools:mips \ + libsystemd-dev:mips \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && mips-linux-gnu-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'MIPS R3000' \ + && readelf -h helloWorld | grep -c 'ELF32' \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/Debian9/mips/Makefile b/go1.14/Debian9/mips/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/mips/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/mips/rootfs/compilers.yaml b/go1.14/Debian9/mips/rootfs/compilers.yaml new file mode 100644 index 00000000..f508de1a --- /dev/null +++ b/go1.14/Debian9/mips/rootfs/compilers.yaml @@ -0,0 +1,6 @@ +--- + +linux: + mips: + CC: mips-linux-gnu-gcc + CXX: mips-linux-gnu-g++ diff --git a/go1.14/Debian9/mips/rootfs/helloWorld.c b/go1.14/Debian9/mips/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/mips/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/mips64/.dockerignore b/go1.14/Debian9/mips64/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/mips64/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/Debian9/mips64/Dockerfile.tmpl b/go1.14/Debian9/mips64/Dockerfile.tmpl new file mode 100644 index 00000000..821d8c34 --- /dev/null +++ b/go1.14/Debian9/mips64/Dockerfile.tmpl @@ -0,0 +1,48 @@ +ARG REPOSITORY +ARG VERSION +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base + +RUN \ + dpkg --add-architecture mips64 \ + && apt-get update -qq \ + && apt-get install -qq -y \ + --no-install-recommends \ + --allow-unauthenticated \ + dpkg-cross \ + gcc-mips64-linux-gnuabi64 \ + g++-mips64-linux-gnuabi64 \ + # FIXME build from sources \ + # librpm-dev:mips64 \ + # libc-dev:mips64 \ + # libpopt-dev:mips64 \ + # linux-libc-dev:mips64 \ + # libxml2-dev:mips64 \ + # libxml2:mips64 \ + # libicu-dev:mips64 \ + # libicu57:mips64 \ + # icu-devtools:mips64 \ + # libsystemd-dev:mips64 \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && mips64-linux-gnuabi64-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'MIPS R3000' \ + && readelf -h helloWorld | grep -c 'ELF64' \ + && readelf -h helloWorld | grep -c "big endian" \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/Debian9/mips64/Makefile b/go1.14/Debian9/mips64/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/mips64/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/mips64/rootfs/compilers.yaml b/go1.14/Debian9/mips64/rootfs/compilers.yaml new file mode 100644 index 00000000..67d30f41 --- /dev/null +++ b/go1.14/Debian9/mips64/rootfs/compilers.yaml @@ -0,0 +1,6 @@ +--- + +linux: + mips64: + CC: mips64-linux-gnuabi64-gcc + CXX: mips64-linux-gnuabi64-g++ diff --git a/go1.14/Debian9/mips64/rootfs/helloWorld.c b/go1.14/Debian9/mips64/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/mips64/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/mips64el/.dockerignore b/go1.14/Debian9/mips64el/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/mips64el/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/mips/Dockerfile.tmpl b/go1.14/Debian9/mips64el/Dockerfile.tmpl similarity index 68% rename from go1.14/mips/Dockerfile.tmpl rename to go1.14/Debian9/mips64el/Dockerfile.tmpl index 25fe93d6..05761a4c 100644 --- a/go1.14/mips/Dockerfile.tmpl +++ b/go1.14/Debian9/mips64el/Dockerfile.tmpl @@ -8,13 +8,9 @@ RUN \ && apt-get install -qq -y \ --no-install-recommends \ --allow-unauthenticated \ - crossbuild-essential-mipsel \ - gcc-mips-linux-gnu \ - g++-mips-linux-gnu \ - gcc-6-mips64-linux-gnuabi64 \ - g++-6-mips64-linux-gnuabi64 \ - gcc-6-mips64el-linux-gnuabi64 \ - g++-6-mips64el-linux-gnuabi64 \ + dpkg-cross \ + gcc-mips64el-linux-gnuabi64 \ + g++-mips64el-linux-gnuabi64 \ librpm-dev:mips64el \ libc-dev:mips64el \ libpopt-dev:mips64el \ @@ -29,6 +25,16 @@ RUN \ COPY rootfs / +# Basic test +RUN cd / \ + && mips64el-linux-gnuabi64-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'MIPS R3000' \ + && readelf -h helloWorld | grep -c 'ELF64' \ + && readelf -h helloWorld | grep -c "little endian" \ + && rm helloWorld.c helloWorld + # Build-time metadata as defined at http://label-schema.org. ARG BUILD_DATE ARG IMAGE diff --git a/go1.14/Debian9/mips64el/Makefile b/go1.14/Debian9/mips64el/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/mips64el/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/mips64el/rootfs/compilers.yaml b/go1.14/Debian9/mips64el/rootfs/compilers.yaml new file mode 100644 index 00000000..51c3b4b5 --- /dev/null +++ b/go1.14/Debian9/mips64el/rootfs/compilers.yaml @@ -0,0 +1,6 @@ +--- + +linux: + mips64le: + CC: mips64el-linux-gnuabi64-gcc + CXX: mips64el-linux-gnuabi64-g++ diff --git a/go1.14/Debian9/mips64el/rootfs/helloWorld.c b/go1.14/Debian9/mips64el/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/mips64el/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/mipsel/.dockerignore b/go1.14/Debian9/mipsel/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/mipsel/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/Debian9/mipsel/Dockerfile.tmpl b/go1.14/Debian9/mipsel/Dockerfile.tmpl new file mode 100644 index 00000000..aabcd64c --- /dev/null +++ b/go1.14/Debian9/mipsel/Dockerfile.tmpl @@ -0,0 +1,47 @@ +ARG REPOSITORY +ARG VERSION +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base + +RUN \ + dpkg --add-architecture mipsel \ + && apt-get update -qq \ + && apt-get install -qq -y \ + --no-install-recommends \ + --allow-unauthenticated \ + crossbuild-essential-mipsel \ + gcc-mipsel-linux-gnu \ + g++-mipsel-linux-gnu \ + librpm-dev:mipsel \ + libc-dev:mipsel \ + libpopt-dev:mipsel \ + linux-libc-dev:mipsel \ + libxml2-dev:mipsel \ + libxml2:mipsel \ + libicu-dev:mipsel \ + libicu57:mipsel \ + icu-devtools:mipsel \ + libsystemd-dev:mipsel \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && mipsel-linux-gnu-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'MIPS R3000' \ + && readelf -h helloWorld | grep -c 'ELF32' \ + && readelf -h helloWorld | grep -c "little endian" \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/Debian9/mipsel/Makefile b/go1.14/Debian9/mipsel/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/mipsel/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/mipsel/rootfs/compilers.yaml b/go1.14/Debian9/mipsel/rootfs/compilers.yaml new file mode 100644 index 00000000..a9bda56a --- /dev/null +++ b/go1.14/Debian9/mipsel/rootfs/compilers.yaml @@ -0,0 +1,6 @@ +--- + +linux: + mipsle: + CC: mipsel-linux-gnu-gcc + CXX: mipsel-linux-gnu-g++ diff --git a/go1.14/Debian9/mipsel/rootfs/helloWorld.c b/go1.14/Debian9/mipsel/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/mipsel/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/ppc64/.dockerignore b/go1.14/Debian9/ppc64/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/ppc64/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/Debian9/ppc64/Dockerfile.tmpl b/go1.14/Debian9/ppc64/Dockerfile.tmpl new file mode 100644 index 00000000..4a0140a8 --- /dev/null +++ b/go1.14/Debian9/ppc64/Dockerfile.tmpl @@ -0,0 +1,48 @@ +ARG REPOSITORY +ARG VERSION +FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base + +RUN \ + dpkg --add-architecture ppc64 \ + && apt-get update -qq \ + && apt-get install -y -qq \ + --no-install-recommends \ + --allow-unauthenticated \ + g++-powerpc64-linux-gnu \ + gcc-powerpc64-linux-gnu \ + dpkg-cross \ + # FIXME install from sources \ + # librpm-dev:ppc64 \ + # libc-dev:ppc64 \ + # libpopt-dev:ppc64 \ + # linux-libc-dev:ppc64 \ + # libxml2-dev:ppc64 \ + # libxml2:ppc64 \ + # libicu-dev:ppc64 \ + # libicu57:ppc64 \ + # icu-devtools:ppc64 \ + # libsystemd-dev:ppc64 \ + && rm -rf /var/lib/apt/lists/* + +COPY rootfs / + +# Basic test +RUN cd / \ + && powerpc64-linux-gnu-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'PowerPC64' \ + && readelf -h helloWorld | grep -c 'ELF64' \ + && readelf -h helloWorld | grep -c "big endian" \ + && rm helloWorld.c helloWorld + +# Build-time metadata as defined at http://label-schema.org. +ARG BUILD_DATE +ARG IMAGE +ARG VCS_REF +ARG VCS_URL +LABEL org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.name=$IMAGE \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.schema-version="1.0" diff --git a/go1.14/Debian9/ppc64/Makefile b/go1.14/Debian9/ppc64/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/ppc64/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/Debian9/ppc64/rootfs/compilers.yaml b/go1.14/Debian9/ppc64/rootfs/compilers.yaml new file mode 100644 index 00000000..bd76b2bd --- /dev/null +++ b/go1.14/Debian9/ppc64/rootfs/compilers.yaml @@ -0,0 +1,6 @@ +--- + +linux: + ppc64: + CC: powerpc64-linux-gnu-gcc + CXX: powerpc64-linux-gnu-g++ diff --git a/go1.14/Debian9/ppc64/rootfs/helloWorld.c b/go1.14/Debian9/ppc64/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/ppc64/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/ppc64el/.dockerignore b/go1.14/Debian9/ppc64el/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/ppc64el/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/ppc/Dockerfile.tmpl b/go1.14/Debian9/ppc64el/Dockerfile.tmpl similarity index 70% rename from go1.14/ppc/Dockerfile.tmpl rename to go1.14/Debian9/ppc64el/Dockerfile.tmpl index acdc1870..b00e9918 100644 --- a/go1.14/ppc/Dockerfile.tmpl +++ b/go1.14/Debian9/ppc64el/Dockerfile.tmpl @@ -8,8 +8,8 @@ RUN \ && apt-get install -y -qq \ --no-install-recommends \ --allow-unauthenticated \ - g++-6-powerpc64-linux-gnu \ - gcc-6-powerpc64-linux-gnu \ + g++-powerpc64le-linux-gnu \ + gcc-powerpc64le-linux-gnu \ crossbuild-essential-ppc64el \ librpm-dev:ppc64el \ libc-dev:ppc64el \ @@ -25,6 +25,16 @@ RUN \ COPY rootfs / +# Basic test +RUN cd / \ + && powerpc64le-linux-gnu-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'PowerPC64' \ + && readelf -h helloWorld | grep -c 'ELF64' \ + && readelf -h helloWorld | grep -c "little endian" \ + && rm helloWorld.c helloWorld + # Build-time metadata as defined at http://label-schema.org. ARG BUILD_DATE ARG IMAGE diff --git a/go1.14/Debian9/ppc64el/Makefile b/go1.14/Debian9/ppc64el/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/ppc64el/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/ppc/rootfs/compilers.yaml b/go1.14/Debian9/ppc64el/rootfs/compilers.yaml similarity index 54% rename from go1.14/ppc/rootfs/compilers.yaml rename to go1.14/Debian9/ppc64el/rootfs/compilers.yaml index 15ab651f..1012cc32 100644 --- a/go1.14/ppc/rootfs/compilers.yaml +++ b/go1.14/Debian9/ppc64el/rootfs/compilers.yaml @@ -1,9 +1,6 @@ --- linux: - ppc64: - CC: powerpc64-linux-gnu-gcc-6 - CXX: powerpc64-linux-gnu-g++-6 ppc64le: CC: powerpc64le-linux-gnu-gcc CXX: powerpc64le-linux-gnu-g++ diff --git a/go1.14/Debian9/ppc64el/rootfs/helloWorld.c b/go1.14/Debian9/ppc64el/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/ppc64el/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Debian9/s390x/.dockerignore b/go1.14/Debian9/s390x/.dockerignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/go1.14/Debian9/s390x/.dockerignore @@ -0,0 +1 @@ +Makefile diff --git a/go1.14/s390x/Dockerfile.tmpl b/go1.14/Debian9/s390x/Dockerfile.tmpl similarity index 75% rename from go1.14/s390x/Dockerfile.tmpl rename to go1.14/Debian9/s390x/Dockerfile.tmpl index 0efefa28..a9e7ddd0 100644 --- a/go1.14/s390x/Dockerfile.tmpl +++ b/go1.14/Debian9/s390x/Dockerfile.tmpl @@ -24,6 +24,16 @@ RUN \ COPY rootfs / +# Basic test +RUN cd / \ + && s390x-linux-gnu-gcc helloWorld.c -o helloWorld \ + && file helloWorld \ + && readelf -h helloWorld \ + && readelf -h helloWorld | grep -c 'IBM S/390' \ + && readelf -h helloWorld | grep -c 'ELF64' \ + && readelf -h helloWorld | grep -c "big endian" \ + && rm helloWorld.c helloWorld + # Build-time metadata as defined at http://label-schema.org. ARG BUILD_DATE ARG IMAGE diff --git a/go1.14/Debian9/s390x/Makefile b/go1.14/Debian9/s390x/Makefile new file mode 100644 index 00000000..0a42375f --- /dev/null +++ b/go1.14/Debian9/s390x/Makefile @@ -0,0 +1 @@ +include ../Makefile.common diff --git a/go1.14/s390x/rootfs/compilers.yaml b/go1.14/Debian9/s390x/rootfs/compilers.yaml similarity index 100% rename from go1.14/s390x/rootfs/compilers.yaml rename to go1.14/Debian9/s390x/rootfs/compilers.yaml diff --git a/go1.14/Debian9/s390x/rootfs/helloWorld.c b/go1.14/Debian9/s390x/rootfs/helloWorld.c new file mode 100644 index 00000000..dcfb86bc --- /dev/null +++ b/go1.14/Debian9/s390x/rootfs/helloWorld.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/go1.14/Makefile.common b/go1.14/Makefile.common index 168fd223..f96da809 100644 --- a/go1.14/Makefile.common +++ b/go1.14/Makefile.common @@ -1,26 +1,12 @@ -SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -include $(SELF_DIR)/../Makefile.common - -NAME := golang-crossbuild -VERSION := 1.14.4 -DEBIAN_VERSION ?= 9 -SUFFIX := -$(shell basename $(CURDIR)) -TAG_EXTENSION ?= - -export DEBIAN_VERSION TAG_EXTENSION - -build: - @echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" - @go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile - @docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ - --build-arg REPOSITORY=$(REPOSITORY) \ - --build-arg VERSION=$(VERSION) \ - --build-arg DEBIAN_VERSION=$(DEBIAN_VERSION) \ - --build-arg TAG_EXTENSION=$(TAG_EXTENSION) \ - --build-arg IMAGE="$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \ - --build-arg VCS_REF="$(VCS_REF)" \ - --build-arg VCS_URL="$(VCS_URL)" \ - --build-arg BUILD_DATE="$(BUILD_DATE)" \ - . - -.PHONY: build +REPOSITORY ?= docker.elastic.co/beats-dev +VCS_REF := $(shell git rev-parse HEAD) +VCS_URL := https://github.com/elastic/golang-crossbuild +BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") +.DEFAULT_GOAL := build + +# Requires login at https://docker.elastic.co:7000/. +push: + echo ">> Pushing $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" + @docker push "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" + +.PHONY: push diff --git a/go1.14/base/sources-debian7.list b/go1.14/base/sources-debian7.list deleted file mode 100644 index 18c86e1e..00000000 --- a/go1.14/base/sources-debian7.list +++ /dev/null @@ -1,2 +0,0 @@ -deb http://archive.debian.org/debian wheezy main -deb http://archive.debian.org/debian-security wheezy/updates main diff --git a/go1.14/base/sources-debian8.list b/go1.14/base/sources-debian8.list deleted file mode 100644 index d20d69a1..00000000 --- a/go1.14/base/sources-debian8.list +++ /dev/null @@ -1,2 +0,0 @@ -deb http://archive.debian.org/debian jessie main -deb http://security.debian.org/debian-security jessie/updates main diff --git a/go1.14/mips/rootfs/compilers.yaml b/go1.14/mips/rootfs/compilers.yaml deleted file mode 100644 index 7dff3130..00000000 --- a/go1.14/mips/rootfs/compilers.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- - -linux: - mips: - CC: mips-linux-gnu-gcc - CXX: mips-linux-gnu-g++ - mipsle: - CC: mipsel-linux-gnu-gcc - CXX: mipsel-linux-gnu-g++ - mips64: - CC: mips64-linux-gnuabi64-gcc-6 - CXX: mips64-linux-gnuabi64-g++-6 - mips64le: - CC: mips64el-linux-gnuabi64-gcc-6 - CXX: mips64el-linux-gnuabi64-g++-6 diff --git a/go1.14/template.go b/go1.14/template.go new file mode 100644 index 00000000..e1dc935f --- /dev/null +++ b/go1.14/template.go @@ -0,0 +1,87 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package main + +import ( + "bytes" + "flag" + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + "strings" + "text/template" +) + +var usageText = ` +Usage: template -t [-o output] + This command renders the specified template file using the Go text/template + package. It makes the current environment available as variables. +Options: +`[1:] + +var ( + templateFile string + outputFile string +) + +func init() { + flag.StringVar(&templateFile, "t", "", "template file") + flag.StringVar(&outputFile, "o", "", "output file") + flag.Usage = func() { + fmt.Fprintf(os.Stderr, usageText) + flag.PrintDefaults() + } +} + +func main() { + flag.Parse() + log.SetFlags(0) + + if templateFile == "" { + log.Fatal("Template file (-t) is required.") + } + + t := template.Must(template. + New(filepath.Base(templateFile)). + ParseFiles(templateFile)) + + data := envVars() + buf := new(bytes.Buffer) + if err := t.Execute(buf, data); err != nil { + log.Fatal(err) + } + + if outputFile == "-" || outputFile == "" { + fmt.Println(buf.String()) + } else { + if err := ioutil.WriteFile(outputFile, buf.Bytes(), 0644); err != nil { + log.Fatal(err) + } + } +} + +func envVars() map[string]string { + env := map[string]string{} + for _, e := range os.Environ() { + parts := strings.SplitN(e, "=", 2) + env[parts[0]] = parts[1] + } + return env +}