Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable passing config via environment variables #2

Merged
merged 1 commit into from Jan 11, 2018

Conversation

knaperek
Copy link
Contributor

This simplifies deployment in various environments and it is generally
considered the best practice.

This simplifies deployment in various environments and it is generally
considered the best practice.
@knaperek
Copy link
Contributor Author

Hi @oxarbitrage, can I help you in any way to push this through faster? I'd like to continue improving the codebase and fixing bugs, and don't want create many PRs at the same time - that would only make merging harder. Also, when this is merged it'll be easier to reproduce any bugs reported subsequently. Thanks.

@oxarbitrage
Copy link
Member

yes, thanks for what you do, i am having some problems with my internet this week and that is having me behind. i only have available a very slow connection at the moment. i am also taking some vacations starting tomorrow and ill be back monday 22th.

your contributions all look good so i am going to merge them now but keep the current version running to the explorer because i don't want any issue while traveling that i may not be able to fix.

let me ask you something so when i came back i can upgrade the service to the last version with your additions.

i run the api service as follows:

uwsgi --ini api.ini

in a screen session of a server. what are the steps i am going to need to take in order to start the service with the environment variables. populate them before executing that command or something else ? i should maybe do it with the docker ?

how the files that are under cron will have the environment variables, if i have them added to the user for running the service then cron will have them available ?

thank you very much for your work.

@oxarbitrage oxarbitrage merged commit 45795c0 into bitshares:master Jan 11, 2018
oxarbitrage added a commit that referenced this pull request Jan 11, 2018
[Waiting #2] Dockerize the API service including background tasks
@knaperek
Copy link
Contributor Author

Thanks for fast response.

The new feature for passing configuration through environment variables is made backwards-compatible, so if you used the values as defined in the code, you'll be just fine even after this is merged and don't have to do any further changes.

If, however, you maintain a different version of the repo for production where you have those connection parameters overridden (changed to different values), then you'll have to put these values into environment variables and make them available to the process. There are multiple ways to do it, the simplest one is just to define them on the shell line, e.g.:

WEBSOCKET_URL=ws://some.other.host.com:8090/ws POSTGRES_HOST=dbhost.com POSTGRES_USER=foobar POSTGRES_PASSWORD=barbaz uwsgi --ini api.ini

Likewise you'll have to change the crontab entries (put the env variables before the command).

There are other ways to make your env variables automatically available to your processes but those depend on your OS. For example, in Ubunut you can add them all to /etc/environment. You can also define it in your shell init script (e.g. .bashrc) but be careful because this may not be automatically loaded when running the commands from CRON.

For now you can keep using your existing api.ini config for uWSGI, it will still work. Eventually when you're ready, I'd suggest you install Docker Engine CE on your production server and deploy it with Docker. I'll be happy to give you a hand with that, just pop me a message.

I suppose you're using nginx as a front server on production right now, is that right? So far I configured the Docker Compose to use uWSGI only (in HTTP mode), but I can integrate nginx as well if you want. Or, alternatively, you can keep your nginx outside of Docker and just set it to reverse-proxy all connections back to Docker-powered uWSGI process. We can discuss this later if you're interested.

@oxarbitrage
Copy link
Member

thank you for that, i use the exact same values for production so ill give it a try as i see they are in the code by default so i will be fine. ill check into the docker when i came back.

in regards to nginx, yes i use it in production, the configuration file is as follows:

root@alfredo:/etc/nginx/sites-available# cat myapp 
server {
    listen 5000;
    server_name 23.94.69.140;
    location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/api.sock;
    }
}
root@alfredo:/etc/nginx/sites-available# 

mainly use it because the service was not able to handle the high traffic without it, i am pretty new to nginx and uwsgi itself so there are some things i am not totally sure of but with that configuration the services almost don't ever crash anymore.

I used the same for other wrappers that you maybe already saw:
https://github.com/oxarbitrage/bitshares-es-wrapper
https://github.com/oxarbitrage/udf-bitshares-wrapper

They are all working fine with a similar configuration of wsgi and nginx.

Your contributions are helping to put this services into the bitshares organization repos, thats is the goal, if we can do that i can also get funding for your contributions, not my decision alone but definitely can happen. anyways, we might discuss that if you are interested in telegram or by email.

thanks again.

@knaperek
Copy link
Contributor Author

I'll send you a PM on Bitshares Talk, we can set up a communication channel then.

@knaperek knaperek deleted the config-through-env-vars branch January 25, 2018 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants