Git Product home page Git Product logo

controller's Introduction

Development of Appsody as a standalone project has ended, but the core technologies of Appsody have been merged with odo to create odo 2.0! See our blog post for more details!

appsody-controller

The appsody-controller is an Appsody process that runs inside the Docker container. The controller does any preinstall required, starts the server with the command specified for run, debug or test mode, and watches for file changes, if configured to do so. If so configured, when file or directory changes occur it runs an "ON_CHANGE" action specific to the mode.

Build Notes:

Travis Build

The project is instrumented with Travis CI and an appropriate Makefile. Most of the build logic is triggered from within the Makefile.

Upon commit, only the test and lint actions are run by Travis.

In order for Travis to go all the way to package and deploy, you need to create a new release (one that is tagged with a never seen before tag). When you create a new release, a Travis build is automatically run, and the resulting artifacts are posted on the Releases page.

Manual Build

You can also test the build process manually.

Set the GOPATH environment variable, then run make <action...> from the command line, within the directory that contains the makefile. For example, make package clean runs the package and then the clean actions.

Supported make commands include:

  • make lint - Lints the files
  • make test - Runs automated test cases
  • make build - Builds the binary in the build directory
  • make package - Builds the Linux binary and stores it in the package directory

Where to find the latest binary build

[https://github.com/appsody/controller/releases]

The controller needs to be executable. Note you might have to chmod the permissions to be executable.

Environment Variables

To use the controller, you must configure the relevant Dockerfile environment variables. For more information about the environment variables currently supported by Appsody, see here.

Running the controller for development:

Run the appsody-controller-vlatest (appsody-controller) command located in the build directory

There are two parameters -mode (--mode) and -debug (--debug)

-mode controls which mode the controller runs in: run, debug, or test. If the mode option is unspecified, the mode is assumed to be "run".

The options are as follows (note --mode and -mode are interchangeable):

Mode flag Description
Not specified Mode defaults to run
--mode Mode is set to run
--mode=debug Mode is set to debug
--mode=test Mode is set to test
--mode=run Mode is set to run

-v or -verbose controls whether debug level of logging is enabled. If the mode is not specified, it is assumed to be false.

This can be specified in several ways (note --verbose and -v are interchangeable):

Verbose flag Description
Not specified Debug logging is off
--v Debug logging is on
--v=false Debug logging is off
--v=true Debug logging is on

--version returns the current version

The docker appsody/init-controller:{travis_tag} image

This image is built as part of the release/deploy process in Travis. This image contains a copy of the appsody-controller binary placed at the / directory of the image.

In addition, the Dockerfile contains a CMD that copies the controller binary to the /.appsody directory when the image is run by the Appsody CLI. The /.appsody directory is mounted on a volume known to the Appsody CLI:

CMD ["cp","/appsody-controller","/.appsody/appsody-controller"]

Building a test init-controller docker image

The developer can build their own init-controller image to test with the CLI by using the build.sh script located at the root of this project.

Note that you must do make package prior to running the build.sh script as the Dockerfile will look for appsody-controller in the package directory.

Specify the following environment variables:

  • TRAVIS_TAG
  • DOCKER_ORG
  • DOCKER_USERNAME
  • DOCKER_PASSWORD

This will build the init-controller image locally and push it to the corresponding DOCKER_ORG/DOCKER_USERNAME/init-controller:{TRAVIS_TAG} docker repository location where it will also be tagged as 'latest'.

Testing the controller with the Appsody CLI

The Appsody CLI makefile specifies a particular version of the appsody-controller that causes a particular version of init-controller to be used.

If a tester needs to test a different version of the controller with the Appsody CLI, there are two environment variables they can export to test with a different version:

APPSODY_CONTROLLER_VERSION will allow the tester to specify a different version of the appsody-controller, for instance 0.3.0 vs 0.3.1:

export APPSODY_CONTROLLER_VERSION=0.3.0

APPSODY_CONTROLLER_IMAGE will allow the tester to specify a different image to use, this is very useful during development. For instance a developer could create a new image for the controller at docker.io/{org}/init-controller:{tag} and then specify this as the image to use when invoking the CLI:

export APPSODY_CONTROLLER_IMAGE=mydockeraccount/my-controller:0.3.2.

If both are specified, APPSODY_CONTROLLER_IMAGE will be used.

Controller behavior

  • As of release 0.2.4 only file related events will trigger ON_CHANGE actions by the controller. Directory events such as mkdir, rmdir, chmod, etc will not trigger ON_CHANGE actions.

  • As of release 0.2.4 a potential problem with how events occuring in the APPSODY_WATCH_IGNORE_DIR are handled has been fixed. Such events are now preprocessed by the watcher code, rather than post processed once the event reaches the controller.

Known issues

  • If the Appsody stack of interest uses a script file (.sh for example) that is then edited by the vi editor while the script is running, the file modification time is not updated on the container file system until the script ends. What this means is that the ON_CHANGE action is not triggered when vi writes the file.

  • The use of symlinks within the directories that the controller monitors for file changes might result in undefined behavior.

Contributing

We welcome all contributions to the Appsody project. Please see our Contributing guidelines

Community

Join our Slack to meet the team, ask for help, and talk about Appsody!

License

Please see LICENSE and NOTICES for more information.

controller's People

Contributors

garypicher avatar gireeshpunathil avatar helenmasters avatar kewegner avatar kylegc avatar lance avatar mhamwala avatar rykal-nate avatar skoh7645 avatar tnixa avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

controller's Issues

Should the file watcher run during APPSODY_PREP?

Currently we launch the watcher async right after we launch the RUN command which in turn does APPSODY_PREP.

We should pull out APPSODY_PREP so it runs sync prior to any of this. OR we should update the run commands logic to spin the func for watching after APPSODY_PREP runs,

Investigation into ON_CHANGE actions during nodejs-express APPSODY_PREP

Description:
In some cases, particularly with appsody run for a clean docker for desktop install on Mac Os or when doing:

appsody init-nodejs-express
appsody run
The first time in a new directory on the Che-emulator environment

We will see:

[Container] Running APPSODY_PREP command: npm install --prefix user-app && npm audit fix --prefix user-app
File watch event detected for: FILE "test.js" REMOVE [/project/user-app/test/test.js]
File watch event detected for: FILE "test.js" CREATE [/project/user-app/test/test.js]

It appears that something in the npm commands may cause the watcher to think there is no test.js file (and due to the 1 event per watcher cycle setting we use, it could be more than just test.js)

FYI: The watcher.go code uses filepath.walk() routine to construct a map of files and then compares the map previously obtained on the poll to the current poll's map.

One short term fix that was tested for this would be to run APPSODY_PREP serially before starting the watcher, note this was brought up in another issue, whether we should watch during APPSODY_PREP.

Longer term, we need to investigate why the watcher/commands exhibit this behavior.

It did not appear to happen with Java Microprofile in the che emulator environment.

It seems to happen with nodejs-express on MacOS when there is a clean docker environment every time with the first appsody run. It has been seen a couple of times after long disuse of appsody init/followed by appsody run.

Note that subsequent appsody run's do not see the behavior.

When APPSODY_<RUN/TEST/DEBUG>_KILL is false, and the server process doesn't exist, the server should be restarted

@kylegc raised this issue. This could happen if Jane has a bug in her code that prevents the server from starting, or the server crashed unexpectedly. The controller would still be watching for Jane to fix the issue with a file change, however the ON_CHANGE action will not be enough to start the server back up. In this scenario, the controller should run the start server command instead of the ON_CHANGE command.

An alternative solution is to watch for the server process to exit, and then exit the controller and container. This would require Jane to fix the code and re-run appsody dev run to restart the container.

Change image name for controller docker image

-Change appsody-controller to init-controller in build.sh

-Remove the setController.sh file

-Remove references to the setControler.sh file in the Dockerfile

  • Add the CMD to copy appsody-controller in the Dockerfile to /.appsody

CMD ["cp","/appsody-controller","/.appsody/appsody-controller"]

How to proceed with "appsody-controller" by using latest "appsody" binary for ppc64le?

Hi Team,

This question is with reference to the enhancement request raised few days back - #59

As I am a bit new to appsody and appsody-controller, please guide me on how can I work with ppc64le specific "appsody-controller" binary by leveraging the recently released "appsody" binary.

The link for appsody binary download is - https://github.com/appsody/appsody/releases/download/0.5.3/appsody-0.5.3-linux-ppc64le.tar.gz

Regards,
Vrushali

Update Controller Readme

Much of the readme's content is now contained in the environment-variables document. It should be replaced with a link.

Improve controller debug trace.

  1. The debug trace has diverged a lot from the CLI trace. Should they be made more similar
  2. Controller outputs a large volume of trace. Is it all needed.
  3. The controller test bucket is heavily dependent on trace output. Changes may break the test cases.

Shell error messages different on different versions of linux.

When testing #57, our CI/CD system tests fail because /bin/sh has a different error response when an invalid command is specified.

root@9a9fc7d528b1:/project/user-app# bad
bash: bad: command not found
root@9a9fc7d528b1:/project/user-app# sh

bad

sh: 1: bad: not found

echo $0

sh

exit

root@9a9fc7d528b1:/project/user-app# echo $0
bash

This issue updates the tests tolerate both variants.

Is it possible to make appsody-controller binary download available for "ppc64le" architecture?

Hi Team,

We have recently built "appsody" binary from source on linux/ppc64le architecture. We found that ppc64le specific binary is not available for download under https://github.com/appsody/appsody/releases.

Is it possible to make it available for download. We have built it from source by using following steps:

  • Create following directory structure to build go based packages.
    $HOME/go/bin/src/github.com/appsody/Pkg
  • Clone appsody-controller source code into appsody directory from https://github.com/appsody/controller.
  • Install ‘go’ using steps mentioned at https://tecadmin.net/install-go-on-centos.
  • Go into $HOME/go/src/github.com/appsody/controller directory.
  • Execute go build command to build appsody-controller executable.
  • copy both the binaries into /usr/bin directory.
  • Execute appsody-controller version command to verify the binary.

Please let me know the feasibility.

Regards,
Vrushali

Change controller to do a multi arch docker build in travis

Is your feature request related to a problem? Please describe.
This will allow architectures different to x86 to use Appsody as they currently do not work.

Describe the solution you'd like
Use experimental docker daemon buildx across multiple platforms.

File Watcher can not see cached volumes changes

If one makes a change in the DEPS directory it is not seen by the watcher.

At this moment all DEPS directory related changes are to be IGNORED in existing stacks, however, this may change in new stacks in the future.

It is not known what the root cause of this is ATM.

When --interactive is specified when running appsody run and the stack is not tty enabled, ctrl-c no longer causes the docker container to stop

Describe the bug

When --interactive is specified when running appsody run and the stack is not tty enabled, ctrl-c no longer causes the docker container to stop

To Reproduce
For a stack
Make a directory and cd to it
Run the following

  1. appsody init nodejs-express
  2. appsody run --interactive
  3. ctrl-c

Expected behavior
The Controller will cause the container to stop with clean shutdown

Actual behaviour
The container will remain up after the shutdown steps.

Environment Details (please complete the following information):

  • OS: mac catalina
  • Browser NA

If applicable please specify:

  • CLI version:- Version 0.5.0
  • Stack you are using: nodejs-express, java-microprofile

Additional context
None.

Improve process termination when changes are detected

Many stacks have ON_CHANGE commands that end the process by themselves and there is no need to kill them.

Currently the controller tries to kill them in this case, and prints out warning messages which say the kill failed and there is no such process

Outcome desired:
Either:

  1. suppress the above messages

or

*2. Use a similar technique that we use to determine server failures and restarts in the on change events where we send a benign signal to determine if the process is alive.
Then we could avoid unnecessary kill actions.

Make ignoring of file watching event actions configurable

In an earlier issue it was found it might be useful to ignore one of the six types of events, specifically DIR WRITE.

We could create additional APPSODY environment variables which allow our users to turn off any of the six actions for either FILES, DIRs or both

The six actions supported by the watcher include:

CREATE
WRITE
RENAME
MOVE
REMOVE
CHMOD

Add --no-watcher flag to disable file watching regardless of the Docker Environment Variable settings.

Is your feature request related to a problem? Please describe.

Stacks are inconsistent in the behavior of appsody test (some run through and quit, others run and then watch). For a script or other automation, you want to be able to run the tests and quit with the appropriate result based on failures. There isn’t anyway to specify this behavior via the appsody command line at the moment.

Doing any kind of manipulation on test output to determine when tests are done is language/stack specific and fragile. Trying to force all stacks to behave identically with appsody test is also not useful, as we expect further customization of stacks...

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like

appsody test --no-watcher could work.

I want the stack specified tests to run, but for the process to terminate and return with the result of the executed command.

Related to appsody/stacks#308 —> appsody/stacks#323

Windows 10 : ctrl-c doesn't remove the container

Describe the bug
I am sshing to my windows 10 system as jenkinstest user (non-Azure) and I have the shell set to git bash for ssh and when I do an appsody run and then do a ctrl-c to exit out of the run the container does not get removed...

[Container] App started on PORT 3000
[Container] [ControllerDebug] The watch interval is set to: 2s seconds.
[Info] Running command: docker stop express-dev
[Debug] CLI exit error is:  exit status 2
[Info] Closing down, development environment was interrupted.
jenkinstest@DESKTOP-GRG3EVR MINGW64 ~/projects/013020/express
$ ~/bats_temp/temp/src/github.com/appsody/appsody/build/appsody-0.0.0-windows-amd64.exe ps
CONTAINER ID    NAME            IMAGE                                   PORTS                                           STATUS
26cb6c891a52    express-dev     docker.io/appsody/nodejs-express:0.4    0.0.0.0:3000->3000/tcp, 0.0.0.0:9229->9229/tcp  Up 28 seconds
$ echo $SHELL
/c/program files/git/bin/bash.exe

To Reproduce
Steps to reproduce the behavior:

  1. ssh [email protected]
  2. mkdir express
  3. cd express
  4. appsody init nodejs-express
  5. appsody run
  6. ctrl-c

Environment Details (please complete the following information):

  • OS: [e.g. iOS] ssh to windows 10 using non-Azure login

If applicable please specify:

  • CLI version: 0.5.6
  • Stack you are using: nodejs-express
  • Controller version: 0.3.4

Ignore Directory events in file watching.

In order to eliminate issues with APPSODY_ REGEX and watching .*, etc. we should ignore directory events. Because those events aren't of interest and cause unnecessary ON_CHANGE calls.

We will revisit supporting directory events in a future sprint.

Support Creation of Docker image to copy controller

Describe the solution you'd like

  • Change .travis.yml to support the process
  • .travis.yml Call script build.sh as part of deploy
  • Create build.sh script to build docker image and push it
  • Update Travis variables for Docker hub (org, user, pwd)
  • setController contributed script which will copy the appsody-controller to shared volume

Describe alternatives you've considered
See Appsody Issues

Build process should set CGO_ENABLED=0

Describe the bug
Travis builds on Linux, and set CGO_ENABLED=1 by default. This makes the controller non-runnable on several popular Linux Docker images, such as alpine and busybox.

To Reproduce
Steps to reproduce the behavior:
See: appsody/appsody#531

Controller and watcher interaction needs to allow preprocessing of ignored events

Currently the controller limits the number of events it gets back to 1 per watch cycle.
This was originally done to cut down on the number of ON_CHANGE actions performed per cycle.
Unfortunately, this can cause some events which the stack does not consider "ON_CHANGE" events to be processed, and others which would be ON_CHANGE actions to be skipped.

Most of the stacks have APPSODY_REGEX expressions which effectively exclude directory events, so the limit of one event causes only file events of interest to be reported back. So the limit of 1 works to a fair degree in those scenarios.

Currently the REGEX is used to match against the filename or the leaf directory name.

The java-spring-boot2 stack has a REGEX that match on almost everything, and thus the directory events are not filtered out. The other stacks filter out the directory events for the normal/majority of case(s), because their REGEX requires the name to end with a file extension.

Update:

We believe the one event limit is valid as long as all the events are valid events. Therefore we do not want the controller to do any post processing of events, all matching of events needs to happen in the watcher.

The solution is this:

  1. Create a FilterHook for the watcher that ignores any events related to APPSODY_IGNORE_DIR
  2. Create a FilterHook for the watcher that ignores any directory events.
    The above require folking the watcher repo to add the new Filters.

As part of the work above, we can make two improvements:

  1. Move the setting of the regex expression on the watcher prior to defining the watchers watch directories
  2. Remove the controller post processing step on event.Name for non ignored events, (this was needed for a specific scenario for node based stacks, which moving the REGEX set on tthe watcher eliminates the need for).

error code lost during appsody test

Describe the bug
I'm using the python-flask stack and I changed its test file so it would cause appsody test to fail. When I do this i get the expected error message but the return code is 0.

To Reproduce
Steps to reproduce the behavior:

  1. edit incubator/python-flask/image/project/test/apptests.py and remove the : from line 4: class ServerTestCase(unittest.TestCase)
  2. from incubator/python-flask run appsody stack validate which will do a package and a test and you should see log messages that the test had problems but was still marked as passed
  3. to isolate the issue you can do an appsody init dev-local/python-flask and then appsody test --no-watcher and once it completes do an echo $? which will return a 0
  4. to isolate the issue further you can run the docker command the test runs which is docker run --rm -p 5678:5678 -p 8080:8080 --name python-dev -v /Users/tnixa/appsody/projects101019/python/:/project/userapp -v python-deps:/project/deps -v /Users/tnixa/.appsody/appsody-controller:/appsody/appsody-controller -t --entrypoint /appsody/appsody-controller dev.local/python-flask:SNAPSHOT --mode=test --no-watcher and when this completes do an echo $? which will return a 0
  5. to isolate the issue further you can do and appsody extract and then cd ~/.appsody/extract/<project name> and then run python -m unittest discover -s test -p *.py and then run echo $? which will return 1

Environment Details (please complete the following information):

  • OS: [e.g. iOS] iOS

If applicable please specify:

  • CLI version: 0.4.6
  • Stack you are using: python-flask

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.