Commit bfdad164 authored by Björn Lindström's avatar Björn Lindström

Merge branch 'separate-build-script' into 'master'

Use build script from separate repo

Closes #5

See merge request !4
parents e4a915ba 80063ac5
Pipeline #107009457 passed with stage
in 43 seconds
stages:
- prepare
- build
---
variables:
CI_REGISTRY_IMAGE: builder
GIT_SUBMODULE_STRATEGY: recursive
prepare:docker:
stage: prepare
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker pull $CI_REGISTRY/$CI_PROJECT_PATH/$CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY/$CI_PROJECT_PATH/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY/$CI_PROJECT_PATH/$CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/$CI_REGISTRY_IMAGE:latest
only:
refs:
- master
changes:
- Dockerfile
build:pages:
build:
stage: build
image: $CI_REGISTRY/$CI_PROJECT_PATH/$CI_REGISTRY_IMAGE:latest
image: registry.gitlab.com/bkhl/web-build/build-machine:latest
variables:
LANG: sv_SE.UTF-8
LC_ALL: sv_SE.UTF-8
LC_ALL: C.UTF-8
LANG: C.UTF-8
before_script:
- python3 -V
- zola --version
- xmlstarlet --version
- tidy --version
script:
- time python3 build.py
- web-build/build_website.py
artifacts:
paths:
- public
......
[submodule "web-build"]
path = web-build
url = https://gitlab.com/bkhl/web-build.git
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y curl language-pack-sv python3 python3-pip tidy xmlstarlet
RUN pip3 install plumbum
RUN curl --silent --show-error --location 'https://github.com/getzola/zola/releases/download/v0.7.0/zola-v0.7.0-x86_64-unknown-linux-gnu.tar.gz' | tar xzf - -C /usr/local/bin/
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
plumbum = "*"
[requires]
python_version = "3.6"
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
from plumbum import cli, local
from plumbum.cmd import tidy, xmlstarlet, zola
PORT = 8000
class Builder(cli.Application):
serve_locally = cli.Flag(
["l", "serve locally"], help="Build and serve page locally"
)
TCPServer.allow_reuse_address = True
def serve(self):
print("Starting server.")
with TCPServer(("", PORT), SimpleHTTPRequestHandler) as httpd:
with local.cwd(local.cwd / "public"):
httpd.serve_forever()
def public_files_by_extension(self, *extensions):
for filepath in (local.cwd / "public").walk(
filter=lambda f: f.is_file() and f.suffix in ("." + e for e in extensions),
dir_filter=lambda d: d.name != "arkiv",
):
yield filepath
def replace_prefix(self):
if self.serve_locally:
prefix = f"http://localhost:{PORT}"
else:
prefix = "https://upsala.fandom.se"
for filepath in self.public_files_by_extension("html", "xml", "txt", "css"):
with filepath.open() as file_object:
s = file_object.read().replace("__PREFIX__", prefix)
with filepath.open("w") as file_object:
file_object.write(s)
def clean_html(self):
files = list(self.public_files_by_extension("html"))
tidy("-config", "tidy.conf", *files, retcode=(0, 1))
def clean_xml(self):
for filepath in self.public_files_by_extension("xml"):
xml = xmlstarlet(
"fo",
"--noindent",
"--nocdata",
"--nsclean",
"--encode",
"utf-8",
filepath,
)
with filepath.open("w") as file_object:
file_object.write(xml)
def main(self):
zola("build")
self.replace_prefix()
self.clean_html()
self.clean_xml()
if self.serve_locally:
self.serve()
if __name__ == "__main__":
Builder.run()
quiet: yes
show-warnings: no
tidy-mark: no
vertical-space: no
wrap: 0
write-back: yes
Subproject commit db131755260d28846cd4e1c6d8a5522fb712c737
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment