Skip to content
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

Migration to Github Actions and multiarch builds #114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name:

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
build:
strategy:
matrix:
go-version: [ 1.15.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Make all
run: make all
- name: Get Repo Owner
id: get_repo_owner
run: >
echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} |
tr '[:upper:]' '[:lower:]')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Test and Build multiarch
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
outputs: "type=image,push=false"
platforms: linux/amd64,linux/arm64,linux/arm/v7
# throw away tag, since we don't push the image
tags: ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/of-watchdog:${{ github.sha }}
56 changes: 56 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: publish

on:
push:
tags:
- '*'

jobs:
publish:
strategy:
matrix:
go-version: [ 1.15.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Make all
run: make all
- name: Get TAG
id: get_tag
run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
- name: Get Repo Owner
id: get_repo_owner
run: >
echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} |
tr '[:upper:]' '[:lower:]')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker Login
uses: docker/login-action@v1
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
- name: Docker Build and Push
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/of-watchdog:${{ steps.get_tag.outputs.TAG }}
- name: Upload release binaries
uses: alexellis/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_paths: '["./bin/*"]'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ build
template
**/*.sha256

bin
59 changes: 0 additions & 59 deletions .travis.yml

This file was deleted.

35 changes: 9 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
FROM teamserverless/license-check:0.3.9 as license-check
FROM scratch as cache

FROM golang:1.15 as build
COPY --from=license-check /license-check /usr/bin/
COPY bin .

ARG CGO_ENABLED=0
ARG GO111MODULE="on"
ARG GOPROXY=""
FROM scratch as ship

WORKDIR /go/src/github.com/openfaas/of-watchdog
COPY vendor vendor
COPY config config
COPY executor executor
COPY metrics metrics
COPY main.go .
COPY go.mod .
COPY go.sum .
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

RUN license-check -path /go/src/github.com/openfaas/of-watchdog --verbose=false "Alex Ellis" "OpenFaaS Author(s)"
COPY --from=cache /fwatchdog-$TARGETARCH ./fwatchdog

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

RUN go test -mod=vendor -v ./...

# Stripping via -ldflags "-s -w"
RUN CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags "-s -w" -installsuffix cgo -o of-watchdog . \
&& CGO_ENABLED=0 GOOS=darwin go build -mod=vendor -a -ldflags "-s -w" -installsuffix cgo -o of-watchdog-darwin . \
&& GOARM=6 GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags "-s -w" -installsuffix cgo -o of-watchdog-armhf . \
&& GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags "-s -w" -installsuffix cgo -o of-watchdog-arm64 . \
&& GOOS=windows CGO_ENABLED=0 go build -mod=vendor -a -ldflags "-s -w" -installsuffix cgo -o of-watchdog.exe .
ENTRYPOINT ["/fwatchdog"]
6 changes: 0 additions & 6 deletions Dockerfile.packager

This file was deleted.

53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

.GIT_COMMIT=$(shell git rev-parse HEAD)
.GIT_VERSION=$(shell git describe --tags --always --dirty 2>/dev/null)
.GIT_UNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(.GIT_UNTRACKEDCHANGES),)
.GIT_VERSION := $(.GIT_VERSION)-$(shell date +"%s")
endif
LDFLAGS := "-s -w -X main.Version=$(.GIT_VERSION) -X main.GitCommit=$(.GIT_COMMIT)"


.IMAGE=ghcr.io/openfaas/of-watchdog
TAG?=latest

export GOFLAGS=-mod=vendor

.PHONY: all
all: gofmt test dist hashgen

.PHONY: test
test:
@echo "+ $@"
@go test -v ./...

.PHONY: gofmt
gofmt:
@echo "+ $@"
@gofmt -l -d $(shell find . -type f -name '*.go' -not -path "./vendor/*")


.PHONY: build
build:
@echo "+ $@"
@docker build \
--build-arg GIT_COMMIT=${.GIT_COMMIT} \
--build-arg VERSION=${.GIT_VERSION} \
-t ${.IMAGE}:${TAG} .

.PHONY: hashgen
hashgen:
./ci/hashgen.sh

.PHONY: dist
dist:
@echo "+ $@"
CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/fwatchdog-amd64
GOARM=7 GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/fwatchdog-arm
GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/fwatchdog-arm64
GOOS=windows CGO_ENABLED=0 go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/fwatchdog.exe

# use this with
# `./ci/copy_redist.sh $(make print-image) && ./ci/hashgen.sh`
print-image:
@echo ${.IMAGE}
24 changes: 0 additions & 24 deletions build.sh

This file was deleted.

9 changes: 9 additions & 0 deletions ci/copy_redist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
NAME=redist
IMAGE=$1
eTAG=${2:-latest}

docker create --name "$NAME" "${IMAGE}:${eTAG}" \
&& mkdir -p ./bin \
&& docker cp "$NAME":/bin .
docker rm -f "$NAME"
14 changes: 13 additions & 1 deletion ci/hashgen.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#!/bin/sh

for f in of-watchdog*; do shasum -a 256 $f > $f.sha256; done
# ":" separated list of paths to folders that contain
# executable binaries that should be shasum'd
BINARIES=./bin

IFS=':'
for directory in $BINARIES; do
cd "$directory" || exit 1
for f in * ; do # Scanning files in direcotry
if [ -x $f ]; then
shasum -a 256 $f > $f.sha256
fi
done
done
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ module github.com/openfaas/of-watchdog
go 1.13

require (
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
github.com/golang/protobuf v1.3.1
github.com/matttproud/golang_protobuf_extensions v1.0.1
github.com/golang/protobuf v1.3.1 // indirect
github.com/openfaas/faas-middleware v0.0.0-20190415163657-6a78c3a94beb
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
github.com/prometheus/common v0.2.0
github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect
github.com/prometheus/common v0.2.0 // indirect
github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872 // indirect
)
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ var (

func main() {
var runHealthcheck bool
var versionFlag bool

flag.BoolVar(&versionFlag, "version", false, "Print the version and exit")
flag.BoolVar(&runHealthcheck,
"run-healthcheck",
false,
"Check for the a lock-file, when using an exec healthcheck. Exit 0 for present, non-zero when not found.")

flag.Parse()

printVersion()

if versionFlag {
return
}

if runHealthcheck {
if lockFilePresent() {
os.Exit(0)
Expand Down Expand Up @@ -371,3 +379,12 @@ func makeHealthHandler() func(http.ResponseWriter, *http.Request) {
}
}
}

func printVersion() {
sha := "unknown"
if len(GitCommit) > 0 {
sha = GitCommit
}

log.Printf("Version: %v\tSHA: %v\n", BuildVersion(), sha)
}
18 changes: 0 additions & 18 deletions make_manifest.sh

This file was deleted.

Loading