How to add new custom command to docker API? - docker

I'm trying to add a new customized command to the docker API, along with all the commands found at docker/api/client
I added the following new mycomand.go file to the forked repository:
package client
import (
"fmt"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
)
func (cli *DockerCli) CmdMycomnd(args ...string) error {
cmd := Cli.Subcmd("CmdMycomnd", []string{"CONTAINER"}, Cli.DockerCommands["CmdMycomnd"].Description, true)
cmd.Require(flag.Exact, 1)
cmd.ParseFlags(args, true)
fmt.Println("Hi!")
return nil
}
Also updated docker/cli/common DockerCommands data structure to contain my new command.
Then pushed the commit to the branch in github, following the instructions on docker doc page.
Now, build the docker using make and tried to execute the binary of the 'new' docker which is found in bundles/1.10.0-dev/binary/ by the command:
./docker-1.10.0-dev mycomnd [option]
The Problem: i get the error: docker: 'mycomnd' is not a docker command. Any idea how to get around this?

You need to add a .go file in the directory /api/client along with all the API commands.
The name of the file should be identical to the name of your command.
In that .go file you should include whatever your command does in a function named Cmd[YourCommandName]
Commit and push the changes to your forked github branch.
Make the binary file
Example:
Say you want to add the command ‘talk’, so you do the following:
Add a new source file named talk.go: $ touch talk.go
Add contents of the .go source file.
Update the project on git hub:
$ git add talk.go NOTE: your pwd should be /api/client
$ git commit -s -m "Making a dry run test."
$ git push --set-upstream origin dry-run-test
$ <add your github account name + password>
Now change directory to docker-master directory and make the project
Change directory to /bundles/1.10.0-dev/binary
Execute: ./docker-1-10-dev talk
DONE!
Contents of our new talk command:
package client
import (
"fmt"
Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag"
)
func (cli *DockerCli) CmdTalk (args ...string) error {
cmd := Cli.Subcmd("talk", []string{"CONTAINER"}, Cli.DockerCommands["talk"].Description, true)
cmd.Require(flag.Exact, 0)
cmd.ParseFlags(args, true)
fmt.Println("Hi")
return nil
}
Screen Shot

Related

Private Azure PYPI not reachable in azure pipelines run

I have a project A managed with pipenv that depends on another project B built with pipenv too. The project B is published in the private PYPI. My Pipfile looks like
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[[source]]
url = "https://${USERNAME}:${TOKEN}#MyPrivateRepoUrl"
verify_ssl = true
name = "MyRepoPYPI"
When I install A locally I have not problems and every works fine (declaring environment variables with export command). I have configured an azure-pipelines.yml with 2 jobs, first install A and testing, and the second one is to build and publish the docker image to the ACR. When I trigger the pipeline, the first job fails with this error:
FAIL
[ResolutionFailure]: File "/home/adminroot/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 741, in _main
[ResolutionFailure]: resolve_packages(pre, clear, verbose, system, write, requirements_dir, packages, dev)
[ResolutionFailure]: File "/home/adminroot/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 709, in resolve_packages
[ResolutionFailure]: requirements_dir=requirements_dir,
[ResolutionFailure]: File "/home/adminroot/.local/lib/python3.7/site-packages/pipenv/resolver.py", line 692, in resolve
[ResolutionFailure]: req_dir=requirements_dir
[ResolutionFailure]: File "/home/adminroot/.local/lib/python3.7/site-packages/pipenv/utils.py", line 1403, in resolve_deps
[ResolutionFailure]: req_dir=req_dir,
[ResolutionFailure]: File "/home/adminroot/.local/lib/python3.7/site-packages/pipenv/utils.py", line 1108, in actually_resolve_deps
[ResolutionFailure]: resolver.resolve()
[ResolutionFailure]: File "/home/adminroot/.local/lib/python3.7/site-packages/pipenv/utils.py", line 833, in resolve
[ResolutionFailure]: raise ResolutionFailure(message=str(e))
[pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
First try clearing your dependency cache with $ pipenv lock --clear, then try the original command again.
Alternatively, you can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Hint: try $ pipenv lock --pre if it is a pre-release dependency.
ERROR: Could not find a version that matches pymooslotting (from -r /tmp/pipenvzsh1c47crequirements/pipenv-y37q7d_w-constraints.txt (line 11))
No versions found
Were https://pypi.org/simple or https://MyUsername:***#MyPrivateRepoUrl reachable?
I'm pretty sure the credentials are set correctly.
The amazing thing is that if I run the second job, the docker image is built correctly, therefore it is telling me that the credentials to install B are being passed correctly.
here is the part of the pipelines where I install A
steps:
- task: UsePythonVersion#0
inputs:
versionSpec: '3.7'
architecture: 'x64'
- script: |
python -m pip install --user --upgrade pip
python -m pip install --user pipenv
displayName: Install Pipenv
- script: |
pipenv lock --clear
pipenv install --system
displayName: Install Dev Dependencies
- bash: pytest -rf
displayName: Unit test
I'm not commiting the lock file, but I have done many tests that include the lock in the repo.
Here is the command for docker Publish (that works fine and do the job)
- task: Docker#2
displayName: Build Docker Image
inputs:
command: build
containerRegistry: $(acrRepository)
repository: samples/execslotting
inputs:
tags: |
latest
$(tag)
arguments: '--build-arg USERNAME=$(MyUserName) --build-arg TOKEN=$(MyToken)'
The docker image is installing B, so in the build I pass USERNAME and TOKEN vars.
OBS: The error message No versions found Were https://pypi.org/simple or https://MyUsername:***#MyPrivateRepoUrl reachable? tells me that the envars are correctly read in the execution of the installation job.
the docs specify a different push and pull endpoint urls for pip... Try appending /pypi/simple to the repo description where you are pulling from.
full url: https://<your-feed-name>:<your-PAT-key>#pkgs.dev.azure.com/<your-organization-name>/<your-project-name>/_packaging/<your-feed-name>/pypi/simple/

How can I create a file via an XCode run-script and add to project?

I want to display my git version on my app. From some research, it looks like I can accomplish this via a run-script.
This code below will create a file at Resources/GitVersion.swift
version=$(git rev-parse --verify HEAD | cut -c 1-10)
commitDate=$(git log -n 1 HEAD --pretty=format:"%h - %cd" | cut -c 12-)
filesource="//\n// GitVersion.swift\n//\n// Commit Date:$commitDate\n//\n\nlet gitVersion = \"$version\"\n"
cd ${SOURCE_ROOT}/${PROJECT_NAME}
echo "$filesource" > Resources/GitVersion.swift
touch Resources/GitVersion.swift
The file will look like: let gitVersion = XXX, and will update each time the code runs.
Great, except GitVersion.swift isn't in my project, so I can't reference gitVersion anywhere to access the git hash.
How can I add GitVersion.swift via a runscript to my project, such that every time I run my build, it creates the file and dynamically adds the dependency to the project?

Bitbake Setting BBPATH: command not found

I'm comparatively new to Ubuntu and bitbake. Working my way through 'Bitbake User Manual (https://www.yoctoproject.org/docs/1.6/bitbake-user-manual/bitbake-user-manual.html). Yocto version is sumo (git checkout tags/yocto-2.4.1 -b poky_2.4.1); ubuntu 18.04 version.
Trying to set BBPATH for my project directory (step 3), as:
BBPATH = "/home/benjamin/Documents/c code/helloWorld"
Error:
BBPATH: command not found
All else is working fine, so far. The echo $PATH command shows:
/home/benjamin/digikey/poky/bitbake/bin
/home/benjamin/digikey/poky/bitbake/lib
/home/benjamin/digikey/poky/build/conf
The ./conf directory has the as-yet unedited *.conf files:
local.conf
bblayers.conf
At /home/benjamin, the command:
bitbake --version
returns
BitBake Build Tool Core version 1.38.0
So, that's good. Please give me a hint on setting BBPATH.
You may update your bblayer.conf file as so
BBLAYERS += " ${BSPDIR}/path_to_layer "
you may then use bitbake to compile
eg:
bitbake name-of-recipe
Here are a few references
https://community.nxp.com/docs/DOC-331917
https://www.youtube.com/watch?v=kmrHAHADoI8

8th wall web app setup child compilation failed

I am new to 8th wall. I have cloned 8th wall web from git and executed below steps properly
# cd <directory_where_you_saved_sample_project_files>
# cd serve
# npm install
# cd ..
# ./serve/bin/serve -d <sample_project_location>
but on execution of last step which is for ex.
./serve/bin/serve -n -d gettingstarted/xraframe/ -p 7777
I am getting below errors
Failed to compile.
Error: Child compilation failed: Entry module not found: Error:
Can't resolve
'C:\8thWall_Project\web\serve\bin\gettingstarted\xraframe"
\index.html' in 'C:\8thWall_Project\web\serve': Error: Can't resolve
'C:\8thWall_Project\web\serve\bin\gettingstarted\xraframe"
\index.html' in 'C:\8thWall_Project\web\serve'
compiler.js:79 childCompiler.runAsChild
[serve]/[html-webpack-plugin]/lib/compiler.js:79:16
Compiler.js:306 compile
[serve]/[webpack]/lib/Compiler.js:306:11
Compiler.js:631 hooks.afterCompile.callAsync.err
[serve]/[webpack]/lib/Compiler.js:631:15
Hook.js:154 AsyncSeriesHook.lazyCompileHook
[serve]/[tapable]/lib/Hook.js:154:20
Compiler.js:628 compilation.seal.err
[serve]/[webpack]/lib/Compiler.js:628:31
Hook.js:154 AsyncSeriesHook.lazyCompileHook
[serve]/[tapable]/lib/Hook.js:154:20
Compilation.js:1325 hooks.optimizeAssets.callAsync.err
[serve]/[webpack]/lib/Compilation.js:1325:35
Any idea or pointers what is missing?
Thanks
I don't know why, but bat file don't want to be opened by path. Just go to the serve\bin directory and launch bat from here, like that:
7777 is unnecessary. problem was, that it can't find path to your xraframe
project, as you are in another directory, so you have to go tow directories up in ypur path for xraframe
It seems as if you're attempting this on a Windows computer. The serve process for Windows is slightly different than on macOS.
Instead of the normal serve script, use the serve.bat executable.
serve\bin\serve.bat -n -d gettingstarted\xraframe -p 7777
https://docs.8thwall.com/web/#locally-from-windows

how to use execute() in groovy to run any command

I usually build my project using these two commands from command line (dos)
G:\> cd c:
C:\> cd c:\my\directory\where\ant\exists
C:\my\directory\where\ant\exists> ant -Mysystem
...
.....
build successful
What If I want to do the above from groovy instead? groovy has execute() method but following does not work for me:
def cd_command = "cd c:"
def proc = cd_command.execute()
proc.waitFor()
it gives error:
Caught: java.io.IOException: Cannot run program "cd": CreateProcess error=2, The
system cannot find the file specified
at ant_groovy.run(ant_groovy.groovy:2)
Or more explicitly, I think binil's solution should read
"your command".execute(null, new File("/the/dir/which/you/want/to/run/it/from"))
According to this thread (the 2nd part), "cd c:".execute() tries to run a program called cd which is not a program but a built-in shell command.
The workaround would be to change directory as below (not tested):
System.setProperty("user.dir", "c:")
"your command".execute(null, /the/dir/which/you/want/to/run/it/from)
should do what you wanted.
Thanks Noel and Binil, I had a similar problem with a build Maven.
projects = ["alpha", "beta", "gamma"]
projects.each{ project ->
println "*********************************************"
println "now compiling project " + project
println "cmd /c mvn compile".execute(null, new File(project)).text
}
I got to fix the issue by running a command as below:
i wanted to run git commands from git folder, so below is the code which worked for me.
println(["git","add","."].execute(null, new File("/Users/xyz/test-org/groovy-scripts/$GIT_REPOS/")).text)
println(["git","commit","-m","updated values.yaml"].execute(null, new File("/Users/xyz/test-org/groovy-scripts/$GIT_REPOS/")).text)
println(["git","push","--set-upstream","origin","master"].execute(null, new File("/Users/xyz/test-org/groovy-scripts/$GIT_REPOS/")).text)

Resources