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

src!: revert bump to go 1.16 and template changes #340

Merged
merged 22 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
76da577
Revert "src: rename boson import 'fn'"
lance May 12, 2021
fbf67e0
Revert "src: all test dirs set to 0700"
lance May 12, 2021
5f74b48
Revert "src: better error when custom template not found"
lance May 12, 2021
4fa7d62
Revert "src: better errors when custom runtime not found"
lance May 12, 2021
92bf199
Revert "build: create separate target for templates.tgz"
lance May 12, 2021
f62f623
Revert "src: use consistent separators for fs.FS instances"
lance May 12, 2021
6ed3ebe
Revert "src: update go event template dependencies"
lance May 12, 2021
3ca0698
Revert "src: tarfs assumes forward slashes internally"
lance May 12, 2021
d0466d6
Revert "feat: support windows paths in embedded templates FS"
lance May 12, 2021
c7aec49
Revert "feat: positive error when runtimme or template unrecognized"
lance May 12, 2021
99bc351
Revert "fix: lint issues"
lance May 12, 2021
9466c5e
Revert "ci: go 1.16 compatiblity updates"
lance May 12, 2021
afcef65
Revert "feat: preserve file modes using in-memory tar FS"
lance May 12, 2021
2e17271
Revert "feat: create templates archive on go generate"
lance May 12, 2021
4063ba5
Revert "ci: remove pkger from ci"
lance May 12, 2021
3871a24
Revert "src: remove pkger dependency and tidy"
lance May 12, 2021
a822e79
Revert "src: remove packaging artifact"
lance May 12, 2021
e40dcee
Revert "src: remove pkger from make targets"
lance May 12, 2021
cb3909d
Revert "src: replace pkger with embed.FS"
lance May 12, 2021
4af6e1b
Revert "src: update references to deprecated ioutil"
lance May 12, 2021
dbaa2f2
Revert "src: require go 1.16"
lance May 12, 2021
0dc85da
chore: update pkged.go
lance May 12, 2021
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
61 changes: 42 additions & 19 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,47 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- name: Determine download URL for pkger
id: pkger-download-url
uses: actions/github-script@v2
with:
go-version: '^1.16'
result-encoding: string
script: |
return github.repos.getReleaseByTag({
owner: "markbates",
repo: "pkger",
tag: "v0.17.1"
}).then(result => {
return result.data.assets
.filter(a => a.name.includes('Linux_x86'))
.map(a => a.browser_download_url)[0];
})
- name: Install pkger
run: |
curl -s -L -o pkger.tgz ${{ steps.pkger-download-url.outputs.result }}
tar xvzf pkger.tgz
- name: Test
run: make test
env:
PKGER: "./${{ steps.pkger-binaries.outputs.binary }}"
- name: Lint
run: make check
outputs:
pkger: ${{ steps.pkger-download-url.outputs.result }}

build-and-publish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.16'
# Release
# Create a release, or update the release PR
- uses: GoogleCloudPlatform/release-please-action@v2.24.1
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: simple
bump-minor-pre-major: true
# Checkout
- uses: actions/checkout@v2
# Tag
# If a release was created, tag `vX.Y.Z` synchronously which:
# 1. Triggers release-please to create draft release, allowing manual
Expand All @@ -52,23 +70,28 @@ jobs:
git push origin :v${{steps.release.outputs.major}}.${{steps.release.outputs.minor}}.${{steps.release.outputs.patch}} || true
git tag -a v${{steps.release.outputs.major}}.${{steps.release.outputs.minor}}.${{steps.release.outputs.patch}} -m "Release v${{steps.release.outputs.major}}.${{steps.release.outputs.minor}}.${{steps.release.outputs.patch}}"
git push origin v${{steps.release.outputs.major}}.${{steps.release.outputs.minor}}.${{steps.release.outputs.patch}} || true
# Build

- uses: actions/setup-go@v2
- name: Install pkger
run: |
curl -s -L -o pkger.tgz ${{ needs.test.outputs.pkger }}
tar xvzf pkger.tgz

# Standard build tasks
- name: Build
run: make cross-platform
# NOTE:
# release-please adds the version asynchronously. Without using the
# synchonous tagging step above, the version can be explicitly passed
# to the build using the following environment variable. However this
# has the side-effect of causing inter-relese binaries to not include
# verbose version information, because the special version `tip` is
# overriden with a blank string in those cases.
# env:
# VERS: ${{ steps.release.outputs.tag_name }}
env:
PKGER: "./pkger"
# NOTE:
# release-please adds the version asynchronously. Without using the
# synchonous tagging step above, the version can be explicitly passed
# to the build using the following environment variable. However this
# has the side-effect of causing inter-relese binaries to not include
# verbose version information, because the special version `tip` is
# overriden with a blank string in those cases.
# VERS: ${{ steps.release.outputs.tag_name }}

# Upload
# All build artifacts are uploaded whether release or not
# Non-release binaries have a verbose version `tip-[git hash]-[build timestamp]`
# Upload all build artifacts whether it's a release or not
- uses: actions/upload-artifact@v2
with:
name: OSX Binary
Expand Down
53 changes: 50 additions & 3 deletions .github/workflows/pull_requests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,61 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- name: Determine platform binaries
id: pkger-binaries
uses: actions/github-script@v2
with:
go-version: '^1.16'
result-encoding: string
script: |
let platform, binary;
switch ('${{matrix.os}}') {
case 'ubuntu-latest':
platform = 'Linux_x86'
binary = 'pkger'
break
case 'windows-latest':
platform = 'Windows_x86'
binary = 'pkger.exe'
break
case 'macos-latest':
platform = 'Darwin_x86'
binary = 'pkger'
break
}
core.setOutput('platform', platform)
core.setOutput('binary', binary)
- name: Determine download URL for latest pkger
id: pkger-download-url
uses: actions/github-script@v2
with:
result-encoding: string
script: |
let platform = "${{ steps.pkger-binaries.outputs.platform }}"
let binary = "${{ steps.pkger-binaries.outputs.binary }}"
core.info('PLATFORM: ' + platform)
core.info('BINARY: ' + binary)
return github.repos.getReleaseByTag({
owner: "markbates",
repo: "pkger",
tag: "v0.17.1"
}).then(result => {
return result.data.assets
.filter(a => a.name.includes(platform))
.map(a => a.browser_download_url)[0];
})
- name: Install pkger
run: |
curl -s -L -o pkger.tgz ${{ steps.pkger-download-url.outputs.result }}
tar xvzf pkger.tgz

- name: Test
run: make test
env:
PKGER: "./${{ steps.pkger-binaries.outputs.binary }}"
- name: Build
run: make build
env:
PKGER: "./${{ steps.pkger-binaries.outputs.binary }}"
- name: Lint
run: make check

Expand All @@ -28,8 +77,6 @@ jobs:
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
- name: Provision Cluster
uses: lkingland/kind-action@v1 # use ./hack/allocate.sh locally
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/func
/func_*
/templates.tgz
/templates/go/events/go.sum
/templates/go/http/go.sum
/coverage.out
/bin

Expand Down
47 changes: 25 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
REPO := quay.io/boson/func
BIN := func

BIN := func
DARWIN :=$(BIN)_darwin_amd64
LINUX :=$(BIN)_linux_amd64
WINDOWS :=$(BIN)_windows_amd64.exe
PKGER?=pkger

DARWIN=$(BIN)_darwin_amd64
LINUX=$(BIN)_linux_amd64
WINDOWS=$(BIN)_windows_amd64.exe

CODE := $(shell find . -name '*.go')
DATE := $(shell date -u +"%Y%m%dT%H%M%SZ")
Expand All @@ -14,43 +16,45 @@ VTAG := $(shell git tag --points-at HEAD)
# unless explicitly, synchronously tagging as is done in ci.yaml
VERS ?= $(shell [ -z $(VTAG) ] && echo 'tip' || echo $(VTAG) )

LDFLAGS := -X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)
TEMPLATE_DIRS=$(shell find templates -type d)
TEMPLATE_FILES=$(shell find templates -type f -name '*')
TEMPLATE_PACKAGE=pkged.go

build: all
all: $(BIN)
all: $(TEMPLATE_PACKAGE) $(BIN)

templates.tgz:
# ensure no cached dependencies are added to the binary
$(TEMPLATE_PACKAGE): templates $(TEMPLATE_DIRS) $(TEMPLATE_FILES)
# ensure no cached dependencies are added to the binary
rm -rf templates/node/events/node_modules
rm -rf templates/node/http/node_modules
rm -rf templates/python/events/__pycache__
rm -rf templates/python/http/__pycache__
# see generate.go for details
go generate
# to install pkger: go get github.com/markbates/pkger/cmd/pkger
$(PKGER)

cross-platform: $(DARWIN) $(LINUX) $(WINDOWS)
cross-platform: $(TEMPLATE_PACKAGE) $(DARWIN) $(LINUX) $(WINDOWS)

darwin: $(DARWIN) ## Build for Darwin (macOS)

linux: $(LINUX) ## Build for Linux

windows: $(WINDOWS) ## Build for Windows

$(BIN): templates.tgz $(CODE) ## Build using environment defaults
env CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" ./cmd/$(BIN)
$(BIN): $(CODE) ## Build using environment defaults
env CGO_ENABLED=0 go build -ldflags "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)" ./cmd/$(BIN)

$(DARWIN): templates.tgz
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(DARWIN) -ldflags "$(LDFLAGS)" ./cmd/$(BIN)
$(DARWIN):
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(DARWIN) -ldflags "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)" ./cmd/$(BIN)

$(LINUX): templates.tgz
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(LINUX) -ldflags "$(LDFLAGS)" ./cmd/$(BIN)
$(LINUX):
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(LINUX) -ldflags "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)" ./cmd/$(BIN)

$(WINDOWS): templates.tgz
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $(WINDOWS) -ldflags "$(LDFLAGS)" ./cmd/$(BIN)
$(WINDOWS):
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $(WINDOWS) -ldflags "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.hash=$(HASH)" ./cmd/$(BIN)

test: test-binary test-node test-python test-quarkus test-go

test-binary: templates.tgz
test-binary:
go test -race -cover -coverprofile=coverage.out ./...

test-node:
Expand All @@ -69,7 +73,7 @@ test-go:
cd templates/go/events && go test
cd templates/go/http && go test

test-integration: templates.tgz
test-integration:
go test -tags integration ./...

bin/golangci-lint:
Expand All @@ -91,5 +95,4 @@ cluster: ## Set up a local cluster for integraiton tests.

clean:
rm -f $(BIN) $(WINDOWS) $(LINUX) $(DARWIN)
rm -f templates.tgz
-rm -f coverage.out
4 changes: 2 additions & 2 deletions buildpacks/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/buildpacks/pack"
"github.com/buildpacks/pack/logging"

fn "github.com/boson-project/func"
bosonFunc "github.com/boson-project/func"
)

//Builder holds the configuration that will be passed to
Expand All @@ -37,7 +37,7 @@ var RuntimeToBuildpack = map[string]string{
}

// Build the Function at path.
func (builder *Builder) Build(ctx context.Context, f fn.Function) (err error) {
func (builder *Builder) Build(ctx context.Context, f bosonFunc.Function) (err error) {

// Use the builder found in the Function configuration file
// If one isn't found, use the defaults
Expand Down
5 changes: 3 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -339,14 +340,14 @@ func (c *Client) Create(cfg Function) (err error) {
}

// Write out a template.
w := templateWriter{repositories: c.templates, verbose: c.verbose}
w := templateWriter{templates: c.templates, verbose: c.verbose}
if err = w.Write(f.Runtime, f.Trigger, f.Root); err != nil {
return
}

// Check if template specifies a builder image. If so, add to configuration
builderFilePath := filepath.Join(f.Root, ".builders.yaml")
if builderConfig, err := os.ReadFile(builderFilePath); err == nil {
if builderConfig, err := ioutil.ReadFile(builderFilePath); err == nil {
// A .builder file was found. Read the default builder and set in the config file
// TODO: A command line flag could be used to specify non-default builders
builders := make(map[string]string)
Expand Down
Loading