GithubHelp home page GithubHelp logo

dgtlmoon / lemonade-fresh Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 2.0 1.75 MB

Lemonade Fresh - Cryptocurrency Paid Container Provisioner

Dockerfile 2.75% Python 61.01% Shell 0.76% CSS 11.58% Jinja 1.17% HTML 22.73%
docker crypto bitcoin docker-compose containers web cryptocurrency python self-hosted

lemonade-fresh's Introduction

Lemonade Fresh - Cryptocurrency Paid Container Provisioner

An extremely simple platform which enables you to host a docker container in exchange for digital currency (bitcoin/litecoin/dogecoin)

In otherwords - provision a container using docker-compose when someone pays you with cryptocurrency - host that container for them, accessible as a URL path on your server (that URL path is automatically generated from two random words)

Yes I'm sure there's a better way todo this, but this works for me :), and it was the fastest way I could get some proof of concept working

How does it work?

  • A person who is interested registers via a simple flask application, the application creates a cryptocurrency payment address, this is emailed and presented to them.
  • When a correct payment is detected, a data/docker-compose-paid-instances.yml is re-generated with the paid container information (and a container name which is also the container hostname), managed by a simple SQLite DB
  • docker-compose up runs periodically, it knows when a YAML has changed thanks to its internal checksums, so lazy so implementation..
  • The new paid container is running, and has a randomly generated hostname, this hostname is available as http://yoursite/random-name via proxy_pass

Then the new 'customer' simply accesses their hosted container via nginx's proxy_pass as a path on your server, it's recommended to run the containers as a sub-domain, otherwise the nginx rules get a bit complicated ie, https://pay-me.mydomain.io/ , so the hosted container would be available as https://pay-me.mydomain.io/random-name

Some extra bonus stuff happens like

Syncing new containers when paid

# m h  dom mon dow   command
*/2 * * * * curl -s https://your-site.com/sync >/dev/null && cd /var/www/provisioner && docker-compose --log-level=WARNING -f docker-compose.yml -f docker-compose.prod.yml -f data/docker-compose-paid-instances.yml  up -d --remove-orphans

There's some very lazy things going on here

  • Runs every 2 minutes
  • docker-compose.yml the stock one, required
  • docker-compose.prod.yml your local settings, like setting the crypto network (bitcoin/testnet/litecoin etc) and return coin address
  • data/docker-compose-paid-instances.yml the generated extra docker-compose YAML for paid instances

The lazy magic here, is that docker-compose wont do anything unless one of the YAML's change, up supports --remove-orphans so it's easy to remove containers that are not paid for, and --log-level=WARNING keeps it quiet unless something bad happens.

The only shameful thing is that /sync call, which re-builds the composer and checks for payments, your nginx shouldnt allow this to be accessed other than locally (or change the code and move it to a local command)

Probably nearly all of this can be removed by using an actual decent interface like coinbase's API, which handles payments way better, but, where is the fun in that? :)

So basically, when someone has paid for their container, a random name is generated (stir-commuted herein), and data/docker-compose-paid-instances.yml will contain for example...

  paid_instance_stir-commuted:
    image: dgtlmoon/changedetection.io:latest
    networks:
    - provisioner_net
    environment:
    - USE_X_SETTINGS=1
    - SALTED_PASS=abc123
    hostname: stir-commuted
    volumes:
    - paid_instance_stir-commuted-data:/datastore
    restart: unless-stopped

And they can access it via https://yoursite.com/stir-commuted via this nginx location statement

image: is set by HOSTED_IMAGE env var

Once it is paid, the server will send the coin balance onto an another address, which should NOT be on the server

Testing/Development

  • I like the Electrum client, start it in testnet mode, electrum --testnet
  • Use https://testnet-faucet.com/btc-testnet/ or a similar "test coin faucet" to get some test-coins (remember to return them when you're done!)
  • It's good to set the return address for the coins back to your wallet (dont store them on the server! See BTC_FORWARD_ADDRESS env var)

Batteries NOT included

  • Some web-ops stuff like certbot not included, you will need to sort out how this works.
  • No threaded python gunicorn etc server

Going forwards

  • You could use a wildcard DNS entry, tweak the nginx rules, and bounce the requests to a random-name.yoursite.com instead of a path suffix, then you dont have to worry about mapping paths etc and they could enjoy full socket IO access aswell

lemonade-fresh's People

Contributors

dgtlmoon avatar

Stargazers

 avatar Cioclea Doru Octavian avatar DeveloperN avatar bernsteining avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

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.