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

Allow running the build with docker #564

Merged
merged 48 commits into from
Feb 6, 2019
Merged

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Jan 29, 2019

This adds support for building the docs using docker with the expectation
without breaking support for building the docs without docker. My goal
is to make it simpler for to add dependencies. In the long term this'll
allow us to add support for automatically building diagrams and fancy
mathematical notation. In the short term this'll make it simpler to run
asciidoctor in CI.

On macOS docker is a little slower than running outside of docker. At
this point the overhead is about 20%. This isn't great, but Asciidoctor
will more than make up the difference in the long run. And, in the short
run at least, docker isn't reaquired. I'll make sure it is never
required to build Asciidoc.

One fairly questionable choice that this makes is to diable seccomp by
default. The story goes like this: on linux, building the docs in docker
is somewhere between faster than building them outside of docker and
macOS's overhead. Unless you turn on seccomp. With seccomp enabled the
docs take about twice as long to build in docker. Which is terrible! As
much as I want security, this is terrible! I'd really love to turn it on
but I can't defend that kind of hit.

@nik9000 nik9000 requested review from a user and ddillinger January 29, 2019 20:36
@@ -0,0 +1,35 @@
# Debian builds the docs about 20% faster than alpine. The image is larger
# and takes longer to build but that is worth it.
FROM bitnami/minideb:stretch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alpine is much nicer to work with but 20% slower is a big deal given how often we run this locally.

@@ -17,23 +17,7 @@ on any other website without explicit permission.
[float]
== Requirements

First, you need to make sure that you have the following installed:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just pointing folks right at docker by default because it ought to be simpler to set up.

@@ -1027,13 +1005,13 @@ footnote to a particular line of code:
==================================

[[sense-snippets]]
=== View in Sense
=== View in Console
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't related but they jumped out at me while I was here. I can break this out if folks are more comfortable with that.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grep tells me there are two more SENSEs lurking in here if you wanna smack 'em.

$ grep -iFn sense README.asciidoc
1066:    // SENSE: path/to/snippet.json
1082:// SENSE:one/two/three/example_1.json <1>

if ( $running_in_docker ) {
# We use nginx to serve files instead of the python built in web server
# when we're running inside docker because the python web server performs
# badly there. nginx is fine.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The python web server is fine some of the time but hangs for many seconds at a time. I suspect it'll do that on some Linux systems as well, but nginx runs just fine here.

listen 8000;
location / {
root $dir;
add_header 'Access-Control-Allow-Origin' '*';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are copied from the python runner.

build_docs.sh Outdated
# Build the docker image from stdin so we don't try to pack up everything in
# this directory. It is huge and we don't need any of it in the image because
# we'll mount it into the image on startup.
docker image build -t elastic/docs_build - < "$DIR/Dockerfile"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building the docker image right here feels good to me from a development background. It feels "like gradle but for native dependencies". I know the analogy isn't quite right, but it is pretty close in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we could do things like git bisect and get the docker image specified by the Dockerfile in the repo right now. I'd be quite happy with a caching strategy that makes it so we don't have to build the image locally all the time, but this feels like a simple solution for now.

build_docs.sh Outdated

# Seccomp adds a *devestating* performance overhead if you happen
# to have it installed.
DOCKER_RUN_ARGS+=('--security-opt' 'seccomp=unconfined')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the commit message for this one. I don't like it, but without it my laptop hates this change. I've spent a few days looking into it and I'm cutting my losses for now.

build_docs.sh Outdated
# Running read-only with a proper tmp directory gives us a little
# performance boost and it is simple enough to do.
DOCKER_RUN_ARGS+=('--read-only')
DOCKER_RUN_ARGS+=('--tmpfs' '/tmp')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out it isn't that simple to do for nginx, but it isn't too bad and it feels good to know all the places where we write.

build_docs.sh Outdated
@@ -0,0 +1,173 @@
#!/bin/bash
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

longform-original-14836-1414320930-10

Any advice for writing a bash script that isn't terrible. I'm quite attached to the "iterate all the args and rewrite" method, but beyond that I have no opinions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um... write a Python script instead? Where does the imperative to use Bash come from? If it's deps, then Mac and Linux users have Bash and Python already. Windows users don't have either, so they are going to have to install something either way. Or, you could embrace the chaos and run the script in a container.

build_docs.sh Outdated
DOCKER_RUN_ARGS+=('-e' "SSH_AUTH_SOCK=$SSH_AUTH_SOCK")
fi
# Mount our known_hosts file into the VM so it won't ask about github
DOCKER_RUN_ARGS+=('-v' "$(to_absolute_path ~/.ssh/known_hosts):/tmp/.ssh/known_hosts:ro,cached")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we could use something like ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts to add github's key but this feels, like, slightly better. I feel like this trusts that the user cloned from github and accepted the host. I could copy it in I suppose rather than mount. I've kind of gone mount crazy here but lots of mounts is kind of required for a project like this.

@nik9000
Copy link
Member Author

nik9000 commented Jan 29, 2019

One thing I didn't do in this PR is switch to using the asciidoctor gem in the docker image. We're just using ruby from the image. I'd like to save that for a followup PR because it is fairly mechanical and not actually interesting from a "docker" perspective.

@@ -1080,7 +1058,7 @@ The local web browser can be stopped with `Ctrl-C`.
==== Custom Sense snippets

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another "Sense".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

return 0 unless ( -e $root_cgroup );
open(my $root_cgroup_file, $root_cgroup);
return grep {/docker/} <$root_cgroup_file>;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I consider myself a "linguist programmer", as opposed to a "mathematical programmer" (yay, false dichotomies!), so postfix conditionals make me so happy. Ruby has them, but it's passing into the mists of time, too. 👋

build_docs.sh Outdated
@@ -0,0 +1,173 @@
#!/bin/bash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um... write a Python script instead? Where does the imperative to use Bash come from? If it's deps, then Mac and Linux users have Bash and Python already. Windows users don't have either, so they are going to have to install something either way. Or, you could embrace the chaos and run the script in a container.

@nik9000
Copy link
Member Author

nik9000 commented Feb 2, 2019

@Jarpy I think this is ready for another round!

I say, and then 10 hours later I push 3 more patches.

README.asciidoc Outdated
@@ -54,7 +38,7 @@ this README as follows:
[source,bash]
----------------------------
cd docs/
./build_docs.pl --doc README.asciidoc --open
./build_docs.sh --doc README.asciidoc --open
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no .sh any more, right?

@nik9000
Copy link
Member Author

nik9000 commented Feb 4, 2019 via email

@nik9000
Copy link
Member Author

nik9000 commented Feb 4, 2019 via email

These might not be right but the others were probably wrong too.
@nik9000
Copy link
Member Author

nik9000 commented Feb 5, 2019

@Jarpy could you have another look when you get a chance?

build_docs Outdated
@@ -0,0 +1,258 @@
#!/usr/bin/env python2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no! mac doesn't like this shebang!

@nik9000
Copy link
Member Author

nik9000 commented Feb 5, 2019

I talked to @Jarpy last night. The shebang issue is that last one that we could find. Sadly, it looks like the best way to solve this is to make the script compatible with any version of python which is a little funky, but I'll work on it today. It is the one thing in this repo that'll have to deal with "funny" versions. Everything else had docker to control it.

build_docs Outdated
# it needs to die.
docker_args.append('-i')

# NOCOMMIT handle "tell me who you are"!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm - this is a blocker! I didn't realize I hadn't got to it yet.

@nik9000
Copy link
Member Author

nik9000 commented Feb 5, 2019

I just tested the NOCOMMIT - it was a leftover. I'd already handled it. I was able to build docs locally with docker and push the changes. This might just work!

@nik9000
Copy link
Member Author

nik9000 commented Feb 5, 2019

@Jarpy, could you give this another round today?

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say ship this bad baby.



def decode(bytes_or_str):
"""Decode the result of reading from popen's stdout. In python 2 the
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it came to this :(

@nik9000
Copy link
Member Author

nik9000 commented Feb 6, 2019

I say ship this bad baby.

❤️! Thanks for all of your reviewing! It was a long road, but we're getting there!

@nik9000
Copy link
Member Author

nik9000 commented Feb 6, 2019

Things are pretty busy in this repo right now so I'll hold on to the PR until things calm down.

@nik9000 nik9000 merged commit 3b73603 into elastic:master Feb 6, 2019
@nik9000
Copy link
Member Author

nik9000 commented Feb 6, 2019

OK! Things are looking calmer so I've merged this. Now you can use docker! I'll see about fixing ssh auth on mac now.

nik9000 added a commit that referenced this pull request Feb 15, 2019
This adds support for building the docs using docker with the expectation
without breaking support for building the docs *without* docker. My goal
is to make it simpler for to add dependencies. In the long term this'll
allow us to add support for automatically building diagrams and fancy
mathematical notation. In the short term this'll make it simpler to run
asciidoctor in CI.

On macOS docker is a little slower than running outside of docker. At
this point the overhead is about 20%. This isn't great, but Asciidoctor
will more than make up the difference in the long run. And, in the short
run at least, docker isn't reaquired. I'll make sure it is *never*
required to build Asciidoc.

One fairly questionable choice that this makes is to diable seccomp by
default. The story goes like this: on linux, building the docs in docker
is somewhere between *faster* than building them outside of docker and
macOS's overhead. Unless you turn on seccomp. With seccomp enabled the
docs take about twice as long to build in docker. Which is terrible! As
much as I want security, this is terrible! I'd really love to turn it on
but I can't defend that kind of hit.
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.

1 participant