Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Make edge-router build multi-arch
Browse files Browse the repository at this point in the history
This commit converts the edge-route dockerfile to multi-arch builds.
This was tested on a ofc cluster. After swapping in the new container
the service worked as normal

Signed-off-by: Alistair Hey <alistair@heyal.co.uk>
  • Loading branch information
Waterdrips authored and alexellis committed Nov 18, 2020
1 parent a402aba commit cfd3027
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 33 deletions.
55 changes: 54 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ on:
- '*'

jobs:
build:
# Run the CI tests
test:
strategy:
matrix:
go-version: [1.13.x]
Expand All @@ -25,3 +26,55 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Run CI
run: sh ./contrib/ci.sh

# Test building the non-cli Containers
build-containers:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.13.x]
svc: [
edge-auth,
edge-router,
of-builder
]
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Get TAG
id: get_tag
run: echo ::set-output name=TAG::latest-dev
- name: Build ${{ matrix.svc }}
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.svc }}
file: ./${{ matrix.svc }}/Dockerfile
outputs: "type=image,push=false"
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: |
ghcr.io/openfaas/${{ matrix.svc }}:${{ steps.get_tag.outputs.TAG }}
ghcr.io/openfaas/${{ matrix.svc }}:${{ github.sha }}
ghcr.io/openfaas/${{ matrix.svc }}:latest
# TODO add build for all containers in here
build-stack:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.13.x]
svc: [
edge-auth,
edge-router,
of-builder
]
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Get TAG
id: get_tag
run: echo ::set-output name=TAG::latest-dev
32 changes: 19 additions & 13 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ jobs:
]
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
Expand All @@ -38,13 +40,17 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
- name: Build and push ${{ matrix.svc }}
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.svc }}
file: ./${{ matrix.svc }}/Dockerfile
outputs: "type=registry,push=true"
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: |
ghcr.io/openfaas/${{ matrix.svc }}:${{ steps.get_tag.outputs.TAG }}
ghcr.io/openfaas/${{ matrix.svc }}:${{ github.sha }}
ghcr.io/openfaas/${{ matrix.svc }}:latest
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.svc }}
file: ./${{ matrix.svc }}/Dockerfile
outputs: "type=registry,push=true"
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: |
ghcr.io/openfaas/${{ matrix.svc }}:${{ steps.get_tag.outputs.TAG }}
ghcr.io/openfaas/${{ matrix.svc }}:${{ github.sha }}
ghcr.io/openfaas/${{ matrix.svc }}:latest
# Need a section for faas-cli on each fn in stack.yaml
# section for of-dashboard's stack.yaml
# https://github.com/alexellis/multiarch-templates/
# Section to run the chart tests
1 change: 1 addition & 0 deletions dashboard/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ provider:
name: openfaas
gateway: http://127.0.0.1:8080

# TODO Waterdrips this multi-arch
functions:
system-dashboard:
lang: node12
Expand Down
3 changes: 1 addition & 2 deletions edge-auth/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
auth
edge-auth
/edge-auth
8 changes: 5 additions & 3 deletions edge-auth/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ COPY template template
COPY provider provider
COPY main.go .

RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v ./...
RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")

RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go build \
--ldflags "-s -w" \
-a -installsuffix cgo -o edge-auth .

-a -installsuffix cgo \
-o edge-auth .

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12 as ship

Expand Down
8 changes: 0 additions & 8 deletions edge-auth/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
name = "github.com/dgrijalva/jwt-go"
version = "3.2.0"

[[constraint]]
name = "github.com/alexellis/hmac"
version = "1.2"

[[constraint]]
name = "github.com/openfaas/faas-provider"
version = "v0.15.0"

[[constraint]]
name = "github.com/openfaas/openfaas-cloud"
version = "0.13.0"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions edge-router/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM golang:1.13-alpine AS build
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13 as build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

WORKDIR /go/src/github.com/openfaas/openfaas-cloud/edge-router

Expand All @@ -12,17 +17,23 @@ COPY config_test.go .
COPY health.go .
COPY auth_proxy.go .

RUN go test -v \
&& go build -o /usr/bin/edge-router .
RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go build \
--ldflags "-s -w" \
-a -installsuffix cgo \
-o edge-router .


FROM alpine:3.12 as ship
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12 as ship

RUN apk --no-cache add ca-certificates \
&& addgroup -S app && adduser -S -g app app \
&& mkdir -p /home/app \
&& chown app /home/app

COPY --from=build /usr/bin/edge-router /bin/
COPY --from=build /go/src/github.com/openfaas/openfaas-cloud/edge-router /bin/

WORKDIR /home/app/
USER app
Expand Down
2 changes: 2 additions & 0 deletions of-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM golang:1.13-alpine AS builder

## AH TODO set this up as a multi-arch build

ENV CGO_ENABLED=0
ENV GO111MODULE=off

Expand Down
2 changes: 1 addition & 1 deletion stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ functions:
requests:
memory: 32Mi
cpu: 50m

# TODO waterdrips, this dockerfile multiarch?
git-tar:
lang: dockerfile
handler: ./git-tar
Expand Down

0 comments on commit cfd3027

Please sign in to comment.