Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Add support for limited build-args for Go modules #653

Merged
merged 1 commit into from
Jul 7, 2020
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
6 changes: 3 additions & 3 deletions git-tar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openfaas/faas-cli:0.11.8 as faas-cli
FROM openfaas/classic-watchdog:0.18.1 as watchdog
FROM golang:1.13-alpine3.11 as build
FROM openfaas/faas-cli:0.12.8 as faas-cli
FROM openfaas/classic-watchdog:0.18.17 as watchdog
FROM golang:1.13-alpine3.12 as build

ENV CGO_ENABLED=0
ENV GO111MODULE=off
Expand Down
11 changes: 6 additions & 5 deletions git-tar/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions git-tar/Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[constraint]]
name = "github.com/openfaas/faas-cli"
version = "0.9.3"
version = "0.12.8"

[[constraint]]
name = "github.com/openfaas/openfaas-cloud"
Expand All @@ -26,4 +26,3 @@
go-tests = true
unused-packages = true


27 changes: 20 additions & 7 deletions git-tar/function/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ type tarEntry struct {
imageName string
}

type cfg struct {
Ref string `json:"ref"`
Frontend *string `json:"frontend,omitempty"`
}

func parseYAML(filePath string) (*stack.Services, error) {
envVarSubst := false
parsed, err := stack.ParseYAMLFile(path.Join(filePath, "stack.yml"), "", "", envVarSubst)
Expand Down Expand Up @@ -123,8 +118,13 @@ func makeTar(pushEvent sdk.PushEvent, filePath string, services *stack.Services)
imageName := formatImageShaTag(pushRepositoryURL, &v, pushEvent.AfterCommitID,
pushEvent.Repository.Owner.Login, pushEvent.Repository.Name)

config := cfg{
Ref: imageName,
allowedBuildArgs := []string{"GO111MODULE"}
buildArgs := makeBuildArgs(v.BuildArgs, allowedBuildArgs)

// Write a config file for the Docker build
config := buildConfig{
Ref: imageName,
BuildArgs: buildArgs,
}

configBytes, _ := json.Marshal(config)
Expand Down Expand Up @@ -797,3 +797,16 @@ func invokeWithHMAC(uri string, payload []byte, payloadSecret string, headers ma

return res.StatusCode, resOut, nil
}

func makeBuildArgs(inputArgs map[string]string, allowed []string) map[string]string {
args := map[string]string{}
for key, value := range inputArgs {
for _, allow := range allowed {
if key == allow {
args[key] = value
break
}
}
}
return args
}
7 changes: 7 additions & 0 deletions git-tar/function/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package function

type buildConfig struct {
Ref string `json:"ref"`
Frontend string `json:"frontend,omitempty"`
BuildArgs map[string]string `json:"buildArgs,omitempty"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 49 additions & 18 deletions git-tar/vendor/github.com/openfaas/faas-cli/stack/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions git-tar/vendor/github.com/ryanuber/go-glob/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions of-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.11-alpine AS builder
FROM golang:1.13-alpine AS builder

ENV CGO_ENABLED=0
ENV GO111MODULE=off

RUN apk add --no-cache git g++ linux-headers curl ca-certificates

Expand All @@ -16,8 +17,7 @@ ADD vendor vendor

RUN go build -o /usr/bin/of-builder .

FROM alpine:3.10

FROM alpine:3.12
RUN apk add --no-cache ca-certificates

# Setting the group prevented access to /tmp at runtime
Expand Down
4 changes: 2 additions & 2 deletions of-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ The builder service calls into the buildkit daemon to build an OpenFaaS function
### Build

```sh
export OF_BUILDER_TAG=0.7.2
export OF_BUILDER_TAG=0.8.0

make build push
```

### Deploy

```sh
export OF_BUILDER_TAG=0.7.2
export OF_BUILDER_TAG=0.8.0

docker service create \
--network func_functions \
Expand Down
21 changes: 15 additions & 6 deletions of-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ import (
// ConfigFileName for Docker bundle
const ConfigFileName = "com.openfaas.docker.config"

// DefaultFrontEnd to run the build with buildkit
const DefaultFrontEnd = "tonistiigi/dockerfile:v0"

var (
lchownEnabled bool
buildkitURL string
buildArgs = map[string]string{}
)

type buildConfig struct {
Ref string `json:"ref"`
Frontend string `json:"frontend,omitempty"`
BuildArgs map[string]string `json:"buildArgs,omitempty"`
}

func main() {
flag.Parse()

Expand Down Expand Up @@ -160,11 +169,7 @@ func build(w http.ResponseWriter, r *http.Request, buildArgs map[string]string)
return nil, err
}

var cfg struct {
Ref string
Frontend string
}

cfg := buildConfig{}
if err := json.Unmarshal(dt, &cfg); err != nil {
return nil, err
}
Expand All @@ -174,7 +179,7 @@ func build(w http.ResponseWriter, r *http.Request, buildArgs map[string]string)
}

if cfg.Frontend == "" {
cfg.Frontend = "tonistiigi/dockerfile:v0"
cfg.Frontend = DefaultFrontEnd
}

insecure := "false"
Expand All @@ -190,6 +195,10 @@ func build(w http.ResponseWriter, r *http.Request, buildArgs map[string]string)
frontendAttrs[k] = v
}

for k, v := range cfg.BuildArgs {
frontendAttrs[fmt.Sprintf("build-arg:%s", k)] = v
}

contextDir := filepath.Join(tmpdir, "context")
solveOpt := client.SolveOpt{
Exporter: "image",
Expand Down
2 changes: 1 addition & 1 deletion stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ functions:
git-tar:
lang: dockerfile
handler: ./git-tar
image: functions/of-git-tar:0.17.3
image: functions/of-git-tar:0.18.0
labels:
openfaas-cloud: "1"
role: openfaas-system
Expand Down