-
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.
Docker images for cross-building Beats
- Loading branch information
0 parents
commit f047f0d
Showing
39 changed files
with
698 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# See: http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[Dockerfile] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[Makefile] | ||
indent_style = tab |
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,6 @@ | ||
*.iml | ||
*.swp | ||
*.o | ||
.idea | ||
.vagrant | ||
_obj |
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,12 @@ | ||
build: | ||
@make -C go1.10 $@ | ||
@make -C go1.10 -f Makefile.debian7 $@ | ||
@make -C fpm $@ | ||
|
||
# Requires login at https://docker.elastic.co:7000/. | ||
push: | ||
@make -C go1.10 $@ | ||
@make -C go1.10 -f Makefile.debian7 $@ | ||
@make -C fpm $@ | ||
|
||
.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,13 @@ | ||
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 tag "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" "push.$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" | ||
@docker push "push.$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" | ||
|
||
.PHONY: 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,39 @@ | ||
# golang-crossbuild | ||
|
||
golang-crossbuild is a set of Docker images containing the requisite | ||
cross-compilers for cross compiling Go applications. The cross-compilers are | ||
needed when the application uses [cgo](https://golang.org/cmd/cgo/). | ||
|
||
The base image used is Debian 9 (stretch) unless otherwise specified. | ||
|
||
## Docker Repo | ||
|
||
`docker.elastic.co/beats-dev/golang-crossbuild:[TAG]` | ||
|
||
## Build Tags | ||
|
||
- `1.10.3-main` - linux/{amd64,386} and windows/{amd64,386} | ||
- `1.10.3-arm` - linux/{armv5,armv6,armv7,arm64} | ||
- `1.10.3-darwin` - darwin/{amd64,386} | ||
- `1.10.3-ppc` - linux/{ppc64,ppc64le} | ||
- `1.10.3-mips` - linux/{mips,mipsle,mips64,mips64le} | ||
- `1.10.3-s390x` - linux/s390x | ||
- `1.10.3-main-debian7` - linux/{amd64,386} and windows/{amd64,386} (Debian 7 | ||
uses glibc 2.13 so the resulting binaries (if dynamically linked) have greater | ||
compatibility.) | ||
|
||
## Usage Example | ||
|
||
```sh | ||
docker run -it --rm \ | ||
-v $GOPATH/src/github.com/user/go-project:/go/src/github.com/user/go-project \ | ||
-w /go/src/github.com/user/go-project \ | ||
-env CGO_ENABLED=1 \ | ||
docker.elastic.co/beats-dev/golang-crossbuild:1.10.3-arm \ | ||
--build-cmd "make build" \ | ||
-p "linux/armv7" | ||
``` | ||
|
||
This will execute your projects `make build` target. While executing the build | ||
command the following variables with be added to the environment: GOOS, GOARCH, | ||
GOARM, PLATFORM_ID, CC, and CXX. |
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,40 @@ | ||
FROM debian:stable | ||
LABEL maintainer="Elastic Beats Team" | ||
|
||
RUN \ | ||
apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
autoconf build-essential libffi-dev ruby-dev rpm zip dos2unix libgmp3-dev \ | ||
curl make gcc \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG SUEXEC_VERSION=0.2 | ||
ARG SUEXEC_DOWNLOAD_URL=https://github.com/ncopa/su-exec/archive/v${SUEXEC_VERSION}.tar.gz | ||
ARG SUEXEC_DOWNLOAD_SHA256=ec4acbd8cde6ceeb2be67eda1f46c709758af6db35cacbcde41baac349855e25 | ||
|
||
RUN \ | ||
curl -fsSL "$SUEXEC_DOWNLOAD_URL" -o suexec.tar.gz \ | ||
&& echo "$SUEXEC_DOWNLOAD_SHA256 suexec.tar.gz" | sha256sum -c - \ | ||
&& mkdir /suexec \ | ||
&& tar -C /suexec --strip-components=1 -xzf suexec.tar.gz \ | ||
&& make -C /suexec \ | ||
&& mv /suexec/su-exec /usr/bin/ \ | ||
&& rm -rf /suexec suexec.tar.gz | ||
|
||
ARG FPM_VERSION | ||
RUN gem install fpm -v "$FPM_VERSION" | ||
|
||
COPY rootfs / | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
# 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,16 @@ | ||
include ../Makefile.common | ||
|
||
NAME := fpm | ||
VERSION := 1.10.0 | ||
|
||
build: | ||
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)" | ||
@docker build -t "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)" \ | ||
--build-arg FPM_VERSION=$(VERSION) \ | ||
--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 |
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,10 @@ | ||
#!/usr/bin/env sh | ||
|
||
if [ -z ${EXEC_UID+x} ] || [ -z ${EXEC_GID+x} ]; then | ||
exec "$@" | ||
fi | ||
|
||
groupadd -f -g "$EXEC_GID" fpm | ||
useradd -N -m -c 'FPM User' -u "$EXEC_UID" -g "$EXEC_GID" fpm | ||
|
||
su-exec fpm "$@" |
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,10 @@ | ||
IMAGES := base main darwin arm mips ppc 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 |
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,23 @@ | ||
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) | ||
include $(SELF_DIR)/../Makefile.common | ||
|
||
NAME := golang-crossbuild | ||
VERSION := 1.10.3 | ||
DEBIAN_VERSION ?= 9 | ||
SUFFIX := -$(shell basename $(CURDIR)) | ||
TAG_EXTENSION ?= | ||
|
||
build: | ||
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)" | ||
@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 |
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 @@ | ||
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,26 @@ | ||
ARG REPOSITORY | ||
ARG VERSION | ||
FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-base | ||
|
||
RUN \ | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
crossbuild-essential-arm64 \ | ||
crossbuild-essential-armel \ | ||
crossbuild-essential-armhf \ | ||
linux-libc-dev-arm64-cross \ | ||
linux-libc-dev-armel-cross \ | ||
linux-libc-dev-armhf-cross \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY rootfs / | ||
|
||
# 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 @@ | ||
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,55 @@ | ||
ARG DEBIAN_VERSION | ||
FROM debian:${DEBIAN_VERSION} | ||
|
||
RUN \ | ||
apt-get update \ | ||
&& apt-get dist-upgrade -y \ | ||
&& apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
ca-certificates \ | ||
curl \ | ||
git \ | ||
gnupg \ | ||
make \ | ||
file \ | ||
flex \ | ||
bison \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ARG GOLANG_VERSION=1.10.3 | ||
ARG GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz | ||
ARG GOLANG_DOWNLOAD_SHA256=fa1b0e45d3b647c252f51f5e1204aba049cde4af177ef9f2181f43004f901035 | ||
|
||
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 | ||
|
||
ARG MAGE_VERSION=2.1 | ||
ARG MAGE_DOWNLOAD_URL=https://github.com/magefile/mage/releases/download/${MAGE_VERSION}/mage_${MAGE_VERSION}_Linux-64bit.tar.gz | ||
ARG MAGE_DOWNLOAD_SHA256=44f4a34fcf7bd17c11c6ed2a7b495900c771289c580fdef517a950fdccd15e02 | ||
|
||
RUN curl -fsSL "$MAGE_DOWNLOAD_URL" -o mage.tar.gz \ | ||
&& echo "$MAGE_DOWNLOAD_SHA256 mage.tar.gz" | sha256sum -c - \ | ||
&& mkdir /usr/local/mage \ | ||
&& tar -C /usr/local/mage -xzf mage.tar.gz \ | ||
&& rm mage.tar.gz | ||
ENV PATH /usr/local/mage:$PATH | ||
|
||
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"] |
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.