Working devdocs build with githooks

This commit is contained in:
Max Fowler 2020-11-09 21:08:07 +01:00
parent 896076600c
commit 6762ef2582
14 changed files with 102 additions and 31 deletions

5
.gitignore vendored
View File

@ -1,2 +1,5 @@
secret_files*
secret*
secret*
deploy.sh
setup.sh
ssh.sh

View File

@ -1,6 +1,34 @@
# simple-ansible-template
# peach-vps config
tested with ansible-playbook 2.9.3
Code for configuring the peachcloud vps for various hosting and automation
- debian repository of microservices
- mdbook builder for devdocs
# generate deploy key
`ssh-keygen -t rsa -b 4096 -C "email@email.com"`
using ansible 2.9.3
[instructions to install ansible locally](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)
# setup
`ansible-playbook -i ansible/hosts ansible/setup.yml`
gpg key creation is still not automated,
so after creating the server generate a gpg key on the server,
put the gpg_key_id into vars.yaml and then run setup
# deploy
`ansible-playbook -i ansible/hosts ansible/deploy.yml`
# building releases (to be automated later)
## building for arm64
`cd /srv/src/peach-oled
cargo-deb
cd /srv/www/repos/apt/debian
reprepro includedeb buster /srv/src/peach-oled/target/debian/peach-oled_0.1.0_amd64.deb`
## building for aarch64
`cd /srv/src/peach-oled
cargo build --release --target=aarch64-unknown-linux-gnu
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc cargo-deb --release --target=aarch64-unknown-linux-gnu`

View File

@ -22,3 +22,10 @@
- name: install reprepro
apt: pkg=reprepro
- name: install toolchain for cross-compilation
command: /root/.cargo/bin/rustup toolchain install nightly-aarch64-unknown-linux-gnu
- name: install aarch644 gcc
apt: pkg=gcc-aarch64-linux-gnu

View File

@ -16,12 +16,7 @@
- name: create nginx site configs
action: template src={{item.template}} dest=/etc/nginx/sites-enabled/{{item.name}}
loop:
- { template: 'templates/nginx_peach.conf', name: 'peach.conf' }
notify:
- restart nginx
- name: copy index.html
action: template src=index.html dest="{{web_dir}}/index.html"
- { template: 'templates/nginx/nginx_devdocs.conf', name: 'devdocs.conf' }
notify:
- restart nginx
@ -31,7 +26,7 @@
- restart nginx
- name: tasks for creating debian repository
include_tasks: debian_rep.yml
include_tasks: debianrep.yml
args:
apply:
tags:
@ -39,6 +34,15 @@
tags:
- debian
- name: tasks for devdocs
include_tasks:
file: devdocs.yml
apply:
tags:
- devdocs
tags:
- devdocs
handlers:
- name: restart nginx
action: service name=nginx state=restarted

26
ansible/devdocs.yml Normal file
View File

@ -0,0 +1,26 @@
---
- name: ensure devdocs_bare
action: file dest={{src_dir}}/devdocs_bare state=directory
- name: initialize devdocs_bare git repo
command: git init --bare {{src_dir}}/devdocs_bare
args:
creates: '{{src_dir}}/devdocs_bare/.git'
- name: ensure devdocs_build
action: file dest={{src_dir}}/devdocs_build state=directory
- name: ensure git hooks directory
action: file dest={{src_dir}}/devdocs_bare/hooks state=directory
- name: copy devdocs githook
action: template src=devdocs/git-post-receive dest="{{src_dir}}/devdocs_bare/hooks/post-receive" mode='770'
- name: ensure devdocs web directory
action: file dest={{web_dir}}/docs:peachcloud:org/html state=directory
- name: install mdbook
shell: /root/.cargo/bin/cargo install mdbook
args:
creates: /root/.cargo/bin/mdbook

View File

@ -38,8 +38,15 @@
- name: install rust by rustup
shell: curl https://sh.rustup.rs -sSf | sh -s -- -y
args:
creates: /root/.cargo/bin/rustc
- name: install cargo deb
shell: /root/.cargo/bin/cargo install cargo-deb
args:
creates: /root/.cargo/bin/cargo-deb
- name: copy main nginx config
action: template src=nginx/nginx.conf dest=/etc/nginx/nginx.conf

View File

@ -0,0 +1,13 @@
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to build directory..."
git --work-tree={{src_dir}}/devdocs_build --git-dir={{src_dir}}/devdocs_bare checkout -f
echo "Building docs and deploying to production..."
/root/.cargo/bin/mdbook build {{src_dir}}/devdocs_build --dest-dir {{web_dir}}/docs:peachcloud:org/html
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done

View File

@ -1,10 +0,0 @@
description "uWSGI server instance configured to serve hello_webapp"
start on runlevel [2345]
stop on runlevel [!2345]
setuid wsgi-user
setgid webgroup
chdir {{src_dir}}
exec uwsgi --ini hello_webapp.ini

View File

@ -1 +0,0 @@
hello cat landing page

View File

@ -1,4 +1,4 @@
user www-data peach;
user www-data;
worker_processes 1;
worker_rlimit_nofile 8192;

View File

@ -3,7 +3,7 @@ server {
server_name 159.89.5.141;
location / {
root /srv/www/;
root {{web_dir}}/docs:peachcloud:org/html;
index index.html;
try_files $uri $uri/ /index.html;
}

View File

@ -1,2 +0,0 @@
#!/usr/bin/env bash
ansible-playbook -i ansible/hosts ansible/deploy.yml --tags debian

View File

@ -1,3 +0,0 @@
#!/usr/bin/env bash
ansible-playbook -i ansible/hosts ansible/setup.yml
ansible-playbook -i ansible/hosts ansible/deploy.yml

1
ssh.sh
View File

@ -1 +0,0 @@
ssh -i ansible/secret_files/do_rsa root@159.89.5.141