I have a project. Although it is the same website, the front and back ends are divided into 2 repo(s), which are made by React and Ruby on Rails respectively. Therefore, every time I want to start a website locally, I must open 2 Ubuntu terminal windows.
I heard that foreman can start both at once. Are there any examples to learn from? Thanks!
You could just add foreman gem to you Gemfile and create Procfile.dev file in your root directory.
Inside of it, you add all of the processes you want to launch. So, it could be something like this:
backend: bin/rails server -p 3000
frontend: npm start
Obviously, you can use whatever you use to start your frontend application.
And then you run foreman start -f Procfile.dev in your terminal.
Related
this is my first deployment, I have gone so far as to create and configure Ubuntu instance on lightsails following official guide. However, I run into problems when instead of an empty project I use my own Django hosting React frontend.
My project works on my computer and if I start up django's production server thorugh manage.py runserver but does not run at all if I use gunicorn to run it with:
gunicorn my_app.wsgi --bind 0.0.0.0:8000 --workers 4
It seems that it cannot find proper filepaths of any static files but I do not undertstand how to configure it to use it since Django already has all the right paths.
One of the errors in the browser console:
Refused to execute http://3.127.76.103/static/rest_framework/js/bootstrap.min.js as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type.
How can I start fixing it, I do not understand why it does not see the any files.
Serve is a library that allows you to serve your React build folder similar to npm start
Create an app with npx create-react-app .
Then run the following the following to create build and serve the app
npm run build
npm install -g serve
serve -s build
It works perfectly, only how does one kill the listening on port 5000
control c brings back the suspended terminal prompt and lsof -iTCP -sTCP:LISTEN -n -P indicates that it is no longer listening on port 5000.
pkill -9 node does not do it.
Even though it appears not to be listening on port 5000 I can go to localhost:5000 and it serves up the file as though it were listening on 5000;
NOTE: this happened on MacOS
The reason you're still seeing content even after the server is killed is because you're using a Service Worker. Service Workers will cache content so that even when a user is offline, they can continue to use your web app. What you're experiencing is the intended functionality.
You can make your life a little easier by using Incognito Mode when working with service workers, so you can easily reset your browser and thereby clear any active service workers.
I'd recommend you read more of the Workbox documentation as I can see you're working with that framework.
Another way to stop a service worker is through the Chrome Dev tools panel.
I would like to install, configure, deploy and serve a local react application using Ansible but i cannot get any valuable information to do it.
Is there anybody who can guide me on how to achieve this?
Thanks in advance.
First off, ansible has a REALLY extensive wiki here. That will show you the many modules that can be used to do specific tasks. However, this is not where I would start for writing your first playbook, it gets rather daunting.
However, I started and would recommend you start on this tutorial on how to make your first playbook. you would make a yaml file and run it using the 'ansible-playbook' command on a host that has ssh enabled, ansible installed, and a key pair setup (easily done with ssh-copy-id user#hostname). If you need a way to quickly provision these machines, I personally use Hashicorp's Vagrant to quickly make simple Virtual Machines, however it is possible to use Docker or something else.
As for the specifics for installing specific applications using apt; use the apt module in ansible should serve you right. If you need to install NPM or something of the sort, chances are there's a module for that too. As for copying configs you would want the copy module. Things are pretty straight forward. a good way to structure the google searches to find specific modules would be something like "ansible copy files" and find something from docs.ansible
I realize that this is rather vague; however, I'm not completely sure on your use case in this scenario simply because of the broadness of the question.
Thanks a lot for your input, it was very helpful.
I finally achieved what i was looking for, and for reference here's how i made it. Hope this is useful for other users.
Assuming you have already installed Ansible in your machine, the following should do the job.
vim inventory
[appserver]
127.0.0.1 ansible_connection=local
vim playbook.yml
---
- hosts: appserver
tasks:
- name: Installing nodejs
apt: name=nodejs update_cache=yes
- name: Installing npm
apt: name=npm update_cache=yes
- name: Installing dependencies
command: npm install
- name: Building
command: npm run build
- name: Installing web server
command: npm install serve
- name: Running app on http://localhost:8080
command: chdir=./build serve -p 8080
To run it, just place the following in your CLI
sudo ansible-playbook -i inventory playbook.yml
The dronekit Getting Started page suggests installing WinPython to use dronekit-Python on Windows because it includes the dependencies. I already have a working Python installation and I prefer not to risk messing it up with WinPython. What are the dependencies I need to install?
As of DKPY 2.0 this is outdated. Also, I might move to making a MavProxy module depending on whether or not the unpaid devs decide to stay when 3DR stops funding Dronekit
I've written a procedure to help with this problem which I've pasted. 3DR claims they're going to fix it, but in the mean time I hope this will help.
This setup is for Windows 64-bit systems only, although similar procedures will work with 32-bit.
Install MAVProxy and run it once before reaching step 5.
Install Notepad++.
Install Python v2.7.
Inside the Python folder, run WinPython Control Panel and select Advanced->Register Python.
Inside the same folder, run WinPython Command Prompt and input the following four commands:
• pip uninstall python-dateutil
• pip install droneapi
• pip install console
• echo module load droneapi.module.api >> %HOMEPATH%\AppData\Local\MAVProxy\mavinit.scr
Install WX Python. It should be the 64-bit Python 2.7 version.
Download and install OpenCV 2.4.11 to any folder
• Copy/paste the file cv2.pyd from OpenCV\build\python\2.7\x64\ to \python-2.7.6.amd64\Lib\site-packages.
Steps 8 through 11 apply to SITL only
Follow the online documentation for setting up Cygwin for SITL in Windows
Go to C:\cygwin\home\Your Username\ardupilot\Tools\autotest\
Open sim_vehicle.sh in Notepad++
• Change line 429 from…
cygstart -w "/cygdrive/c/Program Files (x86)/MAVProxy/mavproxy.exe" $options --cmd="$extra_cmd" $*
to...
cygstart -w "/cygdrive/c/Users/YOUR USERNAME HERE/Desktop/WinPython-64bit-2.7.6.4/python-2.7.6.amd64/Dronekit/Scripts/mavproxy.py" $options --cmd="$extra_cmd" $*
Note: This location changes depending on where you installed WinPython. For me, it was the desktop.
Start simulations as you would normally for SITL. To run Python scripts during the simulations, use the command
• api start Path to script\script_name
To use the code to connect to an actual copter, open WinPython Command Prompt
• Navigate to the folder which contains the scripts you wish to test
• Type mavproxy.py --master=”com##”,57600
• Run your script by typing into the MAVProxy terminal
o api start script_name
I've set up an App Engine project locally using Docker (on OSX), and have been running a server using the usual "gcloud preview app run app.yaml" command. From what I can tell, this keeps creating new images over and over again. After an hour or so of work I end up with something like 30 docker images, each taking 130MB.
Eventually I'm told I can no longer bind to localhost:8080. I tried killing all containers and images, but still cannot use localhost:8080 until I reboot.
Seems like I'm not using Docker/gcloud correctly. Anyone have an idea what I might be doing wrong? Is there another way I should be restarting App Engine instances other than hitting command C and running the "run" command again?
UPDATE: After looking closer, I noticed I'm getting this message when I run an app locally and a container is created: "http: Hijack is incompatible with use of CloseNotifier". I'm not familiar enough with Docker to understand what's going on here. All searches seem to point to Go, which I am not using.
UPDATE 2: Here is the trace:
Creating container...
INFO 2015-05-05 02:23:28,293 containers.py:560] Container 1564ce4344957114312d6d1dc696ffbb4176b40ace6dcff5e4239e13ee04a8f6 created.
Exception in thread Thread-2:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/judeosborn/google-cloud-sdk/platform/google_appengine/google/appengine/tools/docker/containers.py", line 643, in _ListenToLogs
for line in log_lines:
File "/Users/judeosborn/google-cloud-sdk/./lib/docker/docker/client.py", line 225, in _multiplexed_response_stream_helper
socket = self._get_raw_response_socket(response)
File "/Users/judeosborn/google-cloud-sdk/./lib/docker/docker/client.py", line 167, in _get_raw_response_socket
self._raise_for_status(response)
File "/Users/judeosborn/google-cloud-sdk/./lib/docker/docker/client.py", line 119, in _raise_for_status
raise errors.APIError(e, response, explanation=explanation)
APIError: 500 Server Error: Internal Server Error ("http: Hijack is incompatible with use of CloseNotifier")
INFO 2015-05-05 02:23:28,606 module.py:1745] New instance for module "default" serving on:
http://localhost:8080
There's an ongoing issue with Docker 1.6.x [reference] that prevents gcloud to work well with Managed VMs (as you seem to be using). Easiest workaround until it gets fixed is to downgrade Docker in your development machine to version 1.5.0, which is the latest version known to work.
For Ubuntu, you can do something like:
$ curl -sSL https://get.docker.com/ubuntu | sed 's/lxc-docker/lxc-docker-1.5.0/' | sudo sh
For other Linux distros, you might have to modify that sed pattern, though.
On the other hand, if you're using Boot2Docker under Mac OS X, follow these steps:
Fully uninstall your previous Boot2Docker/Docker setup; there is a nice guide here
Reinstall Boot2Docker/Docker following instructions here. IMPORTANT: You MUST stop right after completing "Install Boot2Docker" step and before "Start the Boot2Docker Application". Once you get there, open up a terminal and execute the following commands:
$ mkdir ~/.boot2docker
$ echo 'ISOURL="https://github.com/boot2docker/boot2docker/releases/download/v1.5.0/boot2docker.iso"' > ~/.boot2docker/profile
At this point, you can continue with "Start the Boot2Docker Application" section and finish the installation. You should now have a valid Docker launchpad with which to start Managed VMs. It'd be nice to double check that you have the right versions installed by issuing:
$ boot2docker ssh docker version | egrep "(Client|Server) version"
The output should look like:
Client version: 1.5.0
Server version: 1.5.0
Now you can try again your original command:
$ gcloud preview app run app.yaml
Try running:
$ ps uax | egrep "gcloud|appserver"
If you see anything running, kill it... you may even need to kill -9 it.