Skip to content

Commit f047f0d

Browse files
committed
Docker images for cross-building Beats
0 parents  commit f047f0d

39 files changed

+698
-0
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# See: http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[Dockerfile]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[Makefile]
19+
indent_style = tab

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.iml
2+
*.swp
3+
*.o
4+
.idea
5+
.vagrant
6+
_obj

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
build:
2+
@make -C go1.10 $@
3+
@make -C go1.10 -f Makefile.debian7 $@
4+
@make -C fpm $@
5+
6+
# Requires login at https://docker.elastic.co:7000/.
7+
push:
8+
@make -C go1.10 $@
9+
@make -C go1.10 -f Makefile.debian7 $@
10+
@make -C fpm $@
11+
12+
.PHONY: build push

Makefile.common

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
REPOSITORY := docker.elastic.co/beats-dev
2+
VCS_REF := $(shell git rev-parse HEAD)
3+
VCS_URL := https://github.com/elastic/golang-crossbuild
4+
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
5+
.DEFAULT_GOAL := build
6+
7+
# Requires login at https://docker.elastic.co:7000/.
8+
push:
9+
echo ">> Pushing $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
10+
@docker tag "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" "push.$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
11+
@docker push "push.$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
12+
13+
.PHONY: push

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# golang-crossbuild
2+
3+
golang-crossbuild is a set of Docker images containing the requisite
4+
cross-compilers for cross compiling Go applications. The cross-compilers are
5+
needed when the application uses [cgo](https://golang.org/cmd/cgo/).
6+
7+
The base image used is Debian 9 (stretch) unless otherwise specified.
8+
9+
## Docker Repo
10+
11+
`docker.elastic.co/beats-dev/golang-crossbuild:[TAG]`
12+
13+
## Build Tags
14+
15+
- `1.10.3-main` - linux/{amd64,386} and windows/{amd64,386}
16+
- `1.10.3-arm` - linux/{armv5,armv6,armv7,arm64}
17+
- `1.10.3-darwin` - darwin/{amd64,386}
18+
- `1.10.3-ppc` - linux/{ppc64,ppc64le}
19+
- `1.10.3-mips` - linux/{mips,mipsle,mips64,mips64le}
20+
- `1.10.3-s390x` - linux/s390x
21+
- `1.10.3-main-debian7` - linux/{amd64,386} and windows/{amd64,386} (Debian 7
22+
uses glibc 2.13 so the resulting binaries (if dynamically linked) have greater
23+
compatibility.)
24+
25+
## Usage Example
26+
27+
```sh
28+
docker run -it --rm \
29+
-v $GOPATH/src/github.com/user/go-project:/go/src/github.com/user/go-project \
30+
-w /go/src/github.com/user/go-project \
31+
-env CGO_ENABLED=1 \
32+
docker.elastic.co/beats-dev/golang-crossbuild:1.10.3-arm \
33+
--build-cmd "make build" \
34+
-p "linux/armv7"
35+
```
36+
37+
This will execute your projects `make build` target. While executing the build
38+
command the following variables with be added to the environment: GOOS, GOARCH,
39+
GOARM, PLATFORM_ID, CC, and CXX.

fpm/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Makefile

fpm/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM debian:stable
2+
LABEL maintainer="Elastic Beats Team"
3+
4+
RUN \
5+
apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
autoconf build-essential libffi-dev ruby-dev rpm zip dos2unix libgmp3-dev \
8+
curl make gcc \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
ARG SUEXEC_VERSION=0.2
12+
ARG SUEXEC_DOWNLOAD_URL=https://github.com/ncopa/su-exec/archive/v${SUEXEC_VERSION}.tar.gz
13+
ARG SUEXEC_DOWNLOAD_SHA256=ec4acbd8cde6ceeb2be67eda1f46c709758af6db35cacbcde41baac349855e25
14+
15+
RUN \
16+
curl -fsSL "$SUEXEC_DOWNLOAD_URL" -o suexec.tar.gz \
17+
&& echo "$SUEXEC_DOWNLOAD_SHA256 suexec.tar.gz" | sha256sum -c - \
18+
&& mkdir /suexec \
19+
&& tar -C /suexec --strip-components=1 -xzf suexec.tar.gz \
20+
&& make -C /suexec \
21+
&& mv /suexec/su-exec /usr/bin/ \
22+
&& rm -rf /suexec suexec.tar.gz
23+
24+
ARG FPM_VERSION
25+
RUN gem install fpm -v "$FPM_VERSION"
26+
27+
COPY rootfs /
28+
29+
ENTRYPOINT ["/entrypoint.sh"]
30+
31+
# Build-time metadata as defined at http://label-schema.org.
32+
ARG BUILD_DATE
33+
ARG IMAGE
34+
ARG VCS_REF
35+
ARG VCS_URL
36+
LABEL org.label-schema.build-date=$BUILD_DATE \
37+
org.label-schema.name=$IMAGE \
38+
org.label-schema.vcs-ref=$VCS_REF \
39+
org.label-schema.vcs-url=$VCS_URL \
40+
org.label-schema.schema-version="1.0"

fpm/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include ../Makefile.common
2+
3+
NAME := fpm
4+
VERSION := 1.10.0
5+
6+
build:
7+
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)"
8+
@docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)" \
9+
--build-arg FPM_VERSION=$(VERSION) \
10+
--build-arg IMAGE="$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \
11+
--build-arg VCS_REF="$(VCS_REF)" \
12+
--build-arg VCS_URL="$(VCS_URL)" \
13+
--build-arg BUILD_DATE="$(BUILD_DATE)" \
14+
.
15+
16+
.PHONY: build

fpm/rootfs/entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
3+
if [ -z ${EXEC_UID+x} ] || [ -z ${EXEC_GID+x} ]; then
4+
exec "$@"
5+
fi
6+
7+
groupadd -f -g "$EXEC_GID" fpm
8+
useradd -N -m -c 'FPM User' -u "$EXEC_UID" -g "$EXEC_GID" fpm
9+
10+
su-exec fpm "$@"

go1.10/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
IMAGES := base main darwin arm mips ppc s390x
2+
3+
build:
4+
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;)
5+
6+
# Requires login at https://docker.elastic.co:7000/.
7+
push:
8+
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) push || exit 1;)
9+
10+
.PHONY: build push

go1.10/Makefile.common

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
2+
include $(SELF_DIR)/../Makefile.common
3+
4+
NAME := golang-crossbuild
5+
VERSION := 1.10.3
6+
DEBIAN_VERSION ?= 9
7+
SUFFIX := -$(shell basename $(CURDIR))
8+
TAG_EXTENSION ?=
9+
10+
build:
11+
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
12+
@docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \
13+
--build-arg REPOSITORY=$(REPOSITORY) \
14+
--build-arg VERSION=$(VERSION) \
15+
--build-arg DEBIAN_VERSION=$(DEBIAN_VERSION) \
16+
--build-arg TAG_EXTENSION=$(TAG_EXTENSION) \
17+
--build-arg IMAGE="$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" \
18+
--build-arg VCS_REF="$(VCS_REF)" \
19+
--build-arg VCS_URL="$(VCS_URL)" \
20+
--build-arg BUILD_DATE="$(BUILD_DATE)" \
21+
.
22+
23+
.PHONY: build

go1.10/Makefile.debian7

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
IMAGES := base main
2+
DEBIAN_VERSION := 7
3+
TAG_EXTENSION := -debian7
4+
5+
export DEBIAN_VERSION TAG_EXTENSION
6+
7+
build:
8+
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;)
9+
10+
# Requires login at https://docker.elastic.co:7000/.
11+
push:
12+
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) push || exit 1;)
13+
14+
.PHONY: build push

go1.10/arm/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Makefile

go1.10/arm/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG REPOSITORY
2+
ARG VERSION
3+
FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base
4+
5+
RUN \
6+
apt-get update && apt-get install -y --no-install-recommends \
7+
crossbuild-essential-arm64 \
8+
crossbuild-essential-armel \
9+
crossbuild-essential-armhf \
10+
linux-libc-dev-arm64-cross \
11+
linux-libc-dev-armel-cross \
12+
linux-libc-dev-armhf-cross \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
COPY rootfs /
16+
17+
# Build-time metadata as defined at http://label-schema.org.
18+
ARG BUILD_DATE
19+
ARG IMAGE
20+
ARG VCS_REF
21+
ARG VCS_URL
22+
LABEL org.label-schema.build-date=$BUILD_DATE \
23+
org.label-schema.name=$IMAGE \
24+
org.label-schema.vcs-ref=$VCS_REF \
25+
org.label-schema.vcs-url=$VCS_URL \
26+
org.label-schema.schema-version="1.0"

go1.10/arm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../Makefile.common

go1.10/arm/rootfs/compilers.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
3+
linux:
4+
armv7:
5+
CC: arm-linux-gnueabihf-gcc
6+
CXX: arm-linux-gnueabihf-g++
7+
armv6:
8+
# Using debian armel for ARMv6.
9+
# This is the same as ARMv5 so it will use softfp instead of hardfp.
10+
CC: arm-linux-gnueabi-gcc
11+
CXX: arm-linux-gnueabi-g++
12+
armv5:
13+
CC: arm-linux-gnueabi-gcc
14+
CXX: arm-linux-gnueabi-g++
15+
arm64:
16+
CC: aarch64-linux-gnu-gcc
17+
CXX: aarch64-linux-gnu-g++

go1.10/base/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Makefile

go1.10/base/Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
ARG DEBIAN_VERSION
2+
FROM debian:${DEBIAN_VERSION}
3+
4+
RUN \
5+
apt-get update \
6+
&& apt-get dist-upgrade -y \
7+
&& apt-get install -y --no-install-recommends \
8+
build-essential \
9+
ca-certificates \
10+
curl \
11+
git \
12+
gnupg \
13+
make \
14+
file \
15+
flex \
16+
bison \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
ARG GOLANG_VERSION=1.10.3
20+
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
21+
ARG GOLANG_DOWNLOAD_SHA256=fa1b0e45d3b647c252f51f5e1204aba049cde4af177ef9f2181f43004f901035
22+
23+
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
24+
&& echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \
25+
&& tar -C /usr/local -xzf golang.tar.gz \
26+
&& rm golang.tar.gz
27+
28+
ENV GOPATH /go
29+
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
30+
31+
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
32+
WORKDIR $GOPATH
33+
34+
ARG MAGE_VERSION=2.1
35+
ARG MAGE_DOWNLOAD_URL=https://github.com/magefile/mage/releases/download/${MAGE_VERSION}/mage_${MAGE_VERSION}_Linux-64bit.tar.gz
36+
ARG MAGE_DOWNLOAD_SHA256=44f4a34fcf7bd17c11c6ed2a7b495900c771289c580fdef517a950fdccd15e02
37+
38+
RUN curl -fsSL "$MAGE_DOWNLOAD_URL" -o mage.tar.gz \
39+
&& echo "$MAGE_DOWNLOAD_SHA256 mage.tar.gz" | sha256sum -c - \
40+
&& mkdir /usr/local/mage \
41+
&& tar -C /usr/local/mage -xzf mage.tar.gz \
42+
&& rm mage.tar.gz
43+
ENV PATH /usr/local/mage:$PATH
44+
45+
COPY rootfs /
46+
47+
WORKDIR /
48+
RUN go get -d . \
49+
&& go build -o /crossbuild /entrypoint.go \
50+
&& rm -rf /go/* /root/.cache/* /entrypoint.go
51+
52+
ENV GOLANG_CROSSBUILD=1
53+
VOLUME /app
54+
WORKDIR /app
55+
ENTRYPOINT ["/crossbuild"]

go1.10/base/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../Makefile.common

0 commit comments

Comments
 (0)