Skip to content

openfaas

Cnaik edited this page Jun 24, 2019 · 1 revision

# Building OpenFaas

Install GO

export work_dir=/home
apt update && apt install -y make curl
wget https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Go/build_go.sh
bash build_go.sh -v 1.10.4
mkdir $work_dir/go && export GOPATH=$work_dir/go

Build gateway 0.13.4

go get github.com/openfaas/faas/gateway
cd $work_dir/go/src/github.com/openfaas/faas/gateway
git checkout tags/0.13.4

Create Dockerfile named Dockerfile.gate-s390x with following contents:

FROM s390x/golang:1.10.4 as build
WORKDIR /go/src/github.com/openfaas/faas/gateway

#RUN curl -sL https://github.com/alexellis/license-check/releases/download/0.1/license-check > /usr/bin/license-check && chmod +x /usr/bin/license-check

COPY vendor         vendor

COPY handlers       handlers
COPY metrics        metrics
COPY requests       requests
COPY tests          tests

COPY types          types
COPY queue          queue
COPY plugin         plugin
COPY version        version
COPY scaling        scaling
COPY server.go      .

#Run a gofmt and exclude all vendored code.
#RUN license-check -path ./ --verbose=false \
RUN GOARCH=s390x CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o gateway .

FROM s390x/alpine:3.8

RUN addgroup -S app \
    && adduser -S -g app app

WORKDIR /home/app

EXPOSE 8080
EXPOSE 8082
ENV http_proxy      ""
ENV https_proxy     ""

COPY --from=build /go/src/github.com/openfaas/faas/gateway/gateway    .
COPY assets     assets

RUN chown -R app:app ./

USER app

RUN sed -ie s/store.json/store-s390x.json/g /home/app/assets/script/funcstore.js

CMD ["./gateway"]

Build gateway image

docker build -f Dockerfile.gate-s390x -t openfaas/gateway:0.13.4-s390x .

Build faas-swarm 0.6.2

cd $work_dir
git clone https://github.com/openfaas/faas-swarm
cd faas-swarm/
git checkout 0.6.2

Create Dockerfile named Dockerfile.s390x with following contents:

FROM s390x/golang:1.10.4 as build

RUN mkdir -p /go/src/github.com/openfaas/faas-swarm/

WORKDIR /go/src/github.com/openfaas/faas-swarm

COPY . .

#RUN curl -sL https://github.com/alexellis/license-check/releases/download/0.2.2/license-check > /usr/bin/license-check \
#    && chmod +x /usr/bin/license-check
#RUN license-check -path ./ --verbose=false "Alex Ellis" "OpenFaaS Author(s)"

RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") \
    && go test $(go list ./... | grep -v /vendor/) -cover \
    && VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \
    && GIT_COMMIT=$(git rev-list -1 HEAD) \
    && GOARCH=s390x CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w \
    -X github.com/openfaas/faas-swarm/version.GitCommit=${GIT_COMMIT}\
    -X github.com/openfaas/faas-swarm/version.Version=${VERSION}" \
    -a -installsuffix cgo -o faas-swarm .

# Release stage
FROM s390x/alpine:3.8

LABEL org.label-schema.license="MIT" \
      org.label-schema.vcs-url="https://github.com/openfaas/faas-swarm" \
      org.label-schema.vcs-type="Git" \
      org.label-schema.name="openfaas/faas-swarm" \
      org.label-schema.vendor="openfaas" \
      org.label-schema.docker.schema-version="1.0"

RUN apk --no-cache add ca-certificates

WORKDIR /root/

EXPOSE 8080

ENV http_proxy      ""
ENV https_proxy     ""

COPY --from=build /go/src/github.com/openfaas/faas-swarm/faas-swarm    .

CMD ["./faas-swarm"]

Build the faas-swarm image

docker build -f Dockerfile.s390x -t openfaas/faas-swarm:0.6.2-s390x .

Build prometheus 2.7.1

cd $work_dir/go/src/github.com
mkdir -p Prometheus && cd Prometheus
wget https://raw.githubusercontent.com/linux-on-ibm-z/dockerfile-examples/master/Prometheus/Dockerfile

Add following to the Dockerfile

--- Dockerfile  2019-06-07 06:59:06.372589452 +0000
+++ Dockerfile.prom-s390x       2019-06-03 13:15:24.893720284 +0000
@@ -54,5 +54,5 @@
 #Export port
 EXPOSE 9090
 VOLUME [ "/prometheus" ]
-
+ENTRYPOINT [ "/prometheus/prometheus" ]
 CMD prometheus --config.file=/etc/prometheus/prometheus.yml --web.console.libraries=/etc/prometheus/console_libraries --web.console.templates=/etc/prometheus/consoles

Build prometheus image

docker build -f Dockerfile -t prom/prometheus:v2.7.1-s390x .

Build queue-worker 0.7.2

cd $work_dir
git clone https://github.com/openfaas/nats-queue-worker
cd nats-queue-worker
git checkout 0.7.2

Create Dockerfile named Dockerfile.s390x with following contents:

FROM s390x/golang:1.10-alpine as golang
WORKDIR /go/src/github.com/openfaas/nats-queue-worker

COPY vendor     vendor
COPY handler    handler
COPY nats       nats
COPY main.go  .
COPY types.go .
COPY readconfig.go .
COPY readconfig_test.go .
COPY auth.go .


RUN GOARCH=s390x CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM s390x/alpine:3.9

RUN addgroup -S app \
  && adduser -S -g app app \
  && apk add --no-cache ca-certificates

WORKDIR /home/app

EXPOSE 8080

ENV http_proxy      ""
ENV https_proxy     ""

COPY --from=golang /go/src/github.com/openfaas/nats-queue-worker/app    .

RUN chown -R app:app ./

USER app
CMD ["./app"]

Build queue-worker image

docker build -f Dockerfile.s390x -t openfaas/queue-worker:0.7.2-s390x .

Build prom-alertmanager 0.16.2

cd $work_dir
git clone https://github.com/prometheus/alertmanager
cd alertmanager
git checkout v0.16.2

Create Dockerfile named Dockerfile.s390x with following contents:

FROM        s390x/golang:1.11.4
MAINTAINER  The Prometheus Authors <[email protected]>

WORKDIR /go/src/github.com/prometheus/alertmanager
COPY    . /go/src/github.com/prometheus/alertmanager

RUN apt-get install make \
    && make build \
    && cp alertmanager /bin/ \
    && mkdir -p /etc/alertmanager/template \
    && mv ./doc/examples/simple.yml /etc/alertmanager/config.yml \
    && rm -rf /go

EXPOSE     9093
VOLUME     [ "/alertmanager" ]
WORKDIR    /alertmanager
ENTRYPOINT [ "/bin/alertmanager" ]
CMD        [ "-config.file=/etc/alertmanager/config.yml", \
             "-storage.path=/alertmanager" ]

Build alertmanager image

docker build -f Dockerfile.s390x -t prom/alertmanager:v0.16.2-s390x .

Build nats-streaming-server 0.12.0

mkdir -p $work_dir/go/src/github.com/nats-io
cd $work_dir/go/src/github.com/nats-io
git clone https://github.com/nats-io/nats-streaming-server
cd nats-streaming-server
git checkout v0.12.0
CGO_ENABLED=0 GOOS=linux   GOARCH=s390x        go build -v -a -tags netgo -installsuffix netgo -ldflags "-s -w -X github.com/nats-io/nats-streaming-server/version.GITCOMMIT=`git rev-parse --short HEAD`" -o pkg/linux-s390x/nats-streaming-server
cd $work_dir/go/src/github.com/nats-io/nats-streaming-server/pkg/linux-s390x

Create Dockerfile named Dockerfile with following contents:

FROM scratch

COPY nats-streaming-server /nats-streaming-server

# Expose client and management ports
EXPOSE 4222 8222

# Run with default memory based store
ENTRYPOINT ["/nats-streaming-server"]
CMD ["-m", "8222"]

Build nats-streaming image

docker build -t nats-streaming:0.12.0-s390x .

Editing the docker-compose.yml file for s390x.

cd $work_dir/go/src/github.com/openfaas/faas/
  • copy docker-compose.arm64.yml to docker-compose.s390x.yml
cp docker-compose.arm64.yml docker-compose.s390x.yml

Change images names in docker-compose file.

--- docker-compose.arm64.yml    2019-06-03 13:06:49.041530058 +0000
+++ docker-compose.s390x.yml    2019-06-04 11:54:54.934208497 +0000
@@ -3,7 +3,7 @@
     gateway:
         ports:
             - 8080:8080
-        image: openfaas/gateway:0.11.0-arm64
+        image: openfaas/gateway:0.13.4-s390x
         networks:
             - functions
         environment:
@@ -43,7 +43,7 @@
     faas-swarm:
         volumes:
             - "/var/run/docker.sock:/var/run/docker.sock"
-        image:  openfaas/faas-swarm:0.6.1-arm64
+        image:  openfaas/faas-swarm:0.6.2-s390x
         networks:
             - functions
         environment:
@@ -74,7 +74,7 @@
             - basic-auth-password

     nats:
-        image: nats-streaming:0.11.2
+        image: nats-streaming:0.12.0-s390x
         # Uncomment the following port mappings if you wish to expose the
         # NATS client and/or management ports you must also add `-m 8222` to the command
         # ports:
@@ -94,7 +94,7 @@
                     - 'node.platform.os == linux'

     queue-worker:
-        image: openfaas/queue-worker:0.6.0-arm64
+        image: openfaas/queue-worker:0.7.2-s390x
         networks:
             - functions
         environment:
@@ -125,7 +125,7 @@
     # Start monitoring

     prometheus:
-        image: functions/prometheus:2.7.0-arm64
+        image: prom/prometheus:v2.7.1-s390x
         environment:
             no_proxy: "gateway"
         configs:
@@ -152,7 +152,7 @@
                     memory: 200M

     alertmanager:
-        image: functions/alertmanager:0.15.0-arm64
+        image: prom/alertmanager:v0.16.2-s390x
         environment:
             no_proxy: "gateway"
         command:
@@ -201,3 +201,4 @@
         external: true
     basic-auth-password:
         external: true
+

Editing the deploy_stack.sh file for s390x.

cd $work_dir/go/src/github.com/openfaas/faas/

Add following to deploy_stack.sh

--- deploy_stack.sh     2019-06-07 07:12:51.452619463 +0000
+++ deploy_stack.s390x.sh       2019-06-07 07:21:24.582619463 +0000
@@ -60,6 +60,9 @@
 "aarch64") echo "Deploying OpenFaaS core services for ARM64"
           composefile="docker-compose.arm64.yml"
           ;;
+"s390x") echo "Deploying OpenFaaS core services for s390x"
+          composefile="docker-compose.s390x.yml"
+          ;;
 *) echo "Deploying OpenFaaS core services"
    composefile="docker-compose.yml"
    ;;

Deployment guide

  • Initialize Swarm mode
docker swarm init
  • Deploy the stack
cd $work_dir/go/src/github.com/openfaas/faas/
./deploy_stack.sh
  • NOTE: Please make a note of the password which will be used to login using faas-cli.

  • Check if the services are up and showing 1/1 for each:

docker service ls

Build faas-CLI

cd $work_dir/go/src/github.com/openfaas
go get github.com/openfaas/faas-cli && cd faas-cli/
git checkout 0.8.14
GOARCH=s390x CGO_ENABLED=0 GOOS=linux go build --ldflags "-s -w \
   -X github.com/openfaas/faas-cli/version.GitCommit=${GIT_COMMIT} \
   -X github.com/openfaas/faas-cli/version.Version=${VERSION}" \
   -a -installsuffix cgo -o faas-cli
  • Run Tests(Optional)
go test -v $(go list ./... | grep -v /vendor/ | grep -v /template/|grep -v /build/) -cover   
  • login using faas-cli Use the password which was generated after executing deploy_stack.sh
faas-cli login --password <password>

Build Watchdog

go get github.com/openfaas/faas/watchdog
cd $work_dir/go/src/github.com/openfaas/faas/watchdog
git checkout tags/0.13.4

Create Dockerfile named Dockerfile.s390x with following contents:

FROM s390x/golang:1.10 as build

ARG VERSION
ARG GIT_COMMIT

RUN mkdir -p /go/src/github.com/openfaas/faas/watchdog
WORKDIR /go/src/github.com/openfaas/faas/watchdog

COPY vendor                     vendor
COPY metrics                    metrics
COPY types                      types
COPY main.go                    .
COPY handler.go                         .
COPY readconfig.go                  .
COPY readconfig_test.go             .
COPY requesthandler_test.go     .
COPY version.go                 .

# Run a gofmt and exclude all vendored code.
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))"

RUN go test -v ./...
# Stripping via -ldflags "-s -w"
RUN GOARCH=s390x CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w \
        -X main.GitCommit=$GIT_COMMIT \
        -X main.Version=$VERSION" \
        -installsuffix cgo -o watchdog . \
        && cp watchdog /fwatchdog

Build watchdog image

docker build -f Dockerfile.s390x -t openfaas/classic-watchdog:0.13.4 .

Deploy a sample function

./faas-cli new --lang python3 hello-python-faas
./faas-cli build -f hello-python-faas.yml
./faas-cli deploy -f ./hello-python-faas.yml

Build Minio image

cd $work_dir
git clone https://github.com/minio/minio.git
cd minio
git checkout RELEASE.2019-05-14T23-57-45Z
docker build -t minio/minio:RELEASE.2019-05-14T23-57-45Z .

Build Sealed Secrets Controller image

mkdir $workdir/sealed-secrets
cd $workdir/sealed-secrets

Create Dockerfile with following contents:

FROM golang:1.12-alpine
RUN apk add --no-cache make git && go get github.com/bitnami-labs/sealed-secrets/cmd/kubeseal \
    &&  cd src/github.com/bitnami-labs/sealed-secrets/ \
    && make && chmod +x controller kubeseal \
    && cp controller /usr/local/bin/ && cp kubeseal /usr/local/bin/

EXPOSE 8080
ENTRYPOINT ["controller"]

Build Docker image for Sealed Secrets Controller

docker build -t quay.io/bitnami/sealed-secrets-controller:v0.7.0 .

Build NGINX Ingress Controller

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/NGINX-ingress-controller/0.24.1/build_nginx-ingress-controller.sh

# Build nginx-ingress-controller
bash build_nginx-ingress-controller.sh -y

docker tag quay.io/kubernetes-ingress-controller/nginx-ingress-controller-s390x:0.24.1 quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.24.1

Package Helm charts

cd $workdir
git clone https://github.com/helm/charts.git
cd charts/stable
helm package minio
helm package sealed-secrets
helm package nginx-ingress

Modify ofc-bootstrap scripts to use local helm

go get -d github.com/openfaas-incubator/ofc-bootstrap
cd $GOPATH/src/github.com/openfaas-incubator/ofc-bootstrap/
git checkout 0.6.4
cd scripts
sed -i 's/stable\///g' install-minio.sh install-sealedsecrets.sh install-nginx.sh
Clone this wiki locally