Skip to content

Commit

Permalink
Duplicate classic-watchdog make and docker files
Browse files Browse the repository at this point in the history
**What**
- Replicate the build process from classic-watchdog. The makefile will
  now cross-compile the binary on the local host and the Dockerfile will
  simply copy the required binary instead of building it inside docker

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler committed Feb 12, 2021
1 parent 6ede08a commit 881aba1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 191 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Make all
run: make test
- name: Docker meta
id: meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: "ghcr.io/${{ github.repository }}"
run: make all
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
Expand All @@ -43,4 +38,4 @@ jobs:
outputs: "type=image,push=false"
platforms: linux/amd64,linux/arm64,linux/arm/v7
# throw away tag, since we don't push the image
tags: openfaas/multiarch:test
tags: ghcr.io/openfaas/of-watchdog:${{ github.sha }}
70 changes: 23 additions & 47 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,43 @@ on:

jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ 1.15.x ]
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
-
uses: actions/checkout@master
- uses: actions/checkout@master
with:
fetch-depth: 1
-
name: Docker meta
id: meta
uses: crazy-max/ghaction-docker-meta@v1
- name: Install Go
uses: actions/setup-go@v2
with:
images: "ghcr.io/${{ github.repository }}"
-
name: Set up QEMU
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: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Docker Login
- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build binaries
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.redist
platforms: linux/amd64
build-args: |
VERSION=${{ steps.meta.outputs.version }}
GIT_COMMIT=${{ github.sha }}
load: true
push: false
# tag doesn't matter because we will never push this
tags: redist/throwaway:latest
-
name: Copy binaries to host
run: ./ci/copy_redist.sh redist/throwaway
-
name: Create SHA of binaries
run: ./ci/hashgen.sh
-
name: Docker Build and Push
registry: ghcr.io
- name: Docker Build and Push
uses: docker/build-push-action@v2
with:
context: .
context: ./
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
target: release
build-args: |
VERSION=${{ steps.meta.outputs.version }}
GIT_COMMIT=${{ github.sha }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
-
name: Upload binaries and their SHA to Github Release
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ghcr.io/openfaas/of-watchdog:${{ steps.get_tag.outputs.TAG }}
- name: Upload release binaries
uses: alexellis/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
50 changes: 5 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,54 +1,14 @@
ARG goversion=1.15
FROM scratch as cache

FROM teamserverless/license-check:0.3.9 as license-check
COPY bin .

FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:$goversion as builder
FROM scratch as ship

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

ARG GIT_COMMIT="000000"
ARG VERSION="dev"
COPY --from=cache /fwatchdog-$TARGETARCH ./fwatchdog

COPY --from=license-check /license-check /usr/bin/

ARG CGO_ENABLED=0
ARG GO111MODULE="on"
ENV GOFLAGS=-mod=vendor
ARG GOPROXY=""

WORKDIR /app
COPY vendor vendor
COPY config config
COPY executor executor
COPY metrics metrics
COPY version.go .
COPY main.go .
COPY go.mod .
COPY go.sum .

RUN license-check -path /app --verbose=false "Alex Ellis" "OpenFaaS Author(s)"
RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")
RUN go test -v ./...

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 \
go build --ldflags "-s -w \
-X github.com/openfaas/of-watchdog/main.GitCommit=${GIT_COMMIT} \
-X github.com/openfaas/of-watchdog/main.Version=${VERSION}" \
-a -installsuffix cgo -o fwatchdog


FROM scratch as release

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

COPY --from=builder /app/fwatchdog /fwatchdog

ENTRYPOINT ["/fwatchdog"]
ENTRYPOINT ["/fwatchdog"]
81 changes: 0 additions & 81 deletions Dockerfile.redist

This file was deleted.

27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
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: fmt
@echo "+ $@"
@go test -v ./...

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

Expand All @@ -31,16 +35,17 @@ build:
--build-arg VERSION=${.GIT_VERSION} \
-t ${.IMAGE}:${TAG} .

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

.PHONY: dist
dist:
@echo "+ $@"
@docker build \
--build-arg GIT_COMMIT=${.GIT_COMMIT} \
--build-arg VERSION=${.GIT_VERSION} \
-f Dockerfile.redist \
-t ${.IMAGE}:${TAG} .
@./ci/copy_redist.sh ${.IMAGE} ${TAG}
@./ci/hashgen.sh
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`
Expand Down

0 comments on commit 881aba1

Please sign in to comment.