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

0 commit comments

Comments
 (0)