Skip to content

Commit

Permalink
new build structure with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Level8Broccoli committed Sep 22, 2019
1 parent 8916de8 commit f776515
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions configs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"websites": [
"spieltage.ch"
]
}
13 changes: 13 additions & 0 deletions docker/hugo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:disco

RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:longsleep/golang-backports && \
apt-get update && \
apt-get -y install golang-go git && \
rm -rf /var/lib/apt/lists/*

RUN git clone --single-branch --branch release-0.56.3 https://github.com/gohugoio/hugo.git
RUN cd hugo && \
go install --tags extended
RUN ln -s /root/go/bin/hugo /bin/hugo
70 changes: 70 additions & 0 deletions start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3

import argparse
import os
import subprocess
import json
import tempfile
import shutil

parser = argparse.ArgumentParser(description='')
parser.add_argument('--publish', dest='publish', action='store')

args = parser.parse_args()

script_dir = os.path.dirname(os.path.realpath(__file__))

with open(os.path.join(script_dir, 'configs', 'config.json')) as file:
config = json.load(file)

subprocess.check_call(
['docker', 'build', os.path.join(script_dir, 'docker', 'hugo'), '--tag', 'hugo-docker'])

with tempfile.TemporaryDirectory() as tmpdir:
for website in config['websites']:
public_dir = os.path.join(tmpdir, website, 'public')
os.makedirs(public_dir)

subprocess.check_call([
'docker',
'run',
'--rm',
'--volume',
'{}:{}'.format(script_dir, '/hugo'),
'--volume',
'{}:{}'.format(public_dir, '/hugo-destination'),
'hugo-docker',
'hugo',
'--source',
'/hugo/websites/{}'.format(website),
'--destination',
'/hugo-destination/'
])

for website in config['websites']:
cloned_dir = os.path.join(tmpdir, website, 'cloned')
os.makedirs(cloned_dir)
subprocess.check_call([
'git',
'clone',
'[email protected]:gilde-der-nacht/test.{}.git'.format(website),
cloned_dir
])
list_dir = os.listdir(cloned_dir)

for entry in [os.path.join(cloned_dir, entry)
for entry in list_dir if entry not in ['.git', 'CNAME']]:
if os.path.isdir(entry):
shutil.rmtree(entry)
else:
os.unlink(entry)

for entry in os.listdir(public_dir):
os.rename(os.path.join(public_dir, entry),
os.path.join(cloned_dir, entry))

subprocess.check_call(['git', 'add', '.'], cwd=cloned_dir)
subprocess.check_call(['git', 'commit', '-m', 'Test'], cwd=cloned_dir)
subprocess.check_call(['git', 'push'], cwd=cloned_dir)

subprocess.check_call(['bash'], cwd=tmpdir)

0 comments on commit f776515

Please sign in to comment.