Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
- uses: webfactory/ssh-agent@v0.5.4
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- run: apt update && apt install -y python3 virtualenv
- run: hypernode-deploy build -vvv
- name: archive production artifacts
uses: actions/upload-artifact@v3
Expand Down
5 changes: 5 additions & 0 deletions bin/generate_nginx_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python3
from hypernode.redirect.generate_nginx_redirects import main

if __name__ == "__main__":
main()
34 changes: 25 additions & 9 deletions deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@
task('python:venv:create', static function () {
run('mkdir -p .hypernode');
run('virtualenv -p python3 .venv');
run('echo export PYTHONPATH=$(pwd) >> .venv/bin/activate');
});

# Install the requirements
task('python:venv:requirements', static function () {
run('source .venv/bin/activate && pip install -r requirements/base.txt');
});

task('python:generate_redirects', static function () {
run('mkdir -p etc/nginx');
run('source .venv/bin/activate && bin/generate_nginx_redirects > etc/nginx/server.redirects.conf');
});

# Build the documentation
task('python:build_documentation', static function () {
run('source .venv/bin/activate && bin/build_docs');
Expand All @@ -49,17 +55,28 @@
}
});

task("deploy:docs_vhost", static function () {
run("hypernode-manage-vhosts --https --force-https {{hostname}} --no --webroot {{current_path}}/{{public_folder}}");
task('deploy:docs_vhost:acceptance', static function () {
run('hypernode-manage-vhosts --https --force-https {{hostname}} --no --webroot {{current_path}}/{{public_folder}}');
})->select('stage=acceptance');

task('deploy:docs_vhost:production', static function () {
run('hypernode-manage-vhosts --https --force-https docs.hypernode.io --no --webroot {{current_path}}/{{public_folder}}');
})->select('stage=production');

task('deploy:nginx_redirects', static function () {
run('cp {{release_path}}/etc/nginx/server.redirects.conf /data/web/nginx/server.redirects.conf');
});

$configuration = new Configuration();
$configuration->addBuildTask('python:venv:create');
$configuration->addBuildTask('python:venv:requirements');
$configuration->addBuildTask('python:build_documentation');
$configuration->addBuildTask('python:generate_redirects');
$configuration->addDeployTask('deploy:disable_public');
$configuration->addDeployTask('deploy:hmv_docker');
$configuration->addDeployTask('deploy:docs_vhost');
$configuration->addDeployTask('deploy:docs_vhost:acceptance');
$configuration->addDeployTask('deploy:docs_vhost:production');
$configuration->addDeployTask('deploy:nginx_redirects');

# Just some sane defaults to exclude from the deploy
$configuration->setDeployExclude([
Expand All @@ -73,12 +90,11 @@
'.idea',
'.gitignore',
'.editorconfig',
'etc/',
'.venv/',
'bin/',
'hypernode/',
'requirements/',
'tests/'
'./.venv',
'./bin',
'./hypernode',
'./requirements',
'./tests',
]);

$productionStage = $configuration->addStage('production', 'docs.hypernode.io');
Expand Down
31 changes: 31 additions & 0 deletions hypernode/redirect/generate_nginx_redirects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os.path
from pathlib import Path
from typing import List

from frontmatter import Frontmatter

from hypernode.common.docs import get_all_docs
from hypernode.common.settings import DOCS_DIR


def get_redirects_from_doc(doc: Path) -> List[str]:
fm = Frontmatter.read_file(doc)
attributes = fm["attributes"] or {}
return attributes.get("redirect_from", [])


def get_path_for_doc(doc: Path) -> str:
relative_path = Path(os.path.relpath(doc, DOCS_DIR))
path = "/{}/{}".format(
relative_path.parent, relative_path.name.replace(".md", ".html")
)
path = path.replace("/./", "/")
path = path.replace("/index.html", "/")
return path


def main():
for doc in get_all_docs():
for redirect in get_redirects_from_doc(doc):
doc_path = get_path_for_doc(doc)
print("rewrite ^{}$ {} permanent;".format(redirect, doc_path))