diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..1ae7d2f2 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,83 @@ +name: build + +on: + push: + branches: [ '*' ] + pull_request: + branches: [ '*' ] + +jobs: + build: + strategy: + matrix: + go-version: [1.13.x] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@master + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Get Owner name + id: get_owner_name + run: echo ::set-output name=OWNER_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print tolower($1)}' | sed -e "s/:refs//") + - name: Get Repository name + id: get_repo_name + run: echo ::set-output name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print tolower($2)}' | sed -e "s/:refs//") + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build x86_64 container into library + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: false + platforms: linux/amd64 + target: ship + build-args: | + VERSION=${{ steps.get_tag.outputs.TAG }} + GIT_COMMIT=${{ github.sha }} + REPO_URL=https://github.com/${{ env.USER_REPO }} + load: true + # note that the image tags for build/test need to match the value in the contrib/docker-compose.yml + tags: ghcr.io/openfaas/faas-swarm:latest-dev + - name: Install faas-cli + run: ./contrib/get_tools.sh + - name: Init Swarm + run: docker swarm init + - name: Deploy OpenFaaS + run: cd contrib && docker stack deploy func --compose-file docker-compose.yml + env: + BASIC_AUTH: "false" + - name: Wait for startup to finish + run : sleep 15 + - name: Debug service state + run: docker service ps func_faas-swarm func_gateway + - name: Debug service logs + run: docker service logs func_faas-swarm + - name: Debug gateway logs + run: docker service logs func_gateway + - name: Authenticate faas-cli + run: cd contrib && cat ci-auth-pass.txt | faas-cli login --username admin --password-stdin + - name: Deploy function + run: faas-cli deploy --image=functions/alpine:latest --fprocess=cat --name "echo" + - name: Verify deployment + run: ./contrib/ci-verify-fnc-deployment.sh + - name: Test invoke the function + run: faas-cli invoke echo <<< "foobar" | grep "foobar" + - name: Remove the function + run: faas-cli rm echo + - name: Stop test cluster + run: docker stack rm func + - name: Build multi-arch containers for validation only + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + outputs: "type=image,push=false" + platforms: linux/amd64,linux/arm/v7,linux/arm64 + tags: ghcr.io/openfaas/faas-swarm:${{ github.sha }} + diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..756eadc1 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,49 @@ +name: publish + +on: + push: + tags: + - '*' + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - + uses: actions/checkout@master + with: + fetch-depth: 1 + - name: Get tags + id: get_tag + run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/} + - name: Set Username/Repo and ImagePrefix as ENV vars + run: | + echo "USER_REPO"=$(echo "$GITHUB_REPOSITORY" | awk '{print tolower($1)}' | sed -e "s/:refs//") >> $GITHUB_ENV && \ + echo "IMAGE_PREFIX"=$(echo "ghcr.io/$GITHUB_REPOSITORY" | awk '{print tolower($1)}' | sed -e "s/:refs//") >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to Github Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and Push container images + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm/v7,linux/arm64 + target: ship + build-args: | + VERSION=${{ steps.get_tag.outputs.TAG }} + GIT_COMMIT=${{ github.sha }} + REPO_URL=https://github.com/${{ env.USER_REPO }} + push: true + # tag names need to match the repo so that they can be safely pushed, even in forks. + tags: | + ${{ env.IMAGE_PREFIX }}:${{ github.sha }} + ${{ env.IMAGE_PREFIX }}:${{ steps.get_tag.outputs.TAG }} + ${{ env.IMAGE_PREFIX }}:latest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0e2c8a43..00000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -sudo: required - -services: - - docker -addons: - apt: - packages: - - docker-ce - -before_install: - - ./contrib/ci.sh - -script: - - make - -after_success: - - if [ -z $DOCKER_NS ] ; then - export DOCKER_NS=openfaas; - fi - - if [ ! -z "$TRAVIS_TAG" ] ; then - - docker tag $DOCKER_NS/faas-swarm:latest-dev $DOCKER_NS/faas-swarm:$TRAVIS_TAG; - echo $DOCKER_PASSWORD | docker login -u=$DOCKER_USERNAME --password-stdin; - docker push $DOCKER_NS/faas-swarm:$TRAVIS_TAG; - - docker tag $DOCKER_NS/faas-swarm:latest-dev quay.io/$DOCKER_NS/faas-swarm:$TRAVIS_TAG; - echo $QUAY_PASSWORD | docker login -u=$QUAY_USERNAME --password-stdin quay.io; - docker push quay.io/$DOCKER_NS/faas-swarm:$TRAVIS_TAG; - - fi - diff --git a/Dockerfile b/Dockerfile index 40aba21f..fe5ceb8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,22 @@ -FROM teamserverless/license-check:0.3.6 as license-check +FROM teamserverless/license-check:0.3.9 as license-check -FROM golang:1.13 as build -ARG GO111MODULE=off -ARG CGO_ENABLED=0 -COPY --from=license-check /license-check /usr/bin/ +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13 as build + +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH + +ARG NS +ARG REPO +ARG VERSION="dev" +ARG GIT_COMMIT="000000" -RUN mkdir -p /go/src/github.com/openfaas/faas-swarm/ +ENV CGO_ENABLED=0 +ENV GO111MODULE=on +ENV GOFLAGS=-mod=vendor + +COPY --from=license-check /license-check /usr/bin/ WORKDIR /go/src/github.com/openfaas/faas-swarm @@ -15,25 +26,30 @@ RUN license-check -path /go/src/github.com/openfaas/faas-swarm/ --verbose=false RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") -RUN CGO_ENABLED=$CGO_ENABLED go test $(go list ./... | grep -v /vendor/) -cover +RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v ./... -RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \ - && GIT_COMMIT=$(git rev-list -1 HEAD) \ - && CGO_ENABLED=$CGO_ENABLED GOOS=linux go build --ldflags "-s -w \ +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} 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 . -FROM alpine:3.12 as ship +FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12 as ship +ARG REPO_URL +# Get automactic ghcr linking via the image source +# https://github.com/opencontainers/image-spec/blob/master/annotations.md#pre-defined-annotation-keys +# https://github.community/t/github-container-registry-link-to-a-repo/130336 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 + org.label-schema.vcs-url="$REPO_URL" \ + 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" \ + org.opencontainers.image.source="$REPO_URL" + +RUN apk --no-cache add \ + ca-certificates WORKDIR /root/ diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index ce83cefb..00000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,45 +0,0 @@ -FROM teamserverless/license-check:0.3.6 as license-check - -FROM golang:1.13 as build -ARG GO111MODULE=off - -COPY --from=license-check /license-check /usr/bin/ - -RUN mkdir -p /go/src/github.com/openfaas/faas-swarm/ - -WORKDIR /go/src/github.com/openfaas/faas-swarm - -COPY . . - -RUN license-check -path /go/src/github.com/openfaas/faas-swarm/ --verbose=false "Alex Ellis" "OpenFaaS Author(s)" - -RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") \ - && CGO_ENABLED=0 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) \ - && 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 . - -FROM alpine:3.12 as ship - -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"] diff --git a/Dockerfile.armhf b/Dockerfile.armhf deleted file mode 100644 index ce83cefb..00000000 --- a/Dockerfile.armhf +++ /dev/null @@ -1,45 +0,0 @@ -FROM teamserverless/license-check:0.3.6 as license-check - -FROM golang:1.13 as build -ARG GO111MODULE=off - -COPY --from=license-check /license-check /usr/bin/ - -RUN mkdir -p /go/src/github.com/openfaas/faas-swarm/ - -WORKDIR /go/src/github.com/openfaas/faas-swarm - -COPY . . - -RUN license-check -path /go/src/github.com/openfaas/faas-swarm/ --verbose=false "Alex Ellis" "OpenFaaS Author(s)" - -RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") \ - && CGO_ENABLED=0 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) \ - && 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 . - -FROM alpine:3.12 as ship - -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"] diff --git a/Makefile b/Makefile index 0e4386ca..756e30fd 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,18 @@ + +.IMAGE=ghcr.io/openfaas/faas-swarm + +.GIT_COMMIT=$(shell git rev-parse HEAD) +.GIT_VERSION=$(shell git describe --tags 2>/dev/null || echo "$(.GIT_COMMIT)") +.GIT_UNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no) +ifneq ($(.GIT_UNTRACKEDCHANGES),) + .GIT_COMMIT := $(.GIT_COMMIT)-dirty +endif + TAG?=latest-dev -.PHONY: build -build: - docker build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" -t openfaas/faas-swarm:$(TAG) . -.PHONY: test-unit -test-unit: - go test -v $(go list ./... | grep -v /vendor/) -cover +.PHONY: all +all: build .PHONY: start-dev start-dev: @@ -16,29 +22,44 @@ start-dev: stop-dev: docker stack rm func -.PHONY: build-armhf -build-armhf: - docker build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" -t openfaas/faas-swarm:$(TAG)-armhf . -f Dockerfile.armhf -.PHONY: push -push: - docker push openfaas/faas-swarm:$(TAG) +.PHONY: build +build: + docker build \ + --build-arg http_proxy="${http_proxy}" \ + --build-arg https_proxy="${https_proxy}" \ + --build-arg GIT_COMMIT="${.GIT_COMMIT}" \ + --build-arg VERSION="${.GIT_VERSION}" \ + -t ${.IMAGE}:$(TAG) . -.PHONY: all -all: build +.PHONY: build-buildx +build-buildx: + @docker buildx create --use --name=multiarch --node=multiarch && \ + docker buildx build \ + --output "type=docker,push=false" \ + --platform linux/amd64 \ + --build-arg GIT_COMMIT="${.GIT_COMMIT}" \ + --build-arg VERSION="${.GIT_VERSION}" \ + --tag ${.IMAGE}:$(TAG) \ + . -.PHONY: ci-armhf-build -ci-armhf-build: - docker build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" -t openfaas/faas-swarm:$(TAG)-armhf . -f Dockerfile.armhf +.PHONY: build-buildx-all +build-buildx-all: + @docker buildx create --use --name=multiarch --node=multiarch && \ + docker buildx build \ + --platform linux/amd64,linux/arm/v7,linux/arm64 \ + --output "type=image,push=false" \ + --build-arg GIT_COMMIT="${.GIT_COMMIT}" \ + --build-arg VERSION="${.GIT_VERSION}" \ + --tag ${.IMAGE}:$(TAG) \ + . + +.PHONY: test-unit +test-unit: + go test -v $(go list ./... | grep -v /vendor/) -cover -.PHONY: ci-armhf-push -ci-armhf-push: - docker push openfaas/faas-swarm:$(TAG)-armhf -.PHONY: ci-arm64-build -ci-arm64-build: - docker build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" -t openfaas/faas-swarm:$(TAG)-arm64 . -f Dockerfile.arm64 +.PHONY: push +push: + docker push ${.IMAGE}:$(TAG) -.PHONY: ci-arm64-push -ci-arm64-push: - docker push openfaas/faas-swarm:$(TAG)-arm64 diff --git a/README.md b/README.md index 07cb72dd..9d520ea4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ faas-swarm ========== -[![Build Status](https://travis-ci.com/openfaas/faas-swarm.svg?branch=master)](https://travis-ci.com/openfaas/faas-swarm) +[![Build Status](https://github.com/openfaas/faas-swarm/workflows/build/badge.svg?branch=master)](https://github.com/openfaas/faas-swarm/actions) ## Summary @@ -26,7 +26,7 @@ Features: * [x] List * [x] Scale -Docker image: [`openfaas/faas-swarm`](https://hub.docker.com/r/openfaas/faas-swarm/tags/) +Docker image: [`openfaas/faas-swarm`](https://github.com/orgs/openfaas/packages/container/package/faas-swarm) ## Contributing diff --git a/contrib/ci-auth-pass.txt b/contrib/ci-auth-pass.txt new file mode 100644 index 00000000..f3097ab1 --- /dev/null +++ b/contrib/ci-auth-pass.txt @@ -0,0 +1 @@ +password diff --git a/contrib/ci-auth-user.txt b/contrib/ci-auth-user.txt new file mode 100644 index 00000000..7fbe952b --- /dev/null +++ b/contrib/ci-auth-user.txt @@ -0,0 +1 @@ +admin diff --git a/contrib/ci-verify-fnc-deployment.sh b/contrib/ci-verify-fnc-deployment.sh new file mode 100755 index 00000000..a53579e5 --- /dev/null +++ b/contrib/ci-verify-fnc-deployment.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +for i in {1..180}; +do + Ready="$(faas-cli describe echo | awk '{ if($1 ~ /Status:/) print $2 }')" + if [[ $Ready == "Ready" ]]; + then + exit 0 + fi + sleep 1 +done diff --git a/contrib/ci.sh b/contrib/ci.sh deleted file mode 100755 index 4c448607..00000000 --- a/contrib/ci.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# Enable pre-release docker features in the travis build. -# Can't be in .travis.yml as travis has trouble parsing the braces. -echo "{\"experimental\": true}" | sudo tee /etc/docker/daemon.json diff --git a/contrib/docker-compose.yml b/contrib/docker-compose.yml index 6eaf3e89..da65c5a3 100644 --- a/contrib/docker-compose.yml +++ b/contrib/docker-compose.yml @@ -3,7 +3,7 @@ services: gateway: ports: - 8080:8080 - image: openfaas/gateway:0.17.3 + image: openfaas/gateway:0.18.18 networks: - functions environment: @@ -16,7 +16,7 @@ services: faas_nats_port: 4222 direct_functions: "true" # Functions are invoked directly over the overlay network direct_functions_suffix: "" - basic_auth: "${BASIC_AUTH:-true}" + basic_auth: "${BASIC_AUTH:-false}" secret_mount_path: "/run/secrets/" scale_from_zero: "true" # Enable if you want functions to scale from 0/0 to min replica count upon invoke max_idle_conns: 1024 @@ -43,7 +43,7 @@ services: # auth service provide basic-auth plugin for system APIs basic-auth-plugin: - image: openfaas/basic-auth-plugin:0.17.0 + image: openfaas/basic-auth-plugin:0.18.18 networks: - functions environment: @@ -73,14 +73,14 @@ services: faas-swarm: volumes: - "/var/run/docker.sock:/var/run/docker.sock" - image: openfaas/faas-swarm:latest-dev + image: ghcr.io/openfaas/faas-swarm:latest-dev networks: - functions environment: read_timeout: "5m5s" # set both here, and on your functions write_timeout: "5m5s" # set both here, and on your functions DOCKER_API_VERSION: "1.30" - basic_auth: "${BASIC_AUTH:-true}" + basic_auth: "${BASIC_AUTH:-false}" secret_mount_path: "/run/secrets/" deploy: placement: @@ -102,7 +102,7 @@ services: - basic-auth-password nats: - image: nats-streaming:0.11.2 + image: nats-streaming:0.17.0 # 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: @@ -122,13 +122,13 @@ services: - "node.platform.os == linux" queue-worker: - image: openfaas/queue-worker:0.8.0 + image: openfaas/queue-worker:0.11.2 networks: - functions environment: max_inflight: "1" ack_wait: "5m5s" # Max duration of any async task / request - basic_auth: "${BASIC_AUTH:-true}" + basic_auth: "${BASIC_AUTH:-false}" secret_mount_path: "/run/secrets/" gateway_invoke: "true" faas_gateway_address: "gateway" @@ -227,6 +227,6 @@ networks: secrets: basic-auth-user: - external: true + file: ./ci-auth-user.txt basic-auth-password: - external: true + file: ./ci-auth-pass.txt diff --git a/contrib/get_tools.sh b/contrib/get_tools.sh new file mode 100755 index 00000000..c35b8821 --- /dev/null +++ b/contrib/get_tools.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +ARKADE_VERSION="0.6.21" + +echo "Downloading arkade" + +curl -SLs https://github.com/alexellis/arkade/releases/download/$ARKADE_VERSION/arkade > arkade +chmod +x ./arkade + + +./arkade get faas-cli + +sudo mv $HOME/.arkade/bin/* /usr/local/bin/