-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Golang 1.16.x crossbuild images (#85)
Co-authored-by: NHM Tanveer Hossain Khan <[email protected]> Co-authored-by: Noémi Ványi <[email protected]>
- Loading branch information
1 parent
0a3a9c6
commit 5dda704
Showing
50 changed files
with
1,063 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
IMAGES := base main darwin arm mips ppc s390x | ||
ARM_IMAGES := base-arm | ||
|
||
build: | ||
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;) | ||
|
||
build-arm: | ||
@$(foreach var,$(ARM_IMAGES),$(MAKE) -C $(var) build-arm || exit 1;) | ||
|
||
# Requires login at https://docker.elastic.co:7000/. | ||
push: | ||
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) push || exit 1;) | ||
|
||
push-arm: | ||
@$(foreach var,$(ARM_IMAGES),$(MAKE) -C $(var) push-arm || exit 1;) | ||
|
||
.PHONY: build build-arm push push-arm |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) | ||
include $(SELF_DIR)/../Makefile.common | ||
|
||
NAME := golang-crossbuild | ||
VERSION := 1.16.3 | ||
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)" \ | ||
. | ||
|
||
build-arm: | ||
@echo $(SELF_DIR) | ||
@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 build-arm |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
IMAGES := base main darwin | ||
DEBIAN_VERSION := 10 | ||
TAG_EXTENSION := -debian10 | ||
|
||
export DEBIAN_VERSION TAG_EXTENSION | ||
|
||
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
IMAGES := base main | ||
DEBIAN_VERSION := 7 | ||
TAG_EXTENSION := -debian7 | ||
|
||
export DEBIAN_VERSION TAG_EXTENSION | ||
|
||
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
IMAGES := base main darwin | ||
DEBIAN_VERSION := 8 | ||
TAG_EXTENSION := -debian8 | ||
|
||
export DEBIAN_VERSION TAG_EXTENSION | ||
|
||
build: | ||
export |grep TAG_EXTENSION | ||
@$(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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
IMAGES := base main arm darwin mips ppc s390x | ||
ARM_IMAGES := base-arm | ||
DEBIAN_VERSION := 9 | ||
TAG_EXTENSION := -debian9 | ||
|
||
export DEBIAN_VERSION TAG_EXTENSION | ||
|
||
build: | ||
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;) | ||
|
||
build-arm: | ||
@$(foreach var,$(ARM_IMAGES),$(MAKE) -C $(var) build-arm || exit 1;) | ||
|
||
# Requires login at https://docker.elastic.co:7000/. | ||
push: | ||
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) push || exit 1;) | ||
|
||
push-arm: | ||
@$(foreach var,$(ARM_IMAGES),$(MAKE) -C $(var) push-arm || exit 1;) | ||
|
||
.PHONY: build build-arm push push-arm |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Makefile |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
ARG REPOSITORY | ||
ARG VERSION | ||
ARG TAG_EXTENSION='' | ||
FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base${TAG_EXTENSION} | ||
|
||
RUN \ | ||
dpkg --add-architecture arm64 \ | ||
&& 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 \ | ||
linux-libc-dev:arm64 \ | ||
libxml2-dev:arm64 \ | ||
libxml2:arm64 \ | ||
libicu-dev:arm64 \ | ||
libicu57:arm64 \ | ||
icu-devtools:arm64 \ | ||
libsystemd-dev:arm64 \ | ||
librpm3:arm64 \ | ||
librpmio3:arm64 \ | ||
librpmbuild3:arm64 \ | ||
librpmsign3:arm64 \ | ||
libsqlite3-dev:arm64 \ | ||
libnss3:arm64 \ | ||
libsqlite3-0:arm64 \ | ||
&& 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 | ||
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" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../Makefile.common |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
|
||
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. | ||
CC: arm-linux-gnueabi-gcc | ||
CXX: arm-linux-gnueabi-g++ | ||
armv5: | ||
CC: arm-linux-gnueabi-gcc | ||
CXX: arm-linux-gnueabi-g++ | ||
arm64: | ||
CC: aarch64-linux-gnu-gcc | ||
CXX: aarch64-linux-gnu-g++ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <stdio.h> | ||
int main() { | ||
printf("Hello, World!"); | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
ARG DEBIAN_VERSION | ||
FROM arm64v8/debian:${DEBIAN_VERSION} | ||
|
||
ARG DEBIAN_VERSION | ||
# Replace sources.list in order to use archive.debian.org. | ||
COPY sources-debian${DEBIAN_VERSION}.list /etc/apt/sources.list | ||
|
||
RUN \ | ||
apt-get -o Acquire::Check-Valid-Until=false update \ | ||
&& apt-get dist-upgrade -y \ | ||
&& apt-get install -qq -y --no-install-recommends --allow-unauthenticated \ | ||
build-essential \ | ||
ca-certificates \ | ||
curl \ | ||
git \ | ||
gnupg \ | ||
make \ | ||
file \ | ||
flex \ | ||
bison \ | ||
librpm-dev \ | ||
libc-dev \ | ||
libpopt-dev \ | ||
linux-libc-dev \ | ||
libxml2-dev \ | ||
libxml2 \ | ||
libicu-dev \ | ||
libicu57 \ | ||
icu-devtools \ | ||
libsystemd-dev \ | ||
librpm3 \ | ||
librpmio3 \ | ||
librpmbuild3 \ | ||
librpmsign3 \ | ||
libsqlite3-dev \ | ||
libnss3 \ | ||
libsqlite3-0 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG GOLANG_VERSION=1.16.3 | ||
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-arm64.tar.gz | ||
ARG GOLANG_DOWNLOAD_SHA256=566b1d6f17d2bc4ad5f81486f0df44f3088c3ed47a3bec4099d8ed9939e90d5d | ||
|
||
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 / | ||
|
||
# show the GLIBC version | ||
RUN ldd --version | ||
|
||
WORKDIR / | ||
RUN go mod init github.com/elastic/golang-crossbuild-$GOLANG_VERSION-arm \ | ||
&& 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"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../Makefile.common |
Oops, something went wrong.