Skip to content

Add multi-arch support for golang-http-template #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2020

Conversation

utsavanand2
Copy link
Contributor

@utsavanand2 utsavanand2 commented Sep 8, 2020

Description

Add multi-arch support for golang-http-template

How Has This Been Tested?

Multi-Arch function build

# Pull golang-http multi-arch template
faas-cli template pull https://github.com/utsavanand2/golang-http-template

# Create new golang-middleware function named hello-http
faas-cli new --lang golang-middleware --prefix utsavanand2 hello-http

# Create a shrinkwrapped build of function
faas build -f hello-http.yml --shrinkwrap

# Use buildx to build and push function image to container registry
docker buildx build \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--output "type=image,push=true" \
--tag utsavanand2/hello-http:latest build/hello-http/

# Deploy hello-http function to a Raspberry Pi k3s cluster running OpenFaaS
faas deploy -f hello-http.yml

Making sure faas-cli up works the same way as before.

# Build, push and deploy hello-http function to minikube (amd64 arch)
faas up -f hello-http.yml
[0] > Building hello-http.
Clearing temporary build folder: ./build/hello-http/
Preparing: ./hello-http/ build/hello-http/function
Building: utsavanand2/hello-http:latest with golang-middleware template. Please wait..
Sending build context to Docker daemon  10.75kB
Step 1/33 : FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/of-watchdog:0.8.0 as watchdog
 ---> 1ebcac6b156c
Step 2/33 : FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13-alpine3.11 as build
 ---> 92388aa37316
Step 3/33 : ARG TARGETPLATFORM
 ---> Running in 52cb91f47f6b
Removing intermediate container 52cb91f47f6b
 ---> 88f563431305
Step 4/33 : ARG BUILDPLATFORM
 ---> Running in b964529d9371
Removing intermediate container b964529d9371
 ---> ba68776ec208
Step 5/33 : ARG TARGETOS
 ---> Running in 124709b0e92f
Removing intermediate container 124709b0e92f
 ---> ef74d407e334
Step 6/33 : ARG TARGETARCH
 ---> Running in 624f36ad4751
Removing intermediate container 624f36ad4751
 ---> 6d2ec438c750
Step 7/33 : RUN apk --no-cache add git
 ---> Running in 833cae1ea36c
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/5) Installing nghttp2-libs (1.40.0-r1)
(2/5) Installing libcurl (7.67.0-r0)
(3/5) Installing expat (2.2.9-r1)
(4/5) Installing pcre2 (10.34-r1)
(5/5) Installing git (2.24.3-r0)
Executing busybox-1.31.1-r9.trigger
OK: 22 MiB in 20 packages
Removing intermediate container 833cae1ea36c
 ---> 8919d06cccd9
Step 8/33 : COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
 ---> 1aeab48cdc3f
Step 9/33 : RUN chmod +x /usr/bin/fwatchdog
 ---> Running in 9b51e9713b89
Removing intermediate container 9b51e9713b89
 ---> 23bac12b1ebf
Step 10/33 : ENV CGO_ENABLED=0
 ---> Running in 9bc00f88b516
Removing intermediate container 9bc00f88b516
 ---> bbe16324d540
Step 11/33 : RUN mkdir -p /go/src/handler
 ---> Running in 1af68efae960
Removing intermediate container 1af68efae960
 ---> 280c8a2b41f9
Step 12/33 : WORKDIR /go/src/handler
 ---> Running in d581cf7104ad
Removing intermediate container d581cf7104ad
 ---> 06c780e6bae2
Step 13/33 : COPY . .
 ---> 5a9e9045c162
Step 14/33 : RUN cat function/GO_REPLACE.txt >> ./go.mod || exit 0
 ---> Running in 10f8554ceaf1
cat: can't open 'function/GO_REPLACE.txt': No such file or directory
Removing intermediate container 10f8554ceaf1
 ---> ece7234bf408
Step 15/33 : RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }
 ---> Running in 04a632bd6e8c
Removing intermediate container 04a632bd6e8c
 ---> fa7bbb5f4fc4
Step 16/33 : ARG GO111MODULE="off"
 ---> Running in b65c1d06e594
Removing intermediate container b65c1d06e594
 ---> 141ae4276228
Step 17/33 : ARG GOPROXY=""
 ---> Running in 7b4335dc2588
Removing intermediate container 7b4335dc2588
 ---> b81a9d1af925
Step 18/33 : ARG GOFLAGS=""
 ---> Running in 30b572b25bad
Removing intermediate container 30b572b25bad
 ---> f2f9599e3f5b
Step 19/33 : WORKDIR /go/src/handler/function
 ---> Running in 1a8a0d7d93e5
Removing intermediate container 1a8a0d7d93e5
 ---> 4c59b104254f
Step 20/33 : RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test ./... -cover
 ---> Running in 285c7ff2012d
?   	handler/function	[no test files]
Removing intermediate container 285c7ff2012d
 ---> 7021a150d180
Step 21/33 : WORKDIR /go/src/handler
 ---> Running in 17668fb27dc0
Removing intermediate container 17668fb27dc0
 ---> 9a27e27867f4
Step 22/33 : RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH}     go build --ldflags "-s -w" -a -installsuffix cgo -o handler .
 ---> Running in 7c64ec9774ce
Removing intermediate container 7c64ec9774ce
 ---> fc340aafe802
Step 23/33 : FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.11
 ---> f70734b6a266
Step 24/33 : RUN apk --no-cache add ca-certificates     && addgroup -S app && adduser -S -g app app     && mkdir -p /home/app     && chown app /home/app
 ---> Using cache
 ---> f648c1c514cb
Step 25/33 : WORKDIR /home/app
 ---> Using cache
 ---> 6f2c49c45541
Step 26/33 : COPY --from=build --chown=app /go/src/handler/handler    .
 ---> ec5d1d5b4182
Step 27/33 : COPY --from=build --chown=app /usr/bin/fwatchdog         .
 ---> ac472d068aa4
Step 28/33 : COPY --from=build --chown=app /go/src/handler/function/  .
 ---> 3c0f4812ac17
Step 29/33 : USER app
 ---> Running in b7bd08bfda39
Removing intermediate container b7bd08bfda39
 ---> f282f777a185
Step 30/33 : ENV fprocess="./handler"
 ---> Running in 353604ad8e48
Removing intermediate container 353604ad8e48
 ---> 72676a10f2ef
Step 31/33 : ENV mode="http"
 ---> Running in 93f26d24e3e5
Removing intermediate container 93f26d24e3e5
 ---> a864a32459db
Step 32/33 : ENV upstream_url="http://127.0.0.1:8082"
 ---> Running in 074fa2f1abb1
Removing intermediate container 074fa2f1abb1
 ---> b98af2b05183
Step 33/33 : CMD ["./fwatchdog"]
 ---> Running in b7b4c8e3f0f5
Removing intermediate container b7b4c8e3f0f5
 ---> 95c0acf0e26a
Successfully built 95c0acf0e26a
Successfully tagged utsavanand2/hello-http:latest
Image: utsavanand2/hello-http:latest built.
[0] < Building hello-http done in 41.42s.
[0] Worker done.

Total build time: 41.42s

[0] > Pushing hello-http [utsavanand2/hello-http:latest].
The push refers to repository [docker.io/utsavanand2/hello-http]
4a700a70f29e: Pushed
f829820e558e: Pushed
f8ccc94ba5be: Pushed
aaef15da4c38: Mounted from utsavanand2/popular-repos
3e207b409db3: Layer already exists
latest: digest: sha256:87e8999244f7f32311e83a69c9c3c99e557b736c5517138c53b99220a1d5a960 size: 1367
[0] < Pushing hello-http [utsavanand2/hello-http:latest] done.
[0] Worker done.

Deploying: hello-http.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/hello-http.openfaas-fn


# Invoke function deployed on minikube running on amd64
curl -d 'Hello' http://127.0.0.1:8080/function/hello-http
Hello world, input was: Hello

How are existing users impacted? What migration steps/scripts do we need?

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • read the CONTRIBUTION guide
  • signed-off my commits with git commit -s
  • added unit tests

FROM openfaas/of-watchdog:0.8.0 as watchdog
FROM golang:1.13-alpine3.11 as build
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/of-watchdog:0.8.0 as watchdog
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13-alpine3.11 as build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we upgrade to golang:1.13-alpine3.12 please?


FROM alpine:3.11
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment. Please let's move to 3.12?

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Ready to merge, but please update to 3.12 in a follow-up PR.

@alexellis alexellis merged commit 973f944 into openfaas:master Sep 11, 2020
@utsavanand2
Copy link
Contributor Author

utsavanand2 commented Sep 11, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants