Deploy Flask Application using python 3.7 - amazon-elastic-beanstalk

I follow this guideline to deploy my python application.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html
I got this bug when use command eb deploy:
2021/09/10 17:26:49.653297 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2021/09/10 17:26:49.653315 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2021/09/10 17:26:49.656613 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2021/09/10 17:26:49.657975 [ERROR] An error occurred during execution of command [app-deploy] - [StageApplication]. Stop running the command. Error: chown /var/app/staging/env/lib/python3.7/collections: no such file or directory
2021/09/10 17:26:49.657984 [INFO] Executing cleanup logic
2021/09/10 17:26:49.658080 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1631294809,"severity":"ERROR"}]}]}
its so annoy because it can not find python 3.7 to run. can anyone give me a hand to by pass this mess?
application.py
# app.py
from flask import Flask
application = Flask(__name__)
#application.route("/")
def hello():
return "Hello World!"
if __name__ == '__main__':
application.run()
requirements.txt
click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1

This happened to me while following the tutorial as well.
The problem, in my case, was that my virtual environment folder venv was getting swept up in the deploy and breaking it.
I thought that I could put the path in .ebignore to prevent this, but I did not read the .ebignore documentation clearly:
If .ebignore isn't present, but .gitignore is, the EB CLI ignores files specified in .gitignore. If .ebignore is present, the EB CLI doesn't read .gitignore.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore
In my case, I just removed the .ebignore file completely, added a line for venv into my .gitignore file, ran eb deploy again and everything worked.

Related

Can not deploy Go in Oracle Cloud Function using Cloud Shell

I tried to Creating and Deploying Oracle Cloud Functions by following the official documentation instructions. I can create and deploy using java runtime but when I deploy go runtime always return error.
I tried to init Go function using this command in Oracle Cloud Shell:
fn init --runtime go hello-go
then I tried to deploy it
fn -v deploy --app test
but it returned error like below:
Deploying hello-go to app: test
Bumped to version 0.0.7
Building image bom.ocir.io/bmptwl2psusa/repo/hello-go:0.0.7
FN_REGISTRY: bom.ocir.io/bmptwl2psusa/repo
Current Context: ap-mumbai-1
Sending build context to Docker daemon 5.632kB
Step 1/10 : FROM fnproject/go:dev as build-stage
---> 96c8fb94a8e1
Step 2/10 : WORKDIR /function
---> Using cache
---> 8961dd299ec1
Step 3/10 : WORKDIR /go/src/func/
---> Using cache
---> 5a4c2c6e13f1
Step 4/10 : ENV GO111MODULE=on
---> Using cache
---> 22022ff2fcf8
Step 5/10 : COPY . .
---> 714622a6ff03
Step 6/10 : RUN cd /go/src/func/ && go build -o func
---> Running in 39fedbc476f4
build func: cannot find module for path github.com/fnproject/fdk-go
The command '/bin/sh -c cd /go/src/func/ && go build -o func' returned a non-zero code: 1
Fn: error running docker build: exit status 1
When I'm using java runtime with fn init --runtime java hello-java command, it's successfully deployed, Why always fail when using go?
I tried to run go build -o func in hello-go directory but it's returned:
go: finding module for package github.com/fnproject/fdk-go
go: writing stat cache: mkdir /usr/share/gocode/pkg: permission denied
go: downloading github.com/fnproject/fdk-go v0.0.3
func.go:10:2: mkdir /usr/share/gocode/pkg: permission denied
I know it happened because /usr/share/gocode/ directory is under root user, but I dont know how to change the permission on that folder because Oracle Cloud Shell can not use root user or sudo. (based on this answer)
Maybe I can do it if I use real VM shell or local shell/terminal, but I want to use Oracle Cloud Shell because I just followed official instructions that suggested me using Oracle Cloud Shell, so how to deploy Oracle Cloud Functions with Go runtime using Oracle Cloud Shell?
Mostly the official documentations only give the examples using Java runtime, that make me paranoid when using go.
This is a bug in cloudshell that we are figuring out the best way to solve.
As a short-term workaround you can do this once:
mkdir ${HOME}/gopath
Then set this in your terminal:
export GOPATH=${HOME}/gopath
You should probably edit your ~/.bashrc to set the GOPATH variable automatically so you don't forget

How to intentionally leave a package half configured?

I'm trying to test Wazuh configuration related to half-configured packages. So, I'm trying to create a .deb package that will end up half configured when installed.
I started by following these instructions for creating a dirt-simple, do-nothing package.
I tried changing the exit code of debian/postinst.ex to 1, but the package installed successfully anyway.
I tried adding a non-existing file to debian/conffiles, but debuild failed.
I've also searched all over for information on the things that can cause a package to be left half configured, without any luck.
Thanks!
First of all, I want to mention that there are two different status for failed installed packages:
half-configured: The package is unpacked and configuration has been started, but not yet completed for some reason.
half-installed: The installation of the package has been started, but not completed for some reason.
Source: https://www.man7.org/linux/man-pages/man1/dpkg.1.html
If you want a half-configured package, then the package must be unpackaged and it is the configuration step the one that should fail.
Now, if you follow the guide you shared with us, you may have missed the part where it says that the *.ex files are examples and are not introduced in the package so if you're modifying the file postinst.ex, these changes will no take effect.
You can remove all the *.ex files and create your own postinst file. For example I've used this one:
root#ubuntu:/tmp/build/greetings-0.1# cat debian/postinst
#!/bin/sh
# postinst script for greetings
#
# see: dh_installdeb(1)
set -e
case "$1" in
configure)
echo "configuring..."
sleep 1
echo "..."
sleep 2
echo "ERROR!"
exit 1
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
Using this file (with the correct name), your code will be executed after the package installation. And you will get something like this:
root#ubuntu:/tmp/build# apt-get install ./greetings_0.1-1_all.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'greetings' instead of './greetings_0.1-1_all.deb'
The following NEW packages will be installed:
greetings
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/2916 B of archives.
After this operation, 14.3 kB of additional disk space will be used.
Get:1 /tmp/build/greetings_0.1-1_all.deb greetings all 0.1-1 [2916 B]
Selecting previously unselected package greetings.
(Reading database ... 76875 files and directories currently installed.)
Preparing to unpack .../build/greetings_0.1-1_all.deb ...
Unpacking greetings (0.1-1) ...
Setting up greetings (0.1-1) ...
configuring...
...
ERROR!
dpkg: error processing package greetings (--configure):
installed greetings package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
greetings
E: Sub-process /usr/bin/dpkg returned an error code (1)
Then, you could use the -s flag on dpkg to check the package status:
root#ubuntu:/tmp/build# dpkg -s greetings
Package: greetings
Status: install ok half-configured
Priority: optional
Section: unknown
Installed-Size: 14
Maintainer: Person McTester <person#company.tld>
Architecture: all
Version: 0.1-1
Description: <insert up to 60 chars description>
<insert long description, indented with spaces>
Homepage: <insert the upstream URL, if relevant>
As you can see, as the package has no way to handle this kind of error, the package is still installed and its status is install ok half-configured
I hope this has helped you :)

Cannot install any ejabberd contrib module

I'm trying to instal ejabberd-contrib modules. Using this guide,
However when I run ejabberdctl modules_update_specs nothing is returned.
And when I try install any of the individual modules:
ejabberdctl module_install mod_pottymouth
Failed RPC connection to the node ejabberd#localhost: {'EXIT',
{undef,
[{bitarray,new,
[16777216,false],
[]},
{etbloom,
'-bloom/3-lc$^0/1-0-',
2,
[{file,
"/var/lib/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/mod_pottymouth/deps/etbloom/src/etbloom.erl"},
{line,77}]},
{etbloom,bloom,3,
[{file,
"/var/lib/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/mod_pottymouth/deps/etbloom/src/etbloom.erl"},
{line,77}]},
{etbloom,sbf,4,
[{file,
"/var/lib/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/mod_pottymouth/deps/etbloom/src/etbloom.erl"},
{line,98}]},
{bloom_gen_server,
init,1,
[{file,
"/var/lib/ejabberd/.ejabberd-modules/sources/ejabberd-contrib/mod_pottymouth/src/bloom_gen_server.erl"},
{line,28}]},
{gen_server,init_it,
2,
[{file,
"gen_server.erl"},
{line,374}]},
{gen_server,init_it,
6,
[{file,
"gen_server.erl"},
{line,342}]},
{proc_lib,
init_p_do_apply,3,
[{file,
"proc_lib.erl"},
{line,249}]}]}}
Commands to start an ejabberd node:
start Start an ejabberd node in server mode
debug Attach an interactive Erlang shell to a running ejabberd node
iexdebug Attach an interactive Elixir shell to a running ejabberd node
live Start an ejabberd node in live (interactive) mode
iexlive Start an ejabberd node in live (interactive) mode, within an Elixir shell
foreground Start an ejabberd node in server mode (attached)
ejabberdctl status
The node ejabberd#localhost is started with status: started
How can I fix this?
However when I run ejabberdctl modules_update_specs nothing is returned.
Then it probably worked correctly, otherwise it would have returned some error, and echo would return 1. Example that it worked correctly and created the path:
$ ejabberdctl modules_update_specs
$ echo $?
0
$ ls $HOME/.ejabberd-modules/
sources
And when I try install any of the individual modules:
Installing ANY module produces an error? For example, if you try installing mod_rest, does it work? Notice this reports a warning about documentation, which is not important:
$ ejabberdctl module_install mod_rest
/home/badlop/.ejabberd-modules/sources/ejabberd-contrib/mod_rest/src/mod_rest.erl:27: Warning: undefined callback function mod_doc/0 (behaviour 'gen_mod')
$ ls $HOME/.ejabberd-modules/
mod_rest sources
{'EXIT', {undef, [{bitarray,new,
Yes, this is a known problem when installing mod_pottymouth. The workaround for installing that module is described in the README.txt file of that module. I've followed those instructions now, and the module compiled and installed correctly.

How to debug the cartridge scripts in Openshift?

I want to develop a new cartridge for my own use. I use OpenShift Cartridge Development Kit to start my work. My building script is written in .openshift/action_hooks/build and it can be successfully executed.
But when I tried to use the command displayed on the homepage of the CDK project - "rhc create-app mynewcart http://##YOUR-DOMAIN##/manifest/##YOUR-COMMIT-ID##" - to create an app, I got the following error: "Unable to complete the requested operation due to: An invalid exit code (1) was returned from the server ex-std-node161.prod.rhcloud.com. This indicates an unexpected problem during the
execution of your request."
How can I trace the progress of deploying and find out where is the code that caused the problem? Is there any log file available for me to analyse?
Use the --debug option when running the command and you'll get much more detailed output:
rhc create-app mynewcart http://##YOUR-DOMAIN##/manifest/##YOUR-COMMIT-ID## --debug

How do I configure CI hudson with PHPunit and how do I run phpunit using hudson?

I am getting following error mentioned below. Help is much needed for this...
kindly go through the errors.
Started by an SCM change
Updating https://suppliesguys.unfuddle.com/svn/suppliesguys_frontend2/Frontend-Texity/src
U sites\all\modules\print\print_pdf\print_pdf.pages.inc
At revision 1134
[workspace] $ sh -xe C:\WINDOWS\TEMP\hudson6292587174545072503.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh" (in directory "E:\Projects\Hudson\.hudson\jobs\TSG\workspace"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:149)
at hudson.Proc$LocalProc.<init>(Proc.java:121)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:636)
at hudson.Launcher$ProcStarter.start(Launcher.java:271)
at hudson.Launcher$ProcStarter.join(Launcher.java:278)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:83)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:584)
at hudson.model.Build$RunnerImpl.build(Build.java:174)
at hudson.model.Build$RunnerImpl.doRun(Build.java:138)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:416)
at hudson.model.Run.run(Run.java:1244)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:122)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 17 more
Publishing Javadoc
Publishing Clover coverage report...
No Clover report will be published due to a Build Failure
[xUnit] Starting to record.
[xUnit] [PHPUnit] - Use the embedded style sheet.
[xUnit] [ERROR] - No test report file(s) were found with the pattern 'build/logs/phpunit.xml' relative to 'E:\Projects\Hudson\.hudson\jobs\TSG\workspace' for the testing framework 'PHPUnit'. Did you enter a pattern relative to the correct directory? Did you generate the result report(s) for 'PHPUnit'?
[xUnit] Stopping recording.
Finished: FAILURE
It looks like you are using the "Execute shell" build step on a windows system instead of the "Execute Windows batch command" build step. Windows doesn't normally have 'sh', so the former won't work.
Looks like you have a couple of problems:
FATAL: command execution failed java.io.IOException: Cannot run program "sh" (in directory "E:\Projects\Hudson.hudson\jobs\TSG\workspace"):
The user that's running the Hudson job doesn't have the "sh" command in its path, so it can't run shell scripts. Adding /bin to the $PATH of the Hudson user should fix this.
[xUnit] [ERROR] - No test report file(s) were found with the pattern 'build/logs/phpunit.xml' relative to 'E:\Projects\Hudson.hudson\jobs\TSG\workspace' for the testing framework 'PHPUnit'.
This is probably a result of the previous error; the build just didn't get far enough to run the PHPUnit tests.
'sh' is for linux implementations. Both '.exe' and 'bat' files are used in windows. Are you trying to setup and run Hudson on windows or linux?