diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64e3e29b..dbccdb10 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,10 +7,9 @@ on: pull_request: branches: - '*' -# Auth -# Watchdog containers -# Watchdog bins + shas +# pull buildargs out of container (stop putting git in) +# can then go back to matrix build of containers jobs: # Run the CI tests @@ -28,8 +27,32 @@ jobs: 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 + uses: docker/setup-buildx-action@v1 + - name: Get TAG + id: get_tag + run: echo ::set-output name=TAG::latest-dev + - name: Get Repo Owner + id: get_repo_owner + run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') + - name: Build Gateway + uses: docker/build-push-action@v2 + with: + context: ./gateway + file: ./gateway/Dockerfile + platforms: linux/amd64 + load: true + push: false + build-args: | + VERSION=${{ steps.get_tag.outputs.TAG }} + GIT_COMMIT=${{ github.sha }} + GIT_COMMIT_MESSAGE=${{ github.event.head_commit.message }} + tags: | + ghcr.io/openfaas/gateway:latest-dev - name: Run CI - run: make build test-ci + run: make test-ci build-gateway: runs-on: ubuntu-latest @@ -49,45 +72,18 @@ jobs: run: echo ::set-output name=TAG::latest-dev - name: Get Repo Owner id: get_repo_owner - run: echo ::set-output name=repo_owner::$(echo ${{ github.event.repository.owner.login }} | tr '[:upper:]' '[:lower:]') - - name: Build Gateway + run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') + - name: Build ${{ matrix.svc }} uses: docker/build-push-action@v2 with: - context: . - file: ./gateway/Dockerfile - outputs: "type=image,push=false" - platforms: linux/amd64,linux/arm/v7,linux/arm64 - tags: | - ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/gateway:${{ steps.get_tag.outputs.TAG }} - ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/gateway:${{ github.sha }} - ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/gateway:latest - - build-watchdog: - runs-on: ubuntu-latest - strategy: - matrix: - go-version: [1.13.x] - 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: Get Repo Owner - id: get_repo_owner - run: echo ::set-output name=repo_owner::$(echo ${{ github.event.repository.owner.login }} | tr '[:upper:]' '[:lower:]') - - name: Build Watchdog - uses: docker/build-push-action@v2 - with: - context: . + context: ./gateway file: ./gateway/Dockerfile outputs: "type=image,push=false" platforms: linux/amd64,linux/arm/v7,linux/arm64 + build-args: | + VERSION=${{ steps.get_tag.outputs.TAG }} + GIT_COMMIT=${{ github.sha }} + GIT_COMMIT_MESSAGE=${{ github.event.head_commit.message }} tags: | ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/gateway:${{ steps.get_tag.outputs.TAG }} ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/gateway:${{ github.sha }} @@ -113,7 +109,7 @@ jobs: run: echo ::set-output name=TAG::latest-dev - name: Get Repo Owner id: get_repo_owner - run: echo ::set-output name=repo_owner::$(echo ${{ github.event.repository.owner.login }} | tr '[:upper:]' '[:lower:]') + run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') - name: Build ${{ matrix.svc }} uses: docker/build-push-action@v2 with: diff --git a/Makefile b/Makefile index 97f71e6f..7e151efd 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,6 @@ TAG?=latest NS?=openfaas -.PHONY: build -build: - ./build.sh - .PHONY: build-gateway build-gateway: (cd gateway; docker buildx build --platform linux/amd64 -t $NS/gateway:latest-dev .) @@ -12,7 +8,3 @@ build-gateway: .PHONY: test-ci test-ci: ./contrib/ci.sh - -.PHONY: binaries -binaries: - echo TODO \ No newline at end of file diff --git a/auth/basic-auth/Dockerfile b/auth/basic-auth/Dockerfile index 763a6bf1..46217468 100644 --- a/auth/basic-auth/Dockerfile +++ b/auth/basic-auth/Dockerfile @@ -18,10 +18,13 @@ COPY . . # Run a gofmt and exclude all vendored code. RUN license-check -path ./ --verbose=false "OpenFaaS Authors" "OpenFaaS Author(s)" -RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH } test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))" -RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH } \ - go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && \ - go test $(go list ./... | grep -v /vendor/) -cover + +RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))" + +RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v ./... + +RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \ + --ldflags "-s -w" -a -installsuffix cgo -o handler . FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12 as ship # Add non-root user diff --git a/auth/basic-auth/Makefile b/auth/basic-auth/Makefile deleted file mode 100644 index cc7d41a0..00000000 --- a/auth/basic-auth/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -TAG?=latest - -.PHONY: build -build: - ./build.sh ${TAG} diff --git a/auth/basic-auth/build.sh b/auth/basic-auth/build.sh deleted file mode 100755 index 5f53d8bc..00000000 --- a/auth/basic-auth/build.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -set -e - -export arch=$(uname -m) -export eTAG="latest-dev" -export DOCKERFILE="Dockerfile" - -if [ "$arch" = "armv7l" ] ; then - eTAG="latest-armhf-dev" -elif [ "$arch" = "aarch64" ] ; then - eTAG="latest-arm64-dev" - DOCKERFILE="Dockerfile.arm64" -fi - -echo "$1" -if [ "$1" ] ; then - eTAG=$1 - if [ "$arch" = "armv7l" ] ; then - eTAG="$1-armhf" - elif [ "$arch" = "aarch64" ] ; then - eTAG="$1-arm64" - fi -fi - -NS=openfaas - -echo Building $NS/basic-auth-plugin:$eTAG - -docker build -t $NS/basic-auth-plugin:$eTAG . -f $DOCKERFILE - diff --git a/auth/basic-auth/push.sh b/auth/basic-auth/push.sh deleted file mode 100755 index a60fa81f..00000000 --- a/auth/basic-auth/push.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -set -e - -export arch=$(uname -m) -export eTAG="latest-dev" - -if [ "$arch" = "armv7l" ] ; then - eTAG="latest-armhf-dev" -elif [ "$arch" = "aarch64" ] ; then - eTAG="latest-arm64-dev" -fi - -echo "$1" -if [ "$1" ] ; then - eTAG=$1 - if [ "$arch" = "armv7l" ] ; then - eTAG="$1-armhf" - elif [ "$arch" = "aarch64" ] ; then - eTAG="$1-arm64" - fi -fi - -NS=openfaas - -echo Pushing $NS/basic-auth-plugin:$eTAG - -docker push $NS/basic-auth-plugin:$eTAG \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100755 index 1eb2abba..00000000 --- a/build.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -if [ ! -s "$TAG" ] ; then - echo "This build will be published under the tag: ${TAG}" -fi - -(cd gateway && ./build.sh) -(cd auth/basic-auth && ./build.sh) diff --git a/ci/tagAndPush.sh b/ci/tagAndPush.sh deleted file mode 100755 index 83f630bd..00000000 --- a/ci/tagAndPush.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -set -e - -IMAGE_REGISTRY=$1 -IMAGE_NAME=$2 -PLATFORM="" - -if [ ! -z "$3" ]; then - PLATFORM="-$3" -fi - -echo "Tagging $IMAGE_REGISTRY/$IMAGE_NAME:$TRAVIS_TAG$PLATFORM" -docker tag $IMAGE_NAME:latest-dev$PLATFORM $IMAGE_REGISTRY/$IMAGE_NAME:$TRAVIS_TAG$PLATFORM; - -echo "Pushing $IMAGE_REGISTRY/$IMAGE_NAME:$TRAVIS_TAG$PLATFORM" -docker push $IMAGE_REGISTRY/$IMAGE_NAME:$TRAVIS_TAG$PLATFORM; diff --git a/contrib/ci.sh b/contrib/ci.sh index 597d86f3..6d8ac9c7 100755 --- a/contrib/ci.sh +++ b/contrib/ci.sh @@ -6,7 +6,7 @@ set -e # The timeout is required on Travis due to some tasks not starting in # time and being deemed to have failed. -docker service update func_gateway --image=openfaas/gateway:latest-dev \ +docker service update func_gateway --image=ghcr.io/openfaas/gateway:latest-dev \ --update-failure-action=continue \ --update-monitor=20s @@ -32,11 +32,13 @@ fi cd .. -echo $GOPATH +if [ -z "$GOPATH" ] +then + export GOPATH=$GITHUB_WORKSPACE +fi if [ ! -d "$GOPATH/src/github.com/openfaas/" ]; then mkdir -p $GOPATH/src/github.com/openfaas/ - cp -r faas $GOPATH/src/github.com/openfaas/ fi if [ ! -d "$GOPATH/src/github.com/openfaas/certifier" ]; then diff --git a/gateway/Dockerfile b/gateway/Dockerfile index 6863cb29..a2f67408 100644 --- a/gateway/Dockerfile +++ b/gateway/Dockerfile @@ -10,42 +10,39 @@ ARG BUILDPLATFORM ARG TARGETOS ARG TARGETARCH -ARG GIT_COMMIT_SHA +ARG GIT_COMMIT ARG GIT_COMMIT_MESSAGE -ARG VERSION='dev' +ARG VERSION COPY --from=license-check /license-check /usr/bin/ WORKDIR /go/src/github.com/openfaas/faas/gateway -COPY gateway/vendor vendor +COPY vendor vendor -COPY gateway/handlers handlers -COPY gateway/metrics metrics -COPY gateway/requests requests -COPY gateway/tests tests +COPY handlers handlers +COPY metrics metrics +COPY requests requests +COPY tests tests -COPY gateway/types types -COPY gateway/queue queue -COPY gateway/plugin plugin -COPY gateway/version version -COPY gateway/scaling scaling -COPY gateway/pkg pkg -COPY gateway/main.go . -COPY .git . +COPY types types +COPY queue queue +COPY plugin plugin +COPY version version +COPY scaling scaling +COPY pkg pkg +COPY main.go . RUN license-check -path ./ --verbose=false "Alex Ellis" "OpenFaaS Authors" "OpenFaaS Author(s)" # Run a gofmt and exclude all vendored code. RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))" -RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test $(go list ./... | grep -v integration | grep -v /vendor/ | grep -v /template/) -cover -RUN GIT_COMMIT_MESSAGE=$(git log -1 --pretty=%B 2>&1 | head -n 1) \ - GIT_COMMIT_SHA=$(git rev-list -1 HEAD) \ - VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///' || echo dev) \ - CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build --ldflags "-s -w \ - -X github.com/openfaas/faas/gateway/version.GitCommitSHA=${GIT_COMMIT_SHA} \ - -X github.com/openfaas/faas/gateway/version.GitCommitMessage=${GIT_COMMIT_MESSAGE} \ - -X github.com/openfaas/faas/gateway/version.Version=${VERSION} \ +RUN go test $(go list ./... | grep -v integration | grep -v /vendor/ | grep -v /template/) -cover + +RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build --ldflags "-s -w \ + -X \"github.com/openfaas/faas/gateway/version.GitCommitSHA=${GIT_COMMIT}\" \ + -X \"github.com/openfaas/faas/gateway/version.GitCommitMessage=${GIT_COMMIT_MESSAGE}\" \ + -X \"github.com/openfaas/faas/gateway/version.Version=${VERSION}\" \ -X github.com/openfaas/faas/gateway/types.Arch=${TARGETARCH}" \ -a -installsuffix cgo -o gateway . @@ -70,7 +67,7 @@ ENV http_proxy "" ENV https_proxy "" COPY --from=build /go/src/github.com/openfaas/faas/gateway/gateway . -COPY gateway/assets assets +COPY assets assets RUN sed -ie s/x86_64/${GOARCH}/g assets/script/funcstore.js && \ rm assets/script/funcstore.jse diff --git a/gateway/Makefile b/gateway/Makefile deleted file mode 100644 index 92bbbf4e..00000000 --- a/gateway/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -.PHONY: all build push -TAG?=latest -NS?=openfaas - -all: build -build: - ./build.sh ${TAG} ${NS} -push: - ./push.sh ${TAG} ${NS} diff --git a/gateway/push.sh b/gateway/push.sh deleted file mode 100755 index 5e86c2df..00000000 --- a/gateway/push.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -set -e - -export arch=$(uname -m) - -export eTAG="latest-dev" - -if [ "$arch" = "armv7l" ] ; then - eTAG="latest-armhf-dev" -elif [ "$arch" = "aarch64" ] ; then - eTAG="latest-arm64-dev" -fi - -echo "$1" -if [ "$1" ] ; then - eTAG=$1 - if [ "$arch" = "armv7l" ] ; then - eTAG="$1-armhf" - elif [ "$arch" = "aarch64" ] ; then - eTAG="$1-arm64" - fi -fi - - -if [ "$2" ] ; then - NS=$2 -else - NS=openfaas -fi - -echo Pushing $NS/gateway:$eTAG - -docker push $NS/gateway:$eTAG -