From 1426c4b732514b57eb705a96dd559183e0538cc6 Mon Sep 17 00:00:00 2001 From: Marvin Steadfast Date: Sat, 22 Aug 2015 19:41:55 +0000 Subject: [PATCH] using docker and vagrant for blogging environment also added cookiecutter for easier blog post creation. --- .gitignore | 1 + Makefile | 4 + README.md | 17 +- Vagrantfile | 24 + _nb_header.html | 1576 ++++++++++++++++- ansible/vagrant.yml | 42 + cookiecutter-new-post/cookiecutter.json | 7 + .../posts/{{cookiecutter.slug}}.md | 5 + newpost.py | 7 + pelican-plugins | 2 +- pelicanconf.py | 2 +- requirements.txt | 33 +- vagrant/Dockerfile | 36 + vagrant/supervisord.conf | 6 + 14 files changed, 1707 insertions(+), 55 deletions(-) create mode 100644 Vagrantfile create mode 100644 ansible/vagrant.yml create mode 100644 cookiecutter-new-post/cookiecutter.json create mode 100644 cookiecutter-new-post/{{cookiecutter.repo_name}}/posts/{{cookiecutter.slug}}.md create mode 100644 newpost.py create mode 100644 vagrant/Dockerfile create mode 100644 vagrant/supervisord.conf diff --git a/.gitignore b/.gitignore index 1563c8a..c45d480 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ nosetests.xml # OWN STUFF .ftp_pass.txt +.vagrant/* diff --git a/Makefile b/Makefile index e172926..629e811 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ help: @echo ' make s3_upload upload the web site via S3 ' @echo ' make cf_upload upload the web site via Cloud Files' @echo ' make github upload the web site via gh-pages ' + @echo ' make newpost create new post ' @echo ' ' @echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html' @echo ' ' @@ -108,4 +109,7 @@ github: publish ghp-import -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR) git push origin $(GITHUB_PAGES_BRANCH) +newpost: + python $(BASEDIR)/newpost.py + .PHONY: html help clean regenerate serve devserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github diff --git a/README.md b/README.md index 814c6a7..7518243 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,12 @@ blog ==== - -## install ## +## create environment ## 1. `git clone git@github.com:xsteadfastx/blog.git` -2. `cd blog && virtualenv -p /usr/bin/python3 venv` -3. `source venv/bin/activate` -4. `pip install -r requirements.txt` - -## upgrade ## -`pip install --upgrade pelican markdown ghp-import shovel` +2. build the environment with `cd blog && vagrant up` +3. login in the environment with `vagrant ssh` ## write ## -1. put the markdown files in "content/posts" -2. test it with `make html && make serve` -3. upload it to github with `make github` +1. create new post with `make newpost` +2. write the post with`vim content/posts/new-blog-post.md` +3. upload with `make ftp_upload` diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..3507c4b --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,24 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + config.vm.network "forwarded_port", guest: 8888, host: 8888 + config.ssh.forward_agent = true + + config.vm.provider "docker" do |d| + d.build_dir = "./vagrant" + d.has_ssh = true + end + + # provisioning + require 'rbconfig' + + config.vm.provision "ansible" do |ansible| + ansible.playbook = "ansible/vagrant.yml" + ansible.limit = "all" + ansible.verbose = "v" + #ansible.vault_password_file = "ansible/.vault_pass.txt" + ansible.host_key_checking = false + end + +end diff --git a/_nb_header.html b/_nb_header.html index e6a31b9..4b3566d 100644 --- a/_nb_header.html +++ b/_nb_header.html @@ -1,41 +1,1545 @@ diff --git a/ansible/vagrant.yml b/ansible/vagrant.yml new file mode 100644 index 0000000..25d38bb --- /dev/null +++ b/ansible/vagrant.yml @@ -0,0 +1,42 @@ +--- +- hosts: all + + tasks: + + - name: install deps + apt: + name={{ item }} + state=present + with_items: + - git + - ansible + - python-dev + - python-virtualenv + - libxml2-dev + - libxslt1-dev + - zlib1g-dev + - lftp + - pandoc + - nodejs + sudo: yes + + - name: clone batcave + git: + repo=https://github.com/xsteadfastx/batcave.git + dest=~/batcave + + - name: run batcave + command: + ansible-playbook -i hosts site.yml --skip-tags "x11" -c local + chdir=~/batcave + + - name: create python environment + pip: + requirements=/vagrant/requirements.txt + virtualenv=~/env + virtualenv_command=virtualenv -p /usr/bin/python3 + + - name: clone pelican plugins + git: + repo=https://github.com/getpelican/pelican-plugins.git + dest=/vagrant/pelican-plugins diff --git a/cookiecutter-new-post/cookiecutter.json b/cookiecutter-new-post/cookiecutter.json new file mode 100644 index 0000000..bea3919 --- /dev/null +++ b/cookiecutter-new-post/cookiecutter.json @@ -0,0 +1,7 @@ +{ + "repo_name": "content", + "title": "Title", + "slug": "slug-used-for-url-and-filename", + "tags": "tags, goes, here", + "description": "used for twitter cards" +} diff --git a/cookiecutter-new-post/{{cookiecutter.repo_name}}/posts/{{cookiecutter.slug}}.md b/cookiecutter-new-post/{{cookiecutter.repo_name}}/posts/{{cookiecutter.slug}}.md new file mode 100644 index 0000000..a93f4d6 --- /dev/null +++ b/cookiecutter-new-post/{{cookiecutter.repo_name}}/posts/{{cookiecutter.slug}}.md @@ -0,0 +1,5 @@ +Title: {{cookiecutter.title}} +Date: {{cookiecutter.date}} +Slug: {{cookiecutter.slug}} +Tags: {{cookiecutter.tags}} +Description: {{cookiecutter.description}} diff --git a/newpost.py b/newpost.py new file mode 100644 index 0000000..a348a5f --- /dev/null +++ b/newpost.py @@ -0,0 +1,7 @@ +from cookiecutter.main import cookiecutter +from datetime import datetime + + +cookiecutter( + 'cookiecutter-new-post', + extra_context={'date': datetime.utcnow().strftime('%Y-%m-%d %H:%M')}) diff --git a/pelican-plugins b/pelican-plugins index 5b794ea..fda474f 160000 --- a/pelican-plugins +++ b/pelican-plugins @@ -1 +1 @@ -Subproject commit 5b794ea11b272a74981877a9d8b64dc3d4a2254d +Subproject commit fda474fb90473874f5a0f04b6dda2d4db7c4503e diff --git a/pelicanconf.py b/pelicanconf.py index 44bd464..8bba8ae 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -68,7 +68,7 @@ PLUGIN_PATHS = ['pelican-plugins'] PLUGINS = ['liquid_tags.youtube', 'liquid_tags.vimeo', 'liquid_tags.notebook'] NOTEBOOK_DIR = 'notebooks' -EXTRA_HEADER = open('_nb_header.html').read().decode('utf-8').replace( +EXTRA_HEADER = open('_nb_header.html').read().replace( 'highlight', 'highlight-ipynb') CACHE_CONTENT = True diff --git a/requirements.txt b/requirements.txt index 99bcf93..7a4a03a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,29 +1,50 @@ BeautifulSoup==3.2.1 -Jinja2==2.7.3 +Jinja2==2.8 Markdown==2.4 MarkupSafe==0.23 +PyYAML==3.11 Pygments==2.0.2 Unidecode==0.04.18 argparse==1.2.1 backports.ssl-match-hostname==3.4.0.2 beautifulsoup4==4.3.2 +binaryornot==0.4.0 blinker==1.3 -certifi==14.05.14 +certifi==2015.04.28 +chardet==2.3.0 +click==3.3 +cookiecutter==1.0.0 +decorator==4.0.2 docutils==0.12 feedgenerator==1.7 +funcsigs==0.4 functools32==3.2.3-1 ghp-import==0.4.1 -ipython==3.1.0 +ipykernel==4.0.3 +ipython==4.0.0 +ipython-genutils==0.1.0 jsonschema==2.5.1 +jupyter-client==4.0.0 +jupyter-core==4.0.4 lxml==3.4.2 -mistune==0.5.1 +mistune==0.7 +mock==1.3.0 +nbconvert==4.0.0 +nbformat==4.0.0 +notebook==4.0.4 +path.py==7.6.1 +pbr==1.5.0 pelican==3.6.0 +pexpect==3.3 +pickleshare==0.5 ptyprocess==0.5 python-dateutil==2.4.2 pytz==2015.4 -pyzmq==14.4.1 +pyzmq==14.7.0 requests==2.6.0 +simplegeneric==0.8.1 six==1.9.0 terminado==0.5 -tornado==4.0.2 +tornado==4.2.1 +traitlets==4.0.0 wsgiref==0.1.2 diff --git a/vagrant/Dockerfile b/vagrant/Dockerfile new file mode 100644 index 0000000..abfaee5 --- /dev/null +++ b/vagrant/Dockerfile @@ -0,0 +1,36 @@ +FROM 32bit/ubuntu:14.04 + +RUN apt-get update \ + && apt-get install -y \ + software-properties-common \ + python-software-properties \ + + && add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty universe" \ + + && apt-get update \ + && apt-get install -y \ + openssh-server \ + supervisor + +RUN mkdir -p /var/run/sshd +RUN chmod 0755 /var/run/sshd + +# Create and configure vagrant user +RUN useradd --create-home -s /bin/bash vagrant +WORKDIR /home/vagrant + +# Configure SSH access +RUN mkdir -p /home/vagrant/.ssh +RUN echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/vagrant/.ssh/authorized_keys +RUN chown -R vagrant: /home/vagrant/.ssh +RUN echo -n 'vagrant:vagrant' | chpasswd + +# Enable passwordless sudo for the "vagrant" user +RUN echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/vagrant +RUN chmod 0440 /etc/sudoers.d/vagrant + +# Supervisor +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +EXPOSE 22 +CMD ["/usr/bin/supervisord"] diff --git a/vagrant/supervisord.conf b/vagrant/supervisord.conf new file mode 100644 index 0000000..0b1f2bf --- /dev/null +++ b/vagrant/supervisord.conf @@ -0,0 +1,6 @@ +[supervisord] +nodaemon=true + +[program:sshd] +command=/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no +autostart=true