Documentation
¶
Overview ¶
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Example (CheckUpdated_outdated) ¶
// clone olaris folder into a temp folder
tmpDir, err := os.MkdirTemp("", "ops-test")
if err != nil {
pr("failed to create temp dir", err)
}
defer RemoveAll(tmpDir)
tmpDirBranch := joinpath(tmpDir, getOpsBranch())
olarisTmpPath := joinpath(tmpDirBranch, "olaris")
repo, _ := git.PlainClone(olarisTmpPath, false, &git.CloneOptions{
URL: getOpsRepo(),
},
)
// run checkUpdated and check if it creates the latest_check file
createLatestCheckFile(tmpDirBranch)
if exists(tmpDirBranch, ".latestcheck") {
pr("latest_check file created")
}
// change latest_check file mtime to 2 seconds ago
changeLatestCheckTime(tmpDirBranch, -2*time.Second)
// git reset olaris to a previous commit
resetOneCommit(repo)
// re-run checkUpdated and check output
checkUpdated(tmpDir, 1*time.Second)
Output: latest_check file created Checking for updates... New tasks available! Use 'ops -update' to update.
Example (CheckUpdated_uptodate) ¶
// clone olaris folder into a temp folder
tmpDir, err := os.MkdirTemp("", "ops-test")
if err != nil {
pr("failed to create temp dir", err)
}
defer RemoveAll(tmpDir)
tmpDirBranch := joinpath(tmpDir, getOpsBranch())
olarisTmpPath := joinpath(tmpDirBranch, "olaris")
_, _ = git.PlainClone(olarisTmpPath, false, &git.CloneOptions{
URL: getOpsRepo(),
},
)
// run checkUpdated and check if it creates the latest_check file
createLatestCheckFile(tmpDirBranch)
if exists(tmpDirBranch, ".latestcheck") {
pr("latest_check file created")
}
// change latest_check file mtime to 2 seconds ago
changeLatestCheckTime(tmpDirBranch, -2*time.Second)
// re-run checkUpdated and check output "Tasks up to date!"
checkUpdated(tmpDir, 1*time.Second)
Output: latest_check file created Checking for updates... Tasks up to date!
Example (Download) ¶
TODO: undestand why it fails when executed with others it works executed alone
_ = os.Chdir(workDir)
OpsBranch = "0.1.0"
opsdir, _ := homedir.Expand("~/.ops")
_ = RemoveAll(opsdir)
_, _ = downloadTasksFromGitHub(true, true)
dir, err := locateOpsRoot(".")
pr(1, err, nhpath(dir))
_, _ = downloadTasksFromGitHub(true, true)
dir, err = locateOpsRoot(".")
pr(2, err, nhpath(dir))
Output: Cloning tasks... Tasks downloaded successfully 1 <nil> /home/.ops/0.1.0/olaris Updating tasks... Tasks are already up to date! 2 <nil> /home/.ops/0.1.0/olaris
Example (DownloadPrereq) ¶
bindir, err := EnsureBindir()
if err != nil {
RemoveAll(bindir)
}
prqdir := joinpath(joinpath(workDir, "tests"), "prereq")
prq, _ := loadPrereq(prqdir)
fmt.Println("1", downloadPrereq("bun", prq.Tasks["bun"]))
fmt.Println("2", downloadPrereq("bun", prq.Tasks["bun"]))
prq, _ = loadPrereq(joinpath(prqdir, "sub"))
//fmt.Println(prq)
//fmt.Println(PrereqSeenMap)
fmt.Println("3", downloadPrereq("bun", prq.Tasks["bun"]))
Output: downloading bun v1.11.20 1 <nil> 2 <nil> 3 WARNING: bun prerequisite found twice with different versions! Previous version: v1.11.20, ignoring v1.11.21
Example (EnsureBindir) ¶
// cleanup
bindir, err := EnsureBindir()
if err == nil {
RemoveAll(bindir)
} else {
fmt.Println(err)
}
// ensure no dir
_, err = os.Stat(bindir)
if err != nil {
fmt.Println(1, after(":", err.Error()))
}
bindir1, err := EnsureBindir()
if err != nil {
fmt.Println(err)
}
_, err = os.Stat(bindir1)
fmt.Println(2, err)
fmt.Println(3, bindir == bindir1)
Output: 1 no such file or directory 2 <nil> 3 true
Example (EnsurePrereq) ¶
bindir, err := EnsureBindir()
if err == nil {
RemoveAll(bindir)
}
dir := joinpath(joinpath(workDir, "tests"), "prereq")
fmt.Println(ensurePrereq(dir))
fmt.Println(ensurePrereq(joinpath(dir, "sub")))
Output: downloading bun v1.11.20 downloading coreutils 0.0.27 <nil> error in prereq bun: WARNING: bun prerequisite found twice with different versions! Previous version: v1.11.20, ignoring v1.11.21 <nil>
Example (ExecPrereqTask) ¶
fmt.Println(execPrereqTask("bin", "bun"))
Output: invoking prereq for bun <nil>
Example (LoadArgs) ¶
_ = os.Chdir(workDir)
fmt.Println(1, loadSavedArgs())
_ = os.Chdir(joinpath("tests", "testdata"))
fmt.Println(2, loadSavedArgs())
Output: 1 [] 2 [V1=hello V2=hello V2=world]
Example (LoadPrereq) ¶
//downloadPrereq("")
dir := joinpath(workDir, "tests")
_, err := loadPrereq(dir)
fmt.Println(npath(err.Error()))
prq, err := loadPrereq(joinpath(dir, "prereq"))
//fmt.Println(prq)
fmt.Println(err, *prq.Tasks["bun"].Description, prq.Tasks["bun"].Vars["VERSION"])
Output: not found /work/tests <nil> bun v1.11.20
Example (Locate) ¶
_ = os.Chdir(workDir)
dir, err := locateOpsRoot("tests")
pr(1, err, npath(dir))
dir, err = locateOpsRoot(joinpath("tests", "olaris"))
pr(2, err, npath(dir))
dir, err = locateOpsRoot(joinpath("tests", joinpath("olaris", "sub")))
pr(3, err, npath(dir))
Output: 1 <nil> /work/tests/olaris 2 <nil> /work/tests/olaris 3 <nil> /work/tests/olaris
Example (Locate_root) ¶
_ = os.Chdir(workDir)
OpsBranch = "0.1.0"
opsdir, _ := homedir.Expand("~/.ops")
_ = RemoveAll(opsdir)
_, err := locateOpsRoot(".")
pr(1, err)
dir, err := locateOpsRoot("tests")
pr(2, err, npath(dir))
Output: 1 cannot find opsfiles, download them with ops -update 2 <nil> /work/tests/olaris
Example (OpsArg) ¶
// test
_ = os.Chdir(workDir)
olaris, _ := filepath.Abs(joinpath("tests", "olaris"))
err := Ops(olaris, split("testcmd"))
pr(2, err)
err = Ops(olaris, split("testcmd arg"))
pr(3, err)
err = Ops(olaris, split("testcmd arg VAR=1"))
pr(4, err)
err = Ops(olaris, split("testcmd VAR=1 arg"))
pr(5, err)
Output: (olaris) task [-t opsfile.yml testcmd --] 2 <nil> (olaris) task [-t opsfile.yml testcmd -- arg] 3 <nil> (olaris) task [-t opsfile.yml testcmd VAR=1 -- arg] 4 <nil> (olaris) task [-t opsfile.yml testcmd VAR=1 -- arg] 5 <nil>
Example (PluginsPrint) ¶
p := plugins{
local: make([]string, 0),
ops: make([]string, 0),
}
p.print()
// Output
// No plugins installed. Use 'ops -plugin' to add new ones.
Example (SetupTmp) ¶
_ = os.Chdir(workDir)
opsdir, _ := homedir.Expand("~/.ops")
RemoveAll(opsdir)
setupTmp()
fmt.Println(nhpath(os.Getenv("OPS_TMP")))
RemoveAll(opsdir)
Output: /home/.ops/tmp
Example (TouchAndClean) ¶
bindir, err := EnsureBindir()
if err != nil {
RemoveAll(bindir)
}
bindir, _ = EnsureBindir()
touch(bindir, "hello")
err = touchAndClean(bindir, "hello", "1.2.3")
fmt.Println(err, exists(bindir, "hello"), exists(bindir, "hello-1.2.3"), exists(bindir, "hello-1.2.4"))
err = touchAndClean(bindir, "hello", "1.2.4")
fmt.Println(err, exists(bindir, "hello"), exists(bindir, "hello-1.2.3"), exists(bindir, "hello-1.2.4"))
Output: <nil> true true false <nil> true false true
Index ¶
- Constants
- Variables
- func EnsureBindir() (string, error)
- func GetOpsRootPlugins() (map[string]string, error)
- func IsWskWrapperCommand(name string) ([]string, bool)
- func Main()
- func Ops(base string, args []string) error
- func Serve(olarisDir string, args []string) error
- func Task(args ...string) (int, error)
- func Trace(args ...any)
- type OpsRootJSON
- type Prereq
- type PrereqTask
- type TaskNotFoundErr
Examples ¶
- Package (CheckUpdated_outdated)
- Package (CheckUpdated_uptodate)
- Package (Download)
- Package (DownloadPrereq)
- Package (EnsureBindir)
- Package (EnsurePrereq)
- Package (ExecPrereqTask)
- Package (LoadArgs)
- Package (LoadPrereq)
- Package (Locate)
- Package (Locate_root)
- Package (OpsArg)
- Package (PluginsPrint)
- Package (SetupTmp)
- Package (TouchAndClean)
- Ops
Constants ¶
const CONFIGFILE = "config.json"
const DOCOPTS = "docopts.txt"
const DefaultOpsPort = 9768
default port for ops server
const LATESTCHECK = ".latestcheck"
const OPSFILE = "opsfile.yml"
default files
const OPSREPO = "http://github.com/apache/openserverless-task"
repo where download tasks
const OPSROOT = "opsroot.json"
const PREREQ = "prereq.yml"
Variables ¶
var OpsBranch string
var OpsVersion string
var PrereqSeenMap = map[string]string{}
var WSK_RUNTIMES_JSON string
Functions ¶
func EnsureBindir ¶
ensure there is a bindir for downloading prerequisites read it from OPS_BIN and create it otherwise setup one in ~/ops/<os>-<arch>/bin and sets OPS_BIN
func GetOpsRootPlugins ¶
GetOpsRootPlugins returns the map with all the olaris-*/opsroot.json files in the local and ~/.ops folders, pointed by their plugin names. If the same plugin is found in both folders, the one in the local folder is used. Useful to build the config map including the plugin configs
func IsWskWrapperCommand ¶
func Ops ¶
Ops parses args moving into the folder corresponding to args then parses them with docopts and invokes the task
Example ¶
// test
_ = os.Chdir(workDir)
os.Setenv("TEST_VAR", "evar")
olaris, _ := filepath.Abs(joinpath("tests", "olaris"))
err := Ops(olaris, split(""))
pr(1, err)
err = Ops(olaris, split("sub"))
pr(4, err)
err = Ops(olaris, split("sub opts"))
pr(5, err)
_ = Ops(olaris, split("sub opts ciao 1"))
// pr(6, err)
Types ¶
type OpsRootJSON ¶
type OpsRootJSON struct {
Version string `json:"version"`
Config map[string]interface{} `json:"config"`
}
Represents opsroot.json. It is used to parse the file.
type Prereq ¶
type Prereq struct {
Version int `yaml:"version"`
Tasks map[string]PrereqTask `yaml:"tasks"`
}
Define the Go structs
type PrereqTask ¶
type TaskNotFoundErr ¶
type TaskNotFoundErr struct {
// contains filtered or unexported fields
}
func (*TaskNotFoundErr) Error ¶
func (e *TaskNotFoundErr) Error() string