Skip to content
Open
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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
all: dep build
./fn

build:
build:
go build -o fn

generate-oci-parity:
Expand All @@ -11,7 +11,7 @@ generate-oci-parity:
install:
go build -o ${GOPATH}/bin/fn

docker:
docker:
docker build -t fnproject/fn:latest .

dep:
Expand All @@ -24,7 +24,7 @@ release:
GOOS=linux go build -o fn_linux
GOOS=darwin go build -o fn_mac
GOOS=windows go build -o fn.exe
# Uses fnproject/go:x.x-dev because golang:alpine has this issue: https://github.com/docker-library/golang/issues/155 and this https://github.com/docker-library/golang/issues/153
docker run --rm -v ${PWD}:/go/src/github.com/fnproject/cli -w /go/src/github.com/fnproject/cli fnproject/go:1.23-dev go build -o fn_alpine
# Uses container-registry.oracle.com/oci_functions/go:x.x-dev because golang:alpine has this issue: https://github.com/docker-library/golang/issues/155 and this https://github.com/docker-library/golang/issues/153
docker run --rm -v ${PWD}:/go/src/github.com/fnproject/cli -w /go/src/github.com/fnproject/cli container-registry.oracle.com/oci_functions/go:1.23-dev go build -o fn_alpine

.PHONY: install test build
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,3 @@ You can add more ignore rules by creating a `.fnignore` file in the watched dire
### Build from source
See [CONTRIBUTING](https://github.com/fnproject/cli/blob/master/CONTRIBUTING.md) for instructions to build the CLI from source.




8 changes: 5 additions & 3 deletions commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func StartCommand() cli.Command {
},
cli.StringFlag{
Name: "version",
Usage: "Specify a specific fnproject/fnserver version to run, ex: '1.2.3'.",
Usage: "Specify a specific Fn server version to run, ex: '1.2.3'.",
Value: "latest",
},
cli.IntFlag{
Expand Down Expand Up @@ -143,7 +143,7 @@ func start(c *cli.Context) error {
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
log.Fatalln("Starting command failed:", err)
return fmt.Errorf("could not start Fn server image %s: %w", image, err)
}

done := make(chan error, 1)
Expand All @@ -153,6 +153,7 @@ func start(c *cli.Context) error {
// catch ctrl-c and kill
sigC := make(chan os.Signal, 2)
signal.Notify(sigC, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigC)

log.Println("¡¡¡ 'fn start' should NOT be used for PRODUCTION !!! see https://github.com/fnproject/fn-helm/")

Expand All @@ -167,8 +168,9 @@ func start(c *cli.Context) error {
}
case err := <-done:
if err != nil {
log.Println("Error: processed finished with error", err)
return fmt.Errorf("could not run Fn server image %s: %w", image, err)
}
return nil
}
return err
}
Expand Down
31 changes: 14 additions & 17 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import (

// Global docker variables.
const (
FunctionsDockerImage = "fnproject/fnserver"
FunctionsDockerImage = config.OCRImagePrefix + "fnserver"
FuncfileDockerRuntime = "docker"
MinRequiredDockerVersion = "17.5.0"
BuildxBuilderInstance = "oci_fn_builder"
Expand Down Expand Up @@ -1262,30 +1262,27 @@ func PullImage(image string) error {
cmd := ShellCommander(containerEngineType, args...)
cmd.SetStdOut(os.Stdout)
cmd.SetStdErr(os.Stderr)
err = cmd.Start()
if err != nil {
log.Fatalln("Starting command failed:", err)
}

done := make(chan error, 1)
go func() {
done <- cmd.Wait()
}()
// catch ctrl-c and kill
// Register before starting so cancellation cannot miss a running pull.
sigC := make(chan os.Signal, 2)
signal.Notify(sigC, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigC)
if err := cmd.Start(); err != nil {
return fmt.Errorf("could not start %s pull for %s: %w", containerEngineType, image, err)
}

done := make(chan error, 1)
go func() { done <- cmd.Wait() }()
select {
case <-sigC:
log.Println("Interrupt caught, exiting")
err = cmd.Kill()
if err != nil {
log.Println("Error: could not kill process")
if err := cmd.Kill(); err != nil {
return fmt.Errorf("could not cancel pull for %s: %w", image, err)
}
<-done
return fmt.Errorf("pull cancelled for %s", image)
case err := <-done:
if err != nil {
log.Println("Processed finished with error:", err)
} else {
log.Println("Process finished gracefully")
return fmt.Errorf("%s pull failed for %s: %w", containerEngineType, image, err)
}
}
return nil
Expand Down
19 changes: 10 additions & 9 deletions common/image_stamp_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"github.com/fnproject/cli/config"
"path/filepath"
"testing"
)
Expand All @@ -17,26 +18,26 @@ func TestImageStampFuncFileV20180708UsesExpectedRuntimeVersion(t *testing.T) {
{
name: "legacy node runtime uses fallback version",
runtime: "node",
wantBuild: "fnproject/node:22-dev",
wantRun: "fnproject/node:22",
wantBuild: config.OCRImagePrefix + "node:22-dev",
wantRun: config.OCRImagePrefix + "node:22",
},
{
name: "explicit node24 runtime keeps requested version",
runtime: "node24",
wantBuild: "fnproject/node:24-dev",
wantRun: "fnproject/node:24",
wantBuild: config.OCRImagePrefix + "node:24-dev",
wantRun: config.OCRImagePrefix + "node:24",
},
{
name: "legacy java runtime uses fallback version",
runtime: "java",
wantBuild: "fnproject/fn-java-fdk-build:jdk17-1.2.3",
wantRun: "fnproject/fn-java-fdk:jre17-1.2.3",
wantBuild: config.OCRImagePrefix + "fn-java-fdk-build:jdk17-1.2.3",
wantRun: config.OCRImagePrefix + "fn-java-fdk:jre17-1.2.3",
},
{
name: "explicit java21 runtime keeps requested version",
runtime: "java21",
wantBuild: "fnproject/fn-java-fdk-build:jdk21-1.2.3",
wantRun: "fnproject/fn-java-fdk:jre21-1.2.3",
wantBuild: config.OCRImagePrefix + "fn-java-fdk-build:jdk21-1.2.3",
wantRun: config.OCRImagePrefix + "fn-java-fdk:jre21-1.2.3",
},
}

Expand All @@ -58,4 +59,4 @@ func TestImageStampFuncFileV20180708UsesExpectedRuntimeVersion(t *testing.T) {
}
})
}
}
}
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
)

const (
// OCRImagePrefix is the namespace, including the trailing slash, for Fn-provided images.
OCRImagePrefix = "container-registry.oracle.com/oci_functions/"

rootConfigPathName = ".fn"

contextsPathName = "contexts"
Expand Down
2 changes: 1 addition & 1 deletion langs/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type LangHelper interface {
Extensions() []string
// Runtime that will be used for the build (includes version)
Runtime() string
// BuildFromImage is the base image to build off, typically fnproject/LANG:dev
// BuildFromImage is the base image to build off, from the OCR oci_functions namespace
BuildFromImage() (string, error)
// RunFromImage is the base image to use for deployment (usually smaller than the build images)
RunFromImage() (string, error)
Expand Down
6 changes: 4 additions & 2 deletions langs/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"io/ioutil"
"os"
"path/filepath"

"github.com/fnproject/cli/config"
)

var dotnetToFrameworkVersionMap = map[string]string{
Expand Down Expand Up @@ -56,12 +58,12 @@ func (lh *DotnetLangHelper) Extensions() []string {

func (lh *DotnetLangHelper) BuildFromImage() (string, error) {
fdkVersion, _ := lh.GetLatestFDKVersion()
return fmt.Sprintf("fnproject/dotnet:%s-%s-dev", lh.Version, fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"dotnet:%s-%s-dev", lh.Version, fdkVersion), nil
}

func (lh *DotnetLangHelper) RunFromImage() (string, error) {
fdkVersion, _ := lh.GetLatestFDKVersion()
return fmt.Sprintf("fnproject/dotnet:%s-%s", lh.Version, fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"dotnet:%s-%s", lh.Version, fdkVersion), nil
}

func (h *DotnetLangHelper) DockerfileBuildCmds(localDebug bool) []string {
Expand Down
6 changes: 4 additions & 2 deletions langs/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"os"
"path/filepath"
"strings"

"github.com/fnproject/cli/config"
)

type GoLangHelper struct {
Expand All @@ -49,11 +51,11 @@ func (lh *GoLangHelper) Extensions() []string {
}

func (lh *GoLangHelper) BuildFromImage() (string, error) {
return fmt.Sprintf("fnproject/go:%s-dev", lh.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"go:%s-dev", lh.Version), nil
}

func (lh *GoLangHelper) RunFromImage() (string, error) {
return fmt.Sprintf("fnproject/go:%s", lh.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"go:%s", lh.Version), nil
}

func (h *GoLangHelper) DockerfileBuildCmds(localDebug bool) []string {
Expand Down
18 changes: 10 additions & 8 deletions langs/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"os"
"path/filepath"
"strings"

"github.com/fnproject/cli/config"
)

// JavaLangHelper provides a set of helper methods for the lifecycle of Java Maven projects
Expand Down Expand Up @@ -63,13 +65,13 @@ func (h *JavaLangHelper) BuildFromImage() (string, error) {
}

if h.Version == "8" {
return fmt.Sprintf("fnproject/fn-java-fdk-build:%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk-build:%s", fdkVersion), nil
} else if h.Version == "11" {
return fmt.Sprintf("fnproject/fn-java-fdk-build:jdk11-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk-build:jdk11-%s", fdkVersion), nil
} else if h.Version == "17" {
return fmt.Sprintf("fnproject/fn-java-fdk-build:jdk17-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk-build:jdk17-%s", fdkVersion), nil
} else if h.Version == "21" {
return fmt.Sprintf("fnproject/fn-java-fdk-build:jdk21-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk-build:jdk21-%s", fdkVersion), nil
} else {
return "", fmt.Errorf("unsupported java version %s", h.Version)
}
Expand All @@ -82,13 +84,13 @@ func (h *JavaLangHelper) RunFromImage() (string, error) {
return "", err
}
if h.Version == "8" {
return fmt.Sprintf("fnproject/fn-java-fdk:%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk:%s", fdkVersion), nil
} else if h.Version == "11" {
return fmt.Sprintf("fnproject/fn-java-fdk:jre11-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk:jre11-%s", fdkVersion), nil
} else if h.Version == "17" {
return fmt.Sprintf("fnproject/fn-java-fdk:jre17-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk:jre17-%s", fdkVersion), nil
} else if h.Version == "21" {
return fmt.Sprintf("fnproject/fn-java-fdk:jre21-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk:jre21-%s", fdkVersion), nil
} else {
return "", fmt.Errorf("unsupported java version %s", h.Version)
}
Expand Down
6 changes: 4 additions & 2 deletions langs/kotlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"os"
"path/filepath"
"strings"

"github.com/fnproject/cli/config"
)

// KotlinLangHelper provides a set of helper methods for the lifecycle of Kotlin Maven projects
Expand Down Expand Up @@ -59,7 +61,7 @@ func (h *KotlinLangHelper) BuildFromImage() (string, error) {
return "", err
}

return fmt.Sprintf("fnproject/fn-java-fdk-build:jdk11-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk-build:jdk11-%s", fdkVersion), nil
}

// RunFromImage returns the Docker image used to run the Kotlin function.
Expand All @@ -69,7 +71,7 @@ func (h *KotlinLangHelper) RunFromImage() (string, error) {
return "", err
}

return fmt.Sprintf("fnproject/fn-java-fdk:jre11-%s", fdkVersion), nil
return fmt.Sprintf(config.OCRImagePrefix+"fn-java-fdk:jre11-%s", fdkVersion), nil
}

// HasBoilerplate returns whether the Java runtime has boilerplate that can be generated.
Expand Down
6 changes: 4 additions & 2 deletions langs/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"net/http"
"os"
"path/filepath"

"github.com/fnproject/cli/config"
)

type NodeLangHelper struct {
Expand All @@ -45,10 +47,10 @@ func (lh *NodeLangHelper) Extensions() []string {
return []string{".js"}
}
func (lh *NodeLangHelper) BuildFromImage() (string, error) {
return fmt.Sprintf("fnproject/node:%s-dev", lh.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"node:%s-dev", lh.Version), nil
}
func (lh *NodeLangHelper) RunFromImage() (string, error) {
return fmt.Sprintf("fnproject/node:%s", lh.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"node:%s", lh.Version), nil
}

const funcJsContent = `const fdk=require('@fnproject/fdk');
Expand Down
6 changes: 4 additions & 2 deletions langs/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"net/http"
"os"
"path/filepath"

"github.com/fnproject/cli/config"
)

// PythonLangHelper - python-specific init helper
Expand Down Expand Up @@ -80,11 +82,11 @@ func (h *PythonLangHelper) Extensions() []string {
}

func (h *PythonLangHelper) BuildFromImage() (string, error) {
return fmt.Sprintf("fnproject/python:%s-dev", h.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"python:%s-dev", h.Version), nil
}

func (h *PythonLangHelper) RunFromImage() (string, error) {
return fmt.Sprintf("fnproject/python:%s", h.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"python:%s", h.Version), nil
}

func (h *PythonLangHelper) Entrypoint() (string, error) {
Expand Down
6 changes: 4 additions & 2 deletions langs/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"net/http"
"os"
"path/filepath"

"github.com/fnproject/cli/config"
)

type RubyLangHelper struct {
Expand Down Expand Up @@ -50,10 +52,10 @@ func (h *RubyLangHelper) CustomMemory() uint64 {
return 0
}
func (h *RubyLangHelper) BuildFromImage() (string, error) {
return fmt.Sprintf("fnproject/ruby:%s-dev", h.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"ruby:%s-dev", h.Version), nil
}
func (h *RubyLangHelper) RunFromImage() (string, error) {
return fmt.Sprintf("fnproject/ruby:%s", h.Version), nil
return fmt.Sprintf(config.OCRImagePrefix+"ruby:%s", h.Version), nil
}

func (h *RubyLangHelper) DockerfileBuildCmds(localDebug bool) []string {
Expand Down
Loading