Skip to content

Commit b38aeb0

Browse files
committed
Resolve version from GitHub Action and move to Go 1.17
* As per other projects, the version is determined from the execution environment, and not from within the Docker build stage. This means there's no need to copy the .git folder into the build context. * Moves to Go 1.17 for building the operator/controller. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent c840833 commit b38aeb0

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/artifacts
88
/hack
99
/docs
10+
/.git

.github/workflows/build.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111
strategy:
1212
matrix:
13-
go-version: [1.16.x]
13+
go-version: [1.17.x]
1414
os: [ubuntu-latest]
1515
runs-on: ${{ matrix.os }}
1616

@@ -28,6 +28,9 @@ jobs:
2828
- name: Get Repo Owner
2929
id: get_repo_owner
3030
run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
31+
- name: Get git commit
32+
id: get_git_commit
33+
run: echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
3134

3235
- name: Build x86_64 container into library
3336
uses: docker/build-push-action@v2
@@ -36,6 +39,9 @@ jobs:
3639
file: ./Dockerfile
3740
outputs: "type=docker,push=false"
3841
platforms: linux/amd64
42+
build-args: |
43+
GIT_COMMIT=dev-${{env.GIT_COMMIT}}
44+
VERSION=dev-${{env.GIT_COMMIT}}
3945
tags: |
4046
ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/faas-netes:${{ github.sha }}
4147
@@ -46,6 +52,9 @@ jobs:
4652
file: ./Dockerfile
4753
outputs: "type=image,push=false"
4854
platforms: linux/amd64,linux/arm/v7,linux/arm64
55+
build-args: |
56+
GIT_COMMIT=dev-${{env.GIT_COMMIT}}
57+
VERSION=dev-${{env.GIT_COMMIT}}
4958
tags: |
5059
ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/faas-netes:${{ github.sha }}
5160
# Todo - load the image into Kind before running tests

.github/workflows/publish.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
publish:
1010
strategy:
1111
matrix:
12-
go-version: [1.16.x]
12+
go-version: [1.17.x]
1313
os: [ubuntu-latest]
1414
runs-on: ${{ matrix.os }}
1515
permissions:
@@ -43,6 +43,12 @@ jobs:
4343
- name: Get Repo Owner
4444
id: get_repo_owner
4545
run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
46+
- name: Get git commit
47+
id: get_git_commit
48+
run: echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
49+
- name: Get version
50+
id: get_version
51+
run: echo "VERSION=$(git describe --tags --dirty)" >> $GITHUB_ENV
4652

4753
- name: Push containers
4854
uses: docker/build-push-action@v2
@@ -51,6 +57,9 @@ jobs:
5157
file: ./Dockerfile
5258
outputs: "type=registry,push=true"
5359
platforms: linux/amd64,linux/arm/v7,linux/arm64
60+
build-args: |
61+
GIT_COMMIT=${{env.GIT_COMMIT}}
62+
VERSION=${{env.VERSION}}
5463
tags: |
5564
ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/faas-netes:${{ github.sha }}
5665
ghcr.io/${{ steps.get_repo_owner.outputs.repo_owner }}/faas-netes:${{ steps.get_tag.outputs.TAG }}

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
FROM teamserverless/license-check:0.3.9 as license-check
22

3-
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.16 as build
3+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.17 as build
44

55
ARG TARGETPLATFORM
66
ARG BUILDPLATFORM
77
ARG TARGETOS
88
ARG TARGETARCH
99

10+
ARG VERSION
11+
ARG GIT_COMMIT
12+
1013
ENV CGO_ENABLED=0
1114
ENV GO111MODULE=on
1215
ENV GOFLAGS=-mod=vendor
@@ -20,9 +23,7 @@ RUN license-check -path /go/src/github.com/openfaas/faas-netes/ --verbose=false
2023
RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")
2124
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v ./...
2225

23-
RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \
24-
&& GIT_COMMIT=$(git rev-list -1 HEAD) \
25-
&& GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go build \
26+
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
2627
--ldflags "-s -w \
2728
-X github.com/openfaas/faas-netes/version.GitCommit=${GIT_COMMIT}\
2829
-X github.com/openfaas/faas-netes/version.Version=${VERSION}" \

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
.PHONY: build local push namespaces install charts start-kind stop-kind build-buildx render-charts
2+
IMG_NAME?=faas-netes
3+
24
TAG?=latest
35
OWNER?=openfaas
46
SERVER?=ghcr.io
57
export DOCKER_CLI_EXPERIMENTAL=enabled
8+
export DOCKER_BUILDKIT=1
69

710
TOOLS_DIR := .tools
811

912
GOPATH := $(shell go env GOPATH)
1013
CODEGEN_VERSION := $(shell hack/print-codegen-version.sh)
1114
CODEGEN_PKG := $(GOPATH)/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION}
1215

16+
VERSION := $(shell git describe --tags --dirty)
17+
GIT_COMMIT := $(shell git rev-parse HEAD)
18+
1319
all: build-docker
1420

1521
$(TOOLS_DIR)/code-generator.mod: go.mod
@@ -25,16 +31,20 @@ local:
2531

2632
build-docker:
2733
docker build \
28-
-t $(SERVER)/$(OWNER)/faas-netes:$(TAG) .
34+
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
35+
--build-arg VERSION=$(VERSION) \
36+
-t $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) .
2937

3038
.PHONY: build-buildx
3139
build-buildx:
32-
@echo $(SERVER)/$(OWNER)/faas-netes:$(TAG) && \
40+
@echo $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) && \
3341
docker buildx create --use --name=multiarch --node=multiarch && \
3442
docker buildx build \
3543
--push \
3644
--platform linux/amd64 \
37-
--tag $(SERVER)/$(OWNER)/faas-netes:$(TAG) \
45+
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
46+
--build-arg VERSION=$(VERSION) \
47+
--tag $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) \
3848
.
3949

4050
.PHONY: build-buildx-all
@@ -43,21 +53,25 @@ build-buildx-all:
4353
docker buildx build \
4454
--platform linux/amd64,linux/arm/v7,linux/arm64 \
4555
--output "type=image,push=false" \
46-
--tag $(SERVER)/$(OWNER)/faas-netes:$(TAG) \
56+
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
57+
--build-arg VERSION=$(VERSION) \
58+
--tag $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) \
4759
.
4860

4961
.PHONY: publish-buildx-all
5062
publish-buildx-all:
51-
@echo $(SERVER)/$(OWNER)/faas-netes:$(TAG) && \
63+
@echo $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) && \
5264
docker buildx create --use --name=multiarch --node=multiarch && \
5365
docker buildx build \
5466
--platform linux/amd64,linux/arm/v7,linux/arm64 \
5567
--push=true \
56-
--tag $(SERVER)/$(OWNER)/faas-netes:$(TAG) \
68+
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
69+
--build-arg VERSION=$(VERSION) \
70+
--tag $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) \
5771
.
5872

5973
push:
60-
docker push $(SERVER)/$(OWNER)/faas-netes:$(TAG)
74+
docker push $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG)
6175

6276
charts:
6377
cd chart && helm package openfaas/ && helm package kafka-connector/ && helm package cron-connector/ && helm package nats-connector/ && helm package mqtt-connector/ && helm package pro-builder/ && helm package sqs-connector/

0 commit comments

Comments
 (0)