git.iko.soy/typeable/oauth2-proxy
on master help sign in
feat(arm): Cross build arm and arm64 docker images

- Requires `qemu-user-static`, added to travis - maybe incorrect? - Add build guide - `.gitignore` `release/` directory

commit90e6bd278ec906fe9dc122876ef86dd50f6f81dd authorKarl Skewes <karl.skewes@gmail.com> dateSat 2 Feb 2019, 12:08 (8 years ago) parent2bdf00a
9 files changed+138
.gitignore+1 .travis.yml+3 BUILDING.md+52 CHANGELOG.md+1 CONTRIBUTING.md+3 Dockerfile.arm64+24 Dockerfile.armv6+24 Makefile+28 README.md+2
.gitignore+1
@@ -1,6 +1,7 @@
11oauth2_proxy
22vendor
33dist
4+release
45.godeps
56*.exe
67.env
.travis.yml+3
@@ -2,6 +2,9 @@ language: go
22go:
33 - 1.10.x
44 - 1.11.x
5+before_install:
6+ - sudo apt-get install -y qemu-user-static
7+ - sudo docker run --rm --privileged multiarch/qemu-user-static:register
58install:
69 # Fetch dependencies
710 - wget -O dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
BUILDING.mdnew file+52
@@ -0,0 +1,52 @@
1+# Building
2+
3+This project is setup to build on amd64.
4+
5+It is also possible to cross build binaries and docker images for armv6 and arm64.
6+
7+## Clone repo and configure
8+
9+```bash
10+cd $GOPATH/src/github.com # Create this directory if it doesn't exist
11+git clone git@github.com:<YOUR_FORK>/oauth2_proxy pusher/oauth2_proxy
12+cd pusher/oauth2_proxy
13+./configure # Setup your environment variables
14+make dep
15+```
16+
17+## Building amd64
18+
19+Build binary:
20+```bash
21+make
22+```
23+
24+Build docker image:
25+```bash
26+make docker
27+```
28+
29+## Building for other architectures
30+
31+This requires [multiarch/qemu-user-static](https://github.com/multiarch/qemu-user-static) to be installed in your system.
32+On Ubuntu:
33+```bash
34+sudo apt install qemu-user-static
35+```
36+
37+Register `qemu-user-static` on your system:
38+```bash
39+# make qemu-register
40+# or
41+sudo docker run --rm --privileged multiarch/qemu-user-static:register
42+```
43+
44+Build all binaries:
45+```bash
46+make release
47+```
48+
49+Build all docker images:
50+```bash
51+make docker-all
52+```
CHANGELOG.md+1
@@ -14,6 +14,7 @@
1414 - After a successful login, you will be redirected to your original URL rather than /
1515- [#35](https://github.com/pusher/oauth2_proxy/pull/35) arm and arm64 binary releases (@kskewes)
1616 - Add armv6 and arm64 to Makefile `release` target
17+- [#37](https://github.com/pusher/oauth2_proxy/pull/37) cross build arm and arm64 docker images (@kskewes)
1718
1819# v3.0.0
1920
CONTRIBUTING.md+3
@@ -5,9 +5,12 @@ To develop on this project, please fork the repo and clone into your `$GOPATH`.
55Dependencies are **not** checked in so please download those separately.
66Download the dependencies using [`dep`](https://github.com/golang/dep).
77
8+
89```bash
910cd $GOPATH/src/github.com # Create this directory if it doesn't exist
1011git clone git@github.com:<YOUR_FORK>/oauth2_proxy pusher/oauth2_proxy
12+cd pusher/oauth2_proxy
13+./configure # Setup your environment variables
1114make dep
1215```
1316
Dockerfile.arm64new file+24
@@ -0,0 +1,24 @@
1+FROM golang:1.11-stretch AS builder
2+
3+# Download tools
4+RUN wget -O $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
5+RUN chmod +x $GOPATH/bin/dep
6+
7+# Copy sources
8+WORKDIR $GOPATH/src/github.com/pusher/oauth2_proxy
9+COPY . .
10+
11+# Fetch dependencies
12+RUN dep ensure --vendor-only
13+
14+# Build binary
15+RUN ./configure && GOARCH=arm64 make build
16+
17+# Copy binary to alpine
18+FROM arm64v8/alpine:3.8
19+COPY dist/qemu-aarch64-static /usr/bin/
20+RUN apk add --no-cache ca-certificates
21+COPY --from=builder /go/src/github.com/pusher/oauth2_proxy/oauth2_proxy /bin/oauth2_proxy
22+RUN rm /usr/bin/qemu-*-static -f
23+
24+ENTRYPOINT ["/bin/oauth2_proxy"]
Dockerfile.armv6new file+24
@@ -0,0 +1,24 @@
1+FROM golang:1.11-stretch AS builder
2+
3+# Download tools
4+RUN wget -O $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
5+RUN chmod +x $GOPATH/bin/dep
6+
7+# Copy sources
8+WORKDIR $GOPATH/src/github.com/pusher/oauth2_proxy
9+COPY . .
10+
11+# Fetch dependencies
12+RUN dep ensure --vendor-only
13+
14+# Build binary
15+RUN ./configure && GOARCH=arm GOARM=6 make build
16+
17+# Copy binary to alpine
18+FROM arm32v6/alpine:3.8
19+COPY dist/qemu-arm-static /usr/bin/
20+RUN apk add --no-cache ca-certificates
21+COPY --from=builder /go/src/github.com/pusher/oauth2_proxy/oauth2_proxy /bin/oauth2_proxy
22+RUN rm /usr/bin/qemu-*-static -f
23+
24+ENTRYPOINT ["/bin/oauth2_proxy"]
Makefile+28
@@ -45,6 +45,34 @@ build: clean $(BINARY)
4545$(BINARY):
4646 CGO_ENABLED=0 $(GO) build -a -installsuffix cgo -ldflags="-X main.VERSION=${VERSION}" -o $@ github.com/pusher/oauth2_proxy
4747
48+# Ubuntu 18.04.1 Qemu version
49+QEMU-STATIC-VERSION=v2.11.1
50+
51+.PHONY: qemu-static
52+qemu-static:
53+ wget -O dist/qemu-amd64-static https://github.com/multiarch/qemu-user-static/releases/download/${QEMU-STATIC-VERSION}/qemu-x86_64-static
54+ wget -O dist/qemu-aarch64-static https://github.com/multiarch/qemu-user-static/releases/download/${QEMU-STATIC-VERSION}/qemu-aarch64-static
55+ wget -O dist/qemu-arm-static https://github.com/multiarch/qemu-user-static/releases/download/${QEMU-STATIC-VERSION}/qemu-arm-static
56+ chmod +x dist/qemu-*-static
57+
58+.PHONY: qemu-register
59+qemu-register:
60+ docker run --rm --privileged multiarch/qemu-user-static:register
61+
62+.PHONY: docker
63+docker:
64+ docker build -f Dockerfile -t pusher/oauth2_proxy:latest .
65+
66+.PHONY: docker-all
67+docker-all: qemu-static docker
68+ docker build -f Dockerfile -t pusher/oauth2_proxy:latest-amd64 .
69+ docker build -f Dockerfile -t pusher/oauth2_proxy:${VERSION} .
70+ docker build -f Dockerfile -t pusher/oauth2_proxy:${VERSION}-amd64 .
71+ docker build -f Dockerfile.arm64 -t pusher/oauth2_proxy:latest-arm64 .
72+ docker build -f Dockerfile.arm64 -t pusher/oauth2_proxy:${VERSION}-arm64 .
73+ docker build -f Dockerfile.armv6 -t pusher/oauth2_proxy:latest-armv6 .
74+ docker build -f Dockerfile.armv6 -t pusher/oauth2_proxy:${VERSION}-armv6 .
75+
4876.PHONY: test
4977test: dep lint
5078 $(GO) test -v -race $(go list ./... | grep -v /vendor/)
README.md+2
@@ -25,6 +25,8 @@ A list of changes can be seen in the [CHANGELOG](CHANGELOG.md).
2525
2626 c. Using the prebuilt docker image [quay.io/pusher/oauth2_proxy](https://quay.io/pusher/oauth2_proxy)
2727
28+ d. Building from scratch following our [Building](BUILDING.md) guide
29+
2830Prebuilt binaries can be validated by extracting the file and verifying it against the `sha256sum.txt` checksum file provided for each release starting with version `v3.0.0`.
2931
3032```