-
Notifications
You must be signed in to change notification settings - Fork 30
deployment variable in a (secure) environment variable #349
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
base: master
Are you sure you want to change the base?
Changes from all commits
eda2e82
303d346
b8eb11b
5c9f2d8
65e31de
6b30470
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,8 @@ | |
|
|
||
| on your local machine. This will prompt for your GitHub credentials and the | ||
| name of the repo you want to deploy docs for. This will generate a secure key, | ||
| which you should insert into your .travis.yml. | ||
| which you should insert into your .travis.yml (or set as a secure environment | ||
| variable in your TravisCI repository settings if using the --dkenv option). | ||
|
|
||
| Then, on Travis, for the build where you build your docs, add:: | ||
|
|
||
|
|
@@ -134,6 +135,10 @@ def get_parser(config=None): | |
| if we do not appear to be on Travis.""") | ||
| deploy_parser_add_argument('deploy_directory', type=str, nargs='?', | ||
| help="""Directory to deploy the html documentation to on gh-pages.""") | ||
| deploy_parser_add_argument('--dkenv', type=str, metavar="ENVVAR", | ||
| help="""Push to GitHub using a deployment key stored in the named | ||
| environment variable via your TravisCI repository settings. | ||
| Use this if you used 'doctr configure --dkenv ENVVAR'.""") | ||
| deploy_parser_add_argument('--token', action='store_true', default=False, | ||
| help="""Push to GitHub using a personal access token. Use this if you | ||
| used 'doctr configure --token'.""") | ||
|
|
@@ -193,6 +198,11 @@ def get_parser(config=None): | |
| configure_parser.set_defaults(func=configure) | ||
| configure_parser.add_argument('--force', action='store_true', help="""Run the configure command even | ||
| if we appear to be on Travis.""") | ||
| configure_parser.add_argument('--dkenv', type=str, metavar="ENVVAR", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use the existing environment variable names. If this works we should use it by default and have the old way behind a flag (or just remove it).
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you would be happy making the deploy key in an environment variable the default, then maybe you are right - re-using the old environment variable names would make sense.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming there are no issues with it we should. We will have to continue to support the old way at least for deploy for existing repos. It will need a lot of testing to make sure, once we get it working. |
||
| help="""Generate a deployment key to push to GitHub. The public key | ||
| will be added to your GitHub repository settings. The private key | ||
| should be added to you TravisCI repository settings as a protected | ||
| environment variable.""") | ||
| configure_parser.add_argument('--token', action="store_true", default=False, | ||
| help="""Generate a personal access token to push to GitHub. The default is to use a | ||
| deploy key. WARNING: This will grant read/write access to all the | ||
|
|
@@ -275,6 +285,9 @@ def deploy(args, parser): | |
|
|
||
| config = get_config() | ||
|
|
||
| if args.token and args.dkenv: | ||
| parser.error("The --token and --dkenv settings are incompatible.") | ||
|
|
||
| if args.tmp_dir: | ||
| parser.error("The --tmp-dir flag has been removed (doctr no longer uses a temporary directory when deploying).") | ||
|
|
||
|
|
@@ -310,10 +323,10 @@ def deploy(args, parser): | |
|
|
||
| canpush = setup_GitHub_push(deploy_repo, deploy_branch=deploy_branch, | ||
| auth_type='token' if args.token else 'deploy_key', | ||
| full_key_path=keypath, | ||
| full_key_path=None if args.dkenv else keypath, | ||
| branch_whitelist=branch_whitelist, | ||
| build_tags=args.build_tags, | ||
| env_name=env_name) | ||
| env_name=args.dkenv if args.dkenv else env_name) | ||
|
|
||
| if args.sync: | ||
| built_docs = args.built_docs or find_sphinx_build_dir() | ||
|
|
@@ -383,6 +396,13 @@ def configure(args, parser): | |
| parser.error(red("doctr appears to be running on Travis. Use " | ||
| "doctr configure --force to run anyway.")) | ||
|
|
||
| if args.token and args.dkenv: | ||
| parser.error("The --token and --dkenv settings are incompatible.") | ||
|
|
||
| if len(args.dkenv.split()) != 1: | ||
| # Not going to repeat this sanity test in the deploy command: | ||
| parser.error("The --dkenv setting should be one word only, e.g. DOC_KEY.") | ||
|
|
||
| if not args.authenticate: | ||
| args.upload_key = False | ||
|
|
||
|
|
@@ -484,11 +504,17 @@ def configure(args, parser): | |
| deploy_key_repo, env_name, keypath = get_deploy_key_repo(deploy_repo, args.key_path) | ||
|
|
||
| private_ssh_key, public_ssh_key = generate_ssh_key() | ||
| key = encrypt_to_file(private_ssh_key, keypath + '.enc') | ||
| del private_ssh_key # Prevent accidental use below | ||
| if args.dkenv: | ||
| key = None # don't need it on disk | ||
| encrypted_variable = None # not applicable | ||
| private_ssh_key = private_ssh_key.decode('ASCII') # Will print this later! | ||
| else: | ||
| key = encrypt_to_file(private_ssh_key, keypath + '.enc') | ||
| encrypted_variable = encrypt_variable(env_name.encode('utf-8') + b"=" + key, | ||
| build_repo=build_repo, tld=tld, | ||
| travis_token=travis_token, **login_kwargs) | ||
| private_ssh_key = None # Prevent accidental use below | ||
| public_ssh_key = public_ssh_key.decode('ASCII') | ||
| encrypted_variable = encrypt_variable(env_name.encode('utf-8') + b"=" + key, | ||
| build_repo=build_repo, tld=tld, travis_token=travis_token, **login_kwargs) | ||
|
|
||
| deploy_keys_url = 'https://github.com/{deploy_repo}/settings/keys'.format(deploy_repo=deploy_key_repo) | ||
|
|
||
|
|
@@ -509,16 +535,17 @@ def configure(args, parser): | |
| and add the following as a new key:{RESET} | ||
|
|
||
| {ssh_key} | ||
|
|
||
| {BOLD_MAGENTA}Be sure to allow write access for the key.{RESET} | ||
| """.format(ssh_key=public_ssh_key, deploy_keys_url=deploy_keys_url, N=N, | ||
| BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET))) | ||
|
|
||
| if not args.dkenv: | ||
| print(dedent("""\ | ||
| {N}. {BOLD_MAGENTA}Add the file {keypath}.enc to be staged for commit:{RESET} | ||
|
|
||
| print(dedent("""\ | ||
| {N}. {BOLD_MAGENTA}Add the file {keypath}.enc to be staged for commit:{RESET} | ||
|
|
||
| git add {keypath}.enc | ||
| """.format(keypath=keypath, N=N, BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET))) | ||
| git add {keypath}.enc | ||
| """.format(keypath=keypath, N=N, BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET))) | ||
|
|
||
| options = '--built-docs ' + bold_black('<path/to/built/html/>') | ||
| if args.key_path: | ||
|
|
@@ -531,23 +558,36 @@ def configure(args, parser): | |
| options += ' --token' | ||
| key_type = "personal access token" | ||
|
|
||
| if args.dkenv: | ||
| options += ' --dkenv ' + args.dkenv | ||
| print(dedent("""\ | ||
| {N}. {BOLD_MAGENTA}Add the following private deployment key to your TravisCI | ||
| repository settings as environment variable {env_name}:{RESET} | ||
| """.format(N=N, BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET, | ||
| env_name=args.dkenv, private_ssh_key=private_ssh_key))) | ||
| print(private_ssh_key) | ||
|
|
||
| print(dedent("""\ | ||
| {N}. {BOLD_MAGENTA}Add these lines to your `.travis.yml` file:{RESET} | ||
| """.format(N=N, BOLD_MAGENTA=BOLD_MAGENTA, RESET=RESET))) | ||
|
|
||
| env: | ||
| global: | ||
| # Doctr {key_type} for {deploy_repo} | ||
| - secure: "{encrypted_variable}" | ||
| if not args.dkenv: | ||
| print(dedent("""\ | ||
| env: | ||
| global: | ||
| # Doctr {key_type} for {deploy_repo} | ||
| - secure: "{encrypted_variable}" | ||
| """.format(key_type=key_type, | ||
| encrypted_variable=encrypted_variable.decode('utf-8')))) | ||
|
|
||
| print(dedent("""\ | ||
| script: | ||
| - set -e | ||
| - {BOLD_BLACK}<Command to build your docs>{RESET} | ||
| - pip install doctr | ||
| - doctr deploy {options} {BOLD_BLACK}<target-directory>{RESET} | ||
| """.format(options=options, N=N, key_type=key_type, | ||
| encrypted_variable=encrypted_variable.decode('utf-8'), | ||
| deploy_repo=deploy_repo, BOLD_MAGENTA=BOLD_MAGENTA, | ||
| BOLD_BLACK=BOLD_BLACK, RESET=RESET))) | ||
| """.format(options=options, deploy_repo=deploy_repo, | ||
| BOLD_BLACK=BOLD_BLACK, RESET=RESET))) | ||
|
|
||
| print(dedent("""\ | ||
| Replace the text in {BOLD_BLACK}<angle brackets>{RESET} with the relevant | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to detect this automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, personally I think the interface is much simpler and more flexible if the user picks the environment variable name(s) themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make a flag if the user wants to change it, but there should be a default. It should be possible to just use the variable names we already use, and detect based on the content if it is pointing to a file or if it is a private key. Most users don't really care how doctr works. They just do whatever it says to do and if it pushes their stuff up to gh-pages they are happy.