From 8ea960769f5124c9a10d5966ca4727c0d1c761aa Mon Sep 17 00:00:00 2001 From: howdiz Date: Sat, 30 Mar 2019 00:10:39 +0000 Subject: [PATCH] update example app to run Docker Crest StackScript which accepts a docker file and / or docker comman --- examples/install-on-linode/app.py | 16 +++++++--- examples/install-on-linode/config.py.example | 30 ------------------- .../install-on-linode/templates/base.html | 3 ++ .../templates/configure.html | 12 ++++++++ 4 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 examples/install-on-linode/config.py.example diff --git a/examples/install-on-linode/app.py b/examples/install-on-linode/app.py index 29086f081..203da613d 100644 --- a/examples/install-on-linode/app.py +++ b/examples/install-on-linode/app.py @@ -29,6 +29,7 @@ def start_auth(): session['dc'] = request.form['region'] session['distro'] = request.form['distribution'] session['type'] = request.form['type'] + session['RUNCMD'] = request.form['RUNCMD'] return redirect(login_client.generate_login_url(scopes=OAuthScopes.Linodes.create)) @app.route('/auth_callback') @@ -42,7 +43,8 @@ def auth_callback(): return render_template('error.html', error='Insufficient scopes granted to deploy {}'\ .format(config.application_name)) - (linode, password) = make_instance(token, session['type'], session['dc'], session['distro']) + (linode, password) = make_instance(token, session['type'], session['dc'], + session['distro'], session['RUNCMD']) get_login_client().expire_token(token) return render_template('success.html', @@ -51,12 +53,18 @@ def auth_callback(): application_name=config.application_name ) -def make_instance(token, type_id, region_id, distribution_id): +def make_instance(token, type_id, region_id, distribution_id, runcmd): client = LinodeClient('{}'.format(token)) stackscript = StackScript(client, config.stackscript_id) (linode, password) = client.linode.instance_create(type_id, region_id, group=config.application_name, - image=distribution_id, stackscript=stackscript.id) + image=distribution_id, stackscript=stackscript.id, + stackscript_data = { + "PUBKEY" : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDfP0oZ/G7hNhD0r8e78fDqaQMIsa1kiFckGlWco8RKlv4qoz50EypAW2BTmzvEwq0bVkrLYV9P2wr2F0H2YISuHppth9rxUQ84R3ePae6B6grQK867aCif1x+SDx2mqR7+lDlk0OdzlTxOTVLIISI6n7JOltfvwvWLlA1W2SEJybh/D50+DDzzsDEWpLNWojJmFI3LhBL1T6OiL0flckoxq+56u2K6BHF0wkBNRmBh1iEpGhGSycg26qhg6xBWmvEbpiNmZZDUv+ddbjFC4lMnmT/MvudDqXktgM6XiZhsERXv06ijBtDb8conty8zxsPrXWcFGABThD9l2e6pjpQAZTpseE13gp4ox/IV1SuJDa6THOgRrlaN1QEC6mSbVbuHROJKcDM9oFmAxlj23xA6XKxE878s9vVbvhHNiLJTccfHkdNxgNn1KZho44DBOYwaOgc70o4dvi6j02bLNgsEHNnGyZTQ3JQr062LugULXhGEArjNqCBFc8K953pcKW9r2T+KsayilDBRuV2SkBuDk8Z03fZn03ZCLJ3VqVVJtbbxDAij347932ecUZw5EW6JamPuPKncO/9+ut3EsF1HRy5gZ8ZRRcLB5b05yzhvdlyvjJ9fjnJDVToo4V3fMwQZkHhaEN/QwkWHxxJuUbUMaUZp6k+U6xRK/ZP9jKcIqw== hross@Linodes-MacBook-Pro.local", + "RUNCMD" : runcmd, + "SKIP" : "yes" + } + ) if not linode: raise RuntimeError("it didn't work") @@ -64,4 +72,4 @@ def make_instance(token, type_id, region_id, distribution_id): if __name__ == '__main__': app.debug=True - app.run() + app.run(host='0.0.0.0',port='443',ssl_context='adhoc') diff --git a/examples/install-on-linode/config.py.example b/examples/install-on-linode/config.py.example deleted file mode 100644 index 9bd4ed248..000000000 --- a/examples/install-on-linode/config.py.example +++ /dev/null @@ -1,30 +0,0 @@ -""" -These are all your configuration values. Copy this file to config.py and -substitute these placeholders for your own. config.py is excluded from source -control. - -OAuth Client Details -==================== -These values are obtained by creating a new OAuth Client on -https://cloud.linode.com/profile/clients - see the README included here for -more information. -""" -client_id = 'my-client-id' -client_secret = 'my-client-secret' - -""" -Application Details -=================== -stackscirpt_id - the stackscript to deploy on Linodes we are creating in -this example application. Run ./make_stackscript.py to generate a public -stackscript and put the ID it returns here. - -application_name - displayed to the user of this example application and -used in the new Linode's label. Can be any string. - -secret_key - this flask application's secret key. Not very important since -this is an example application and not for production deployment. -""" -stackscript_id = 320826 -application_name = 'my-application-name' -secret_key = 'my-secret-key' diff --git a/examples/install-on-linode/templates/base.html b/examples/install-on-linode/templates/base.html index e691a62eb..7442beedb 100644 --- a/examples/install-on-linode/templates/base.html +++ b/examples/install-on-linode/templates/base.html @@ -16,6 +16,9 @@ margin: 5px; padding: 5px; } + .long{ + width: 775px; + } .form-group label{ color: #337ab7; } diff --git a/examples/install-on-linode/templates/configure.html b/examples/install-on-linode/templates/configure.html index 92221e607..dde057100 100644 --- a/examples/install-on-linode/templates/configure.html +++ b/examples/install-on-linode/templates/configure.html @@ -37,6 +37,18 @@

Deploy {{application_name}} to a Linode +
+
+ + +
+
+
+
+ + +
+