Skip to content

Commit

Permalink
Deployment konfigurovatelný na Docker a normální instlaci.
Browse files Browse the repository at this point in the history
  • Loading branch information
westfood committed Dec 20, 2024
1 parent eaa6396 commit 3b1c97c
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 183 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pipeline {
set -o pipefail # catch non-zero exit code in pipes
# set -o xtrace # uncomment for bug hunting
ssh -o "StrictHostKeyChecking=no" -i ${SSH_CREDS} ${SSH_CREDS_USR}@10.3.0.21 sudo /home/ansible/pywb/run-test.sh
ssh -o "StrictHostKeyChecking=no" -i ${SSH_CREDS} ${SSH_CREDS_USR}@10.3.0.21 sudo /home/pywb-test/run.sh
# Následující vymřelo na nenalezení dockercopose
# ssh -o "StrictHostKeyChecking=no" -i ${SSH_CREDS} ${SSH_CREDS_USR}@10.3.0.21 sudo /opt/pywb/run-test.sh
'''
Expand Down
363 changes: 184 additions & 179 deletions ci/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,182 +2,187 @@
- name: PyWb Deployment
hosts: all
tasks:
- name: Ensure ACL installed to resolve permission issues
become: "{{ sudo | default(true) }}"
ansible.builtin.apt:
name: acl,nginx
state: present

- name: Install virtualenv via pip
become: "{{ sudo | default(true) }}"
pip:
name: virtualenv
executable: pip3

- name: User running pywb
become: "{{ sudo | default(true) }}"
ansible.builtin.user:
name: "{{ owner }}"
comment: Web archive replay system
shell: /bin/bash
create_home: yes

- name: "Prepare pywb operation directory"
become: "{{ sudo | default(true) }}"
file:
owner: "{{ owner | default(omit) }}"
group: "{{ group | default(omit) }}"
dest: "{{ item }}"
state: directory
loop:
- "{{ pywb_dir }}/venv"
- "{{ pywb_dir }}/uwsgi"

- name: Install pywb
become: "{{ sudo | default(true) }}"
become_user: "{{ owner | default(omit) }}"
ansible.builtin.pip:
name: pywb, uwsgi
virtualenv: "{{ pywb_dir }}/venv"

# - name: deploy nginx configuration for pywb-test
# become: "{{ sudo | default(true) }}"
# copy:
# dest: /etc/nginx/sites-available/pywb-test
# content: |
# server {
# listen 80;
# server_name pywb-test;
# location / {
# proxy_pass http://127.0.0.1:8080;
# }
# }

- name: deploy nginx configuration for pywb-test
become: "{{ sudo | default(true) }}"
copy:
dest: /etc/nginx/sites-available/pywb-test
content: |
server {
listen 80;
location /static {
alias {{ pywb_dir }}/venv/lib/python3.10/site-packages/pywb/static/;
}
location / {
uwsgi_pass localhost:8081;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
}
}
- name: deploy uwsgi configuration for pywb-test
become: "{{ sudo | default(true) }}"
copy:
dest: "{{ pywb_dir }}/uwsgi/uwsgi.ini"
content: |
[uwsgi]
if-not-env = PORT
http-socket = :8080
socket = :8081
endif =
master = true
buffer-size = 65536
die-on-term = true
if-env = VIRTUAL_ENV
venv = $(VIRTUAL_ENV)
endif =
gevent = 100
#Not available until uwsgi 2.1
#monkey-patching manually in pywb.apps.wayback
#gevent-early-monkey-patch =
# for uwsgi<2.1, set env when using gevent
env = GEVENT_MONKEY_PATCH=1
# specify config file here
env = PYWB_CONFIG_FILE=config.yaml
#wsgi = pywb.apps.wayback
# config to run pywb from a prefix
mount = /wayback={{ pywb_dir }}/venv/lib/python3.10/site-packages/pywb/apps/wayback.py
manage-script-name = true
- name: set nginx configuration to pywb-test
become: "{{ sudo | default(true) }}"
file:
state: link
src: /etc/nginx/sites-available/pywb-test
dest: /etc/nginx/sites-enabled/default

- name: reload nginx
become: "{{ sudo | default(true) }}"
service:
name: nginx
state: reloaded

- name: "Deployment scripts & configurations"
become: "{{ sudo | default(true) }}"
template:
owner: "{{ owner | default(omit) }}"
group: "{{ group | default(omit) }}"
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: u+x
loop:
- src: venv.sh
dest: "{{ pywb_dir }}/venv.sh"
- src: config.yaml
dest: "{{ pywb_dir }}/config.yaml"

# - name: "Prepare configuration for static web."
# copy:
# dest: /home/ansible/seeder/static-nginx.conf
# content: |
# server {
# location /static/ {
# root /seeder;
# }
# location /media/ {
# root /seeder;
# }

# # Increase max upload size to ~50MB
# client_max_body_size 53M;

# listen 0.0.0.0:80;
# }

# - name: "Deploy Docker Compose"
# template:
# src: "{{ item.src }}"
# dest: "{{ pywb_dir }}/{{ item.dest }}"
# loop:
# - src: docker-compose.yaml.j2
# dest: docker-compose-{{ env }}.yaml
# - src: config.yaml
# dest: config.yaml

# - name: "Deployment scripts"
# template:
# src: "{{ item.src }}"
# dest: "{{ item.dest }}"
# mode: u+x
# loop:
# - src: run.sh
# dest: "{{ pywb_dir }}/run-{{ env }}.sh"
# - src: stop.sh
# dest: "{{ pywb_dir }}/stop-{{ env }}.sh"
# - src: logs.sh
# dest: "{{ pywb_dir }}/logs-{{ env }}.sh"
# - src: exec.sh
# dest: "{{ pywb_dir }}/exec-{{ env }}.sh"
# - src: docker.sh
# dest: "{{ pywb_dir }}/docker-{{ env }}.sh"
# - src: wb-manager.sh
# dest: "{{ pywb_dir }}/wb-manager-{{ env }}.sh"
- name: Run pywb as Docker Image
when: pywb_deployment == 'docker'
block:
- name: "Deploy Docker Compose"
template:
src: "{{ item.src }}"
dest: "{{ pywb_dir }}/{{ item.dest }}"
loop:
- src: docker-compose.yaml.j2
dest: docker-compose.yaml
- src: config.yaml
dest: config.yaml
- name: "Deployment scripts"
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: u+x
loop:
- src: run.sh
dest: "{{ pywb_dir }}/run.sh"
- src: stop.sh
dest: "{{ pywb_dir }}/stop.sh"
- src: logs.sh
dest: "{{ pywb_dir }}/logs.sh"
- src: exec.sh
dest: "{{ pywb_dir }}/exec.sh"
- src: docker.sh
dest: "{{ pywb_dir }}/docker.sh"
- src: wb-manager.sh
dest: "{{ pywb_dir }}/wb-manager.sh"

- name: Install pywb locally (without Docker)
when: pywb_deployment == 'normal'
block:
- name: Ensure ACL installed to resolve permission issues
become: "{{ sudo | default(true) }}"
ansible.builtin.apt:
name: acl,nginx
state: present

- name: Install virtualenv via pip
become: "{{ sudo | default(true) }}"
pip:
name: virtualenv
executable: pip3

- name: User running pywb
become: "{{ sudo | default(true) }}"
ansible.builtin.user:
name: "{{ owner }}"
comment: Web archive replay system
shell: /bin/bash
create_home: yes

- name: "Prepare pywb operation directory"
become: "{{ sudo | default(true) }}"
file:
owner: "{{ owner | default(omit) }}"
group: "{{ group | default(omit) }}"
dest: "{{ item }}"
state: directory
loop:
- "{{ pywb_dir }}/venv"
- "{{ pywb_dir }}/uwsgi"

- name: Install pywb
become: "{{ sudo | default(true) }}"
become_user: "{{ owner | default(omit) }}"
ansible.builtin.pip:
name: pywb, uwsgi
virtualenv: "{{ pywb_dir }}/venv"

# - name: deploy nginx configuration for pywb-test
# become: "{{ sudo | default(true) }}"
# copy:
# dest: /etc/nginx/sites-available/pywb-test
# content: |
# server {
# listen 80;
# server_name pywb-test;
# location / {
# proxy_pass http://127.0.0.1:8080;
# }
# }

- name: deploy nginx configuration for pywb-test
become: "{{ sudo | default(true) }}"
copy:
dest: /etc/nginx/sites-available/pywb-test
content: |
server {
listen 80;
location /static {
alias {{ pywb_dir }}/venv/lib/python3.10/site-packages/pywb/static/;
}
location / {
uwsgi_pass localhost:8081;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
}
}
- name: deploy uwsgi configuration for pywb-test
become: "{{ sudo | default(true) }}"
copy:
dest: "{{ pywb_dir }}/uwsgi/uwsgi.ini"
content: |
[uwsgi]
if-not-env = PORT
http-socket = :8080
socket = :8081
endif =
master = true
buffer-size = 65536
die-on-term = true
if-env = VIRTUAL_ENV
venv = $(VIRTUAL_ENV)
endif =
gevent = 100
#Not available until uwsgi 2.1
#monkey-patching manually in pywb.apps.wayback
#gevent-early-monkey-patch =
# for uwsgi<2.1, set env when using gevent
env = GEVENT_MONKEY_PATCH=1
# specify config file here
env = PYWB_CONFIG_FILE=config.yaml
#wsgi = pywb.apps.wayback
# config to run pywb from a prefix
mount = /wayback={{ pywb_dir }}/venv/lib/python3.10/site-packages/pywb/apps/wayback.py
manage-script-name = true
- name: set nginx configuration to pywb-test
become: "{{ sudo | default(true) }}"
file:
state: link
src: /etc/nginx/sites-available/pywb-test
dest: /etc/nginx/sites-enabled/default

- name: reload nginx
become: "{{ sudo | default(true) }}"
service:
name: nginx
state: reloaded

- name: "Deployment scripts & configurations"
become: "{{ sudo | default(true) }}"
template:
owner: "{{ owner | default(omit) }}"
group: "{{ group | default(omit) }}"
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: u+x
loop:
- src: venv.sh
dest: "{{ pywb_dir }}/venv.sh"
- src: config.yaml
dest: "{{ pywb_dir }}/config.yaml"

# - name: "Prepare configuration for static web."
# copy:
# dest: /home/ansible/seeder/static-nginx.conf
# content: |
# server {
# location /static/ {
# root /seeder;
# }
# location /media/ {
# root /seeder;
# }

# # Increase max upload size to ~50MB
# client_max_body_size 53M;

# listen 0.0.0.0:80;
# }
2 changes: 2 additions & 0 deletions ci/group_vars/all/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Choose Docker or Normal pywb deployment. Normal is not finished.
pywb_deployment: docker
18 changes: 18 additions & 0 deletions ci/group_vars/prod/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Environment - is it production, test or local development?
env: test

treafik_host_routing: pywb.webarchiv.cz

# Directory where pywb is installed
# pywb_dir: /home/ansible/pywb

# Who owns directories & files
# owner: ansible
# group: ansible

# Directory where pywb is installed
pywb_dir: /home/pywb-prod

# Who owns directories & files
owner: pywb-prod
group: pywb-prod
Loading

0 comments on commit 3b1c97c

Please sign in to comment.