Skip to content

Commit

Permalink
Merge pull request #1 from RockefellerArchiveCenter/nightly
Browse files Browse the repository at this point in the history
refactors to be a (nightly) update triggered by cron
  • Loading branch information
helrond committed Feb 28, 2018
2 parents ef01fbc + 3fab67c commit 28be075
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 232 deletions.
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

3 changes: 0 additions & 3 deletions config.json.sample
@@ -1,7 +1,4 @@
{
"github_ips_only": true,
"enforce_secret": "",
"return_scripts_info": true,
"site_root_dir": "/var/www",
"repository_dir": "repositories",
"staging_dir": "staging",
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Expand Up @@ -28,7 +28,7 @@ source /etc/profile.d/rvm.sh
rvm install 2.1.8
rvm use 2.1.8 --default

sudo pip install requests Flask ipaddress pyyaml
sudo pip install pyyaml
gem install jekyll github-pages --no-rdoc --no-ri

# Add ssh keys
Expand Down
15 changes: 0 additions & 15 deletions package.json

This file was deleted.

108 changes: 108 additions & 0 deletions update.py
@@ -0,0 +1,108 @@
#!/usr/bin/env python
# pulls files and builds sites

import sys
import yaml
from json import loads
from os import chdir, makedirs, listdir
from os.path import join, isdir, isfile, normpath, abspath, dirname
from posix import remove
from shutil import copyfile, copytree, rmtree
from subprocess import call

# base path for the build script
base_path = normpath(abspath(join(dirname(__file__))))

with open(join(base_path, 'config.json'), 'r') as cfg:
config = loads(cfg.read())

site_root_dir = config.get('site_root_dir')
repository_dir = config.get('repository_dir')
staging_dir = config.get('staging_dir')
build_dir = config.get('build_dir')
public_site_dir = config.get('public_site_dir')
private_site_dir = config.get('private_site_dir')


def get_updates(repository_name):
# If the repository exists, update the data
if isdir(join(site_root_dir, repository_dir, repository_name)):
chdir(join(site_root_dir, repository_dir, repository_name))
print "pulling from "+repository_name
call("git pull", shell=True)


def create_structure(target, site, name):
if isdir(target):
rmtree(target)
if isfile(target):
# in case someone put something (like a softlink) in its place
remove(target)
try:
makedirs(join(site_root_dir, site, build_dir))
except OSError:
# dir exists
pass
copytree(join(site_root_dir, repository_dir, name), target)


def build_site(base_url, source, destination):
chdir(base_url)
print "building at " + base_url
print "jekyll build --source %s --destination %s" % (source, destination)
call("/usr/local/rvm/gems/ruby-2.1.8/wrappers/jekyll build --source %s --destination %s" % (source, destination), shell=True)
# set file permissions and ownership if necessary


def build_structure(directory):
with open(join(site_root_dir, repository_dir, directory, '_config.yml')) as f:
yaml_config = yaml.load(f)
if yaml_config['type'] == 'docs':
if yaml_config['public']:
sites = [public_site_dir, private_site_dir]
else:
sites = [private_site_dir]
update_docs_structure(directory, sites)
if yaml_config['type'] == 'theme':
update_theme_structure(directory, [public_site_dir, private_site_dir])


def update_docs_structure(name, sites=[], *args):
print "*** building documentation ***"
for site in sites:
site_staging_dir = join(site_root_dir, site, staging_dir)
# this file is used to generate the site home page
if not isdir(join(site_staging_dir, '_data')):
makedirs(join(site_staging_dir, '_data'))
copyfile(join(site_root_dir, repository_dir, name, '_config.yml'), join(site_root_dir, site_staging_dir, '_data', name + '.yml'))
create_structure(join(site_staging_dir, name), site, name)


def update_theme_structure(name, sites=[], *args):
print "*** building theme ***"
for site in sites:
site_staging_dir = join(site_root_dir, site, staging_dir)
create_structure(site_staging_dir, site, name)

for s in listdir(join(site_root_dir, repository_dir)):
if isdir(join(site_root_dir, repository_dir, s)):
with open(join(site_root_dir, repository_dir, s, '_config.yml')) as f:
yaml_config = yaml.load(f)
if yaml_config['type'] == 'docs':
if yaml_config['public']:
sites = [public_site_dir, private_site_dir]
else:
sites = [private_site_dir]
for site in sites:
copytree(join(site_root_dir, repository_dir, s), join(site_root_dir, site, staging_dir, s))


def main():
for d in listdir(join(site_root_dir, repository_dir)):
get_updates(d)
build_structure(d)
for site in [public_site_dir, private_site_dir]:
build_site(join(site_root_dir, site), staging_dir, build_dir)


main()
203 changes: 0 additions & 203 deletions webhooks.py

This file was deleted.

0 comments on commit 28be075

Please sign in to comment.