Skip to content

Instantly share code, notes, and snippets.

@smashwilson
Last active September 23, 2015 13:35
Show Gist options
  • Save smashwilson/cc1303e55f1d44c6fe75 to your computer and use it in GitHub Desktop.
Save smashwilson/cc1303e55f1d44c6fe75 to your computer and use it in GitHub Desktop.
Manually publish Sphinx repositories to staging.developer.rackspace.com or developer.rackspace.com
#!/bin/bash
set -euo pipefail
help() {
cat <<EOM >&2
Usage: ${0} [-e staging] [-k APIKEY] [-p .]
-e env Choose the environment to submit to. Either "production" or "staging". Default: staging.
-k APIKEY Use the specified API key. Default: \${CONTENT_STORE_APIKEY}.
-p . Path containing content to submit. This should be the directory that contains your
"conf.py" file. Default: working directory.
-h Display this message.
EOM
}
CONTENT_STORE_URL=${CONTENT_STORE_URL:-http://staging.developer.rackspace.com:8000/}
CONTENT_STORE_APIKEY=${CONTENT_STORE_APIKEY:-}
CONTENT_PATH=.
# getopts
while getopts "e:p:k:h" OPT; do
case ${OPT} in
e)
case ${OPTARG} in
production)
CONTENT_STORE_URL=https://developer.rackspace.com:9000/
;;
staging)
CONTENT_STORE_URL=http://staging.developer.rackspace.com:8000/
;;
*)
echo -e "${OPTARG} must be either \"production\" or \"staging\".\n" >&2
help
;;
esac
;;
k)
CONTENT_STORE_APIKEY=${OPTARG}
;;
p)
CONTENT_PATH=${OPTARG}
;;
h)
help
exit 0
;;
\?)
echo -e "Invalid option: ${OPTARG:-}\n" >&2
help
exit 1
;;
:)
echo -e "Option ${OPTARG} requires and argument.\n" >&2
help
exit 1
;;
esac
done
# prerequisite test
[ -z "${CONTENT_STORE_APIKEY}" ] && {
echo -e "No API key.\n" >&2
echo "Please specify one with -k or set CONTENT_STORE_APIKEY." >&2
exit 1
}
docker version >/dev/null 2>&1 || {
echo -e "Unable to talk to the Docker daemon.\n" >&2
echo "Make sure that you can run Docker commands, like:" >&2
echo >&2
echo " docker version" >&2
exit 1
}
[ -f "${CONTENT_PATH}/conf.py" ] || {
echo -e "No conf.py found.\n" >&2
echo "Please specify the path to your conf.py file." >&2
exit 1
}
# Preparer run
CONTENT_PATH=$(cd ${CONTENT_PATH} && pwd)
exec docker run \
--rm --interactive --tty \
-e CONTENT_STORE_URL=${CONTENT_STORE_URL} \
-e CONTENT_STORE_APIKEY=${CONTENT_STORE_APIKEY} \
-e TRAVIS_PULL_REQUEST="false" \
-v "${CONTENT_PATH}:/usr/content-repo" \
quay.io/deconst/preparer-sphinx
@smashwilson
Copy link
Author

To install:

curl https://gist.githubusercontent.com/smashwilson/cc1303e55f1d44c6fe75/raw/0ac301d34e04c4a7a47410ae746b58b2fed2e467/deconst-publish > ./deconst-publish && chmod +x ./deconst-publish

To use:

export CONTENT_STORE_APIKEY=".." # A key I give you

# Provide the path to the directory containing "conf.py"
./deconst-publish -p /path/to/sphinx/content/

See ./deconst-publish -h for more options.

@meker12
Copy link

meker12 commented Sep 22, 2015

When I run this, I get a connection refused. Am I entering the command correctly? I wasn't sure of the syntax for the API KEY

________________________________________________________________________________
| ~/Documents/githubDocs @ MKXKG1DTY3 (marg7175)
| => ./deconst-publish -e staging -k $CONTENT_STORE_APIKEY -p docs-cloud-images/rst/dev-guide/
Running Sphinx v1.3.1
building [mo]: all of 0 po files
building [deconst-single]: all source files
updating environment: 20 added, 0 changed, 0 removed
reading sources... [100%] overview/pricing-service-level
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
assembling single document... overview/index overview/additional-resources overview/pricing-service-level developer-guide concepts general-api-info/index general-api-info/request-response general-api-info/how-curl-commands-work general-api-info/authenticate general-api-info/role-based-access-control general-api-info/service-access-endpoints api-reference api-operations/index api-operations/images-operations api-operations/image-sharing-operations api-operations/image-tag-operations api-operations/image-task-operations api-operations/image-schema-operations glossary Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.4/http/client.py", line 1088, in request
    self._send_request(method, url, body, headers)
  File "/usr/local/lib/python3.4/http/client.py", line 1126, in _send_request
    self.endheaders(body)
  File "/usr/local/lib/python3.4/http/client.py", line 1084, in endheaders
    self._send_output(message_body)
  File "/usr/local/lib/python3.4/http/client.py", line 922, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.4/http/client.py", line 857, in send
    self.connect()
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 155, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 134, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 88, in create_connection
    raise err
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 78, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 597, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/retry.py", line 245, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/packages/six.py", line 309, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.4/http/client.py", line 1088, in request
    self._send_request(method, url, body, headers)
  File "/usr/local/lib/python3.4/http/client.py", line 1126, in _send_request
    self.endheaders(body)
  File "/usr/local/lib/python3.4/http/client.py", line 1084, in endheaders
    self._send_output(message_body)
  File "/usr/local/lib/python3.4/http/client.py", line 922, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.4/http/client.py", line 857, in send
    self.connect()
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 155, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 134, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 88, in create_connection
    raise err
  File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 78, in create_connection
    sock.connect(sa)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/deconst-preparer-sphinx", line 9, in <module>
    load_entry_point('deconstrst==0.1.0', 'console_scripts', 'deconst-preparer-sphinx')()
  File "/usr/local/lib/python3.4/site-packages/deconstrst/__init__.py", line 29, in main
    status = build(srcdir, destdir)
  File "/usr/local/lib/python3.4/site-packages/deconstrst/deconstrst.py", line 33, in build
    app.build(True, [])
  File "/usr/local/lib/python3.4/site-packages/sphinx/application.py", line 258, in build
    self.builder.build_all()
  File "/usr/local/lib/python3.4/site-packages/sphinx/builders/__init__.py", line 205, in build_all
    self.build(None, summary='all source files', method='all')
  File "/usr/local/lib/python3.4/site-packages/sphinx/builders/__init__.py", line 316, in build
    self.write(docnames, list(updated_docnames), method)
  File "/usr/local/lib/python3.4/site-packages/deconstrst/builders/single.py", line 79, in write
    self.post_process_images(doctree)
  File "/usr/local/lib/python3.4/site-packages/deconstrst/builders/single.py", line 121, in post_process_images
    node['uri'] = self._publish_entry(node['uri'])
  File "/usr/local/lib/python3.4/site-packages/deconstrst/builders/single.py", line 139, in _publish_entry
    response = requests.post(url, files=files, headers=headers)
  File "/usr/local/lib/python3.4/site-packages/requests/api.py", line 99, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/requests/api.py", line 49, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/requests/sessions.py", line 461, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.4/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/requests/adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))

Here's my docker-machine listing:

| => docker-machine ls
NAME             ACTIVE   DRIVER       STATE     URL                         SWARM
deconst-client   *        virtualbox   Running   tcp://192.168.99.100:2376
default                   virtualbox   Stopped
workshop                  virtualbox   Stopped

@meker12
Copy link

meker12 commented Sep 23, 2015

Ran off of VPN, and still not working.
(docs_prototype)________________________________________________________________________________
| ~/Documents/githubDocs @ MKXKG1DTY3 (marg7175)
| => ./deconst-publish -e staging -k $CONTENT_STORE_APIKEY -p docs-cloud-images/rst/dev-guide/
Running Sphinx v1.3.1
building [mo]: all of 0 po files
building [deconst-single]: all source files
updating environment: 20 added, 0 changed, 0 removed
reading sources... [100%] overview/pricing-service-level
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
assembling single document... overview/index overview/additional-resources overview/pricing-service-level developer-guide concepts general-api-info/index general-api-info/request-response general-api-info/how-curl-commands-work general-api-info/authenticate general-api-info/role-based-access-control general-api-info/service-access-endpoints api-reference api-operations/index api-operations/images-operations api-operations/image-sharing-operations api-operations/image-tag-operations api-operations/image-task-operations api-operations/image-schema-operations glossary Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
conn.request(method, url, *_httplib_request_kw)
File "/usr/local/lib/python3.4/http/client.py", line 1088, in request
self._send_request(method, url, body, headers)
File "/usr/local/lib/python3.4/http/client.py", line 1126, in _send_request
self.endheaders(body)
File "/usr/local/lib/python3.4/http/client.py", line 1084, in endheaders
self._send_output(message_body)
File "/usr/local/lib/python3.4/http/client.py", line 922, in _send_output
self.send(msg)
File "/usr/local/lib/python3.4/http/client.py", line 857, in send
self.connect()
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 155, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 134, in _new_conn
(self.host, self.port), self.timeout, *_extra_kw)
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 64, in create_connection
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
File "/usr/local/lib/python3.4/socket.py", line 533, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/requests/adapters.py", line 370, in send
timeout=timeout
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 597, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/retry.py", line 245, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/packages/six.py", line 309, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
conn.request(method, url, *_httplib_request_kw)
File "/usr/local/lib/python3.4/http/client.py", line 1088, in request
self._send_request(method, url, body, headers)
File "/usr/local/lib/python3.4/http/client.py", line 1126, in _send_request
self.endheaders(body)
File "/usr/local/lib/python3.4/http/client.py", line 1084, in endheaders
self._send_output(message_body)
File "/usr/local/lib/python3.4/http/client.py", line 922, in _send_output
self.send(msg)
File "/usr/local/lib/python3.4/http/client.py", line 857, in send
self.connect()
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 155, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 134, in _new_conn
(self.host, self.port), self.timeout, *_extra_kw)
File "/usr/local/lib/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 64, in create_connection
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
File "/usr/local/lib/python3.4/socket.py", line 533, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/deconst-preparer-sphinx", line 9, in
load_entry_point('deconstrst==0.1.0', 'console_scripts', 'deconst-preparer-sphinx')()
File "/usr/local/lib/python3.4/site-packages/deconstrst/init.py", line 29, in main
status = build(srcdir, destdir)
File "/usr/local/lib/python3.4/site-packages/deconstrst/deconstrst.py", line 33, in build
app.build(True, [])
File "/usr/local/lib/python3.4/site-packages/sphinx/application.py", line 258, in build
self.builder.build_all()
File "/usr/local/lib/python3.4/site-packages/sphinx/builders/init.py", line 205, in build_all
self.build(None, summary='all source files', method='all')
File "/usr/local/lib/python3.4/site-packages/sphinx/builders/init.py", line 316, in build
self.write(docnames, list(updated_docnames), method)
File "/usr/local/lib/python3.4/site-packages/deconstrst/builders/single.py", line 79, in write
self.post_process_images(doctree)
File "/usr/local/lib/python3.4/site-packages/deconstrst/builders/single.py", line 121, in post_process_images
node['uri'] = self._publish_entry(node['uri'])
File "/usr/local/lib/python3.4/site-packages/deconstrst/builders/single.py", line 139, in _publish_entry
response = requests.post(url, files=files, headers=headers)
File "/usr/local/lib/python3.4/site-packages/requests/api.py", line 99, in post
return request('post', url, data=data, json=json, *_kwargs)
File "/usr/local/lib/python3.4/site-packages/requests/api.py", line 49, in request
response = session.request(method=method, url=url, *_kwargs)
File "/usr/local/lib/python3.4/site-packages/requests/sessions.py", line 461, in request
resp = self.send(prep, *_send_kwargs)
File "/usr/local/lib/python3.4/site-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, *_kwargs)
File "/usr/local/lib/python3.4/site-packages/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment