Skip to content

Commit

Permalink
Add Golang 1.16.x crossbuild images (#85)
Browse files Browse the repository at this point in the history
Co-authored-by: NHM Tanveer Hossain Khan <[email protected]>
Co-authored-by: Noémi Ványi <[email protected]>
  • Loading branch information
3 people authored May 10, 2021
1 parent 0a3a9c6 commit 5dda704
Show file tree
Hide file tree
Showing 50 changed files with 1,063 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pipeline {
DOCKER_REGISTRY_SECRET = 'secret/observability-team/ci/docker-registry/prod'
REGISTRY = 'docker.elastic.co'
STAGING_IMAGE = "${env.REGISTRY}/observability-ci"
GO_VERSION = '1.15.12'
GO_VERSION = '1.16.3'
}
options {
timeout(time: 3, unit: 'HOURS')
Expand Down Expand Up @@ -40,12 +40,12 @@ pipeline {
agent { label "${PLATFORM}" }
axes {
axis {
name "MAKEFILE"
name 'MAKEFILE'
values 'Makefile', 'Makefile.debian7', 'Makefile.debian8', 'Makefile.debian9', 'Makefile.debian10'
}
axis {
name 'GO_FOLDER'
values 'go1.14', 'go1.15'
values 'go1.14', 'go1.15', 'go1.16'
}
axis {
name 'PLATFORM'
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TARGETS=go1.10 go1.11 go1.12 go1.13 go1.14 go1.15
ARM_TARGETS=go1.15
TARGETS=go1.10 go1.11 go1.12 go1.13 go1.14 go1.15 go1.16
ARM_TARGETS=go1.15 go1.16

build: status=".status.build"
build:
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ The base image used is Debian 9 (stretch) unless otherwise specified.

## Build Tags

- `1.10.8-main`, `1.11.13-main`, `1.12.12-main`, `1.13.12-main`, `1.14.15-main`, `1.15.12-main` - linux/{amd64,386} and windows/{amd64,386}
- `1.10.8-arm`, `1.11.13-arm`, `1.12.12-arm`, `1.13.12-arm`, `1.14.15-arm`, `1.15.12-arm` - linux/{armv5,armv6,armv7,arm64}
- `1.10.8-darwin`, `1.11.13-darwin`, `1.12.12-darwin`, `1.13.12-darwin`, `1.14.15-darwin` - darwin/{386}
- `1.10.8-darwin`, `1.11.13-darwin`, `1.12.12-darwin`, `1.13.12-darwin`, `1.14.15-darwin`, `1.15.12-darwin` - darwin/{amd64}
- `1.10.8-ppc`, `1.11.13-ppc`, `1.12.12-ppc`, `1.13.12-ppc`, `1.14.15-ppc`, `1.15.12-ppc` - linux/{ppc64,ppc64le}
- `1.10.8-mips`, `1.11.13-mips`, `1.12.12-mips`, `1.13.12-mips`, `1.14.15-mips`, `1.15.12-mips` - linux/{mips,mipsle,mips64,mips64le}
- `1.10.8-s390x`, `1.11.13-s390x`, `1.12.12-s390`, `1.13.12-s390`, `1.14.15-s390`, `1.15.12-s390` - linux/s390x
- `1.10.8-main-debian7`, `1.11.13-main-debian7`, `1.12.12-debian7`, `1.13.12-debian7`, `1.14.15-debian7`, `1.15.12-debian7` - linux/{amd64,386} and windows/{amd64,386} (Debian 7
- `1.10.8-main`, `1.11.13-main`, `1.12.12-main`, `1.13.12-main`, `1.14.15-main`, `1.15.10-main`, `1.16.3-main` - linux/{amd64,386} and windows/{amd64,386}
- `1.10.8-arm`, `1.11.13-arm`, `1.12.12-arm`, `1.13.12-arm`, `1.14.15-arm`, `1.15.10-arm`, `1.16.3-arm` - linux/{armv5,armv6,armv7,arm64}
- `1.10.8-darwin`, `1.11.13-darwin`, `1.12.12-darwin`, `1.13.12-darwin`, `1.14.15-darwin`, `1.16.3-darwin` - darwin/{386}
- `1.10.8-darwin`, `1.11.13-darwin`, `1.12.12-darwin`, `1.13.12-darwin`, `1.14.15-darwin`, `1.15.10-darwin`, `1.16.3-darwin` - darwin/{amd64}
- `1.10.8-ppc`, `1.11.13-ppc`, `1.12.12-ppc`, `1.13.12-ppc`, `1.14.15-ppc`, `1.15.10-ppc`, `1.16.3-ppc` - linux/{ppc64,ppc64le}
- `1.10.8-mips`, `1.11.13-mips`, `1.12.12-mips`, `1.13.12-mips`, `1.14.15-mips`, `1.15.10-mips`, `1.16.3-mips` - linux/{mips,mipsle,mips64,mips64le}
- `1.10.8-s390x`, `1.11.13-s390x`, `1.12.12-s390`, `1.13.12-s390`, `1.14.15-s390`, `1.15.10-s390`, `1.16.3-s390` - linux/s390x
- `1.10.8-main-debian7`, `1.11.13-main-debian7`, `1.12.12-debian7`, `1.13.12-debian7`, `1.14.15-debian7`, `1.15.10-debian7`, `1.16.3-debian7` - linux/{amd64,386} and windows/{amd64,386} (Debian 7
uses glibc 2.13 so the resulting binaries (if dynamically linked) have greater
compatibility.)
- `1.10.8-main-debian8`, `1.11.13-main-debian8`, `1.12.12-main-debian8`, `1.13.12-debian8`, `1.14.15-debian8`, `1.15.12-debian8` - linux/{amd64,386} and windows/{amd64,386} (Debian 8
- `1.10.8-main-debian8`, `1.11.13-main-debian8`, `1.12.12-main-debian8`, `1.13.12-debian8`, `1.14.15-debian8`, `1.15.10-debian8`, `1.16.3-debian8` - linux/{amd64,386} and windows/{amd64,386} (Debian 8
uses glibc 2.19)
- `1.15.12-debian9` - linux/{amd64,386} and windows/{amd64,386} (Debian 9 uses glibc 2.24)
- `1.15.12-base-arm-debian9` - linux/arm64 (Debian 9 uses glibc 2.24)
- `1.15.12-debian10` - linux/{amd64,386} and windows/{amd64,386} (Debian 10 uses glibc 2.28)
- `1.15.10-debian9`, `1.16.3-debian9` - linux/{amd64,386} and windows/{amd64,386} (Debian 9 uses glibc 2.24)
- `1.15.10-base-arm-debian9`, `1.16.3-base-arm-debian9` - linux/arm64 (Debian 9 uses glibc 2.24)
- `1.15.10-debian10`, `1.16.3-debian10` - linux/{amd64,386} and windows/{amd64,386} (Debian 10 uses glibc 2.28)

## Usage Example

Expand Down
17 changes: 17 additions & 0 deletions go1.16/Makefile
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
41 changes: 41 additions & 0 deletions go1.16/Makefile.common
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
14 changes: 14 additions & 0 deletions go1.16/Makefile.debian10
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
14 changes: 14 additions & 0 deletions go1.16/Makefile.debian7
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
15 changes: 15 additions & 0 deletions go1.16/Makefile.debian8
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
21 changes: 21 additions & 0 deletions go1.16/Makefile.debian9
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
1 change: 1 addition & 0 deletions go1.16/arm/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Makefile
56 changes: 56 additions & 0 deletions go1.16/arm/Dockerfile.tmpl
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"
1 change: 1 addition & 0 deletions go1.16/arm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../Makefile.common
17 changes: 17 additions & 0 deletions go1.16/arm/rootfs/compilers.yaml
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++
5 changes: 5 additions & 0 deletions go1.16/arm/rootfs/helloWorld.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
69 changes: 69 additions & 0 deletions go1.16/base-arm/Dockerfile.tmpl
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"]
1 change: 1 addition & 0 deletions go1.16/base-arm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../Makefile.common
Loading

0 comments on commit 5dda704

Please sign in to comment.