Merge pull request #207 from chr15m/move-bootstrap-update-docs

pull/210/head
Rui Carmo 2021-09-23 08:33:41 +01:00 zatwierdzone przez GitHub
commit b7fb0ef64a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
9 zmienionych plików z 5 dodań i 476 usunięć

Wyświetl plik

@ -54,34 +54,14 @@ To use `piku` you need a VPS, Raspberry Pi, or other server bootstrapped with `p
There are two main ways of deploying `piku` onto a new server:
* Use `cloud-init` when creating a new virtual machine or barebones automated deploy (check [this repository](https://github.com/piku/cloud-init) for examples)
* Use `piku-bootstrap` to reconfigure a new or existing virtual machine
**Warning**: You should use a fresh server or VPS instance without anything important running on it already, as `piku-bootstrap` will make changes to configuration files, running services, etc.
Once you've got a fresh server, download the [piku-bootstrap](./piku-bootstrap) shell script onto your local machine and run it:
```shell
curl https://piku.github.io/get | sh
```
The first time it is run `piku-bootstrap` will install itself into `~/.piku-bootstrap` on your local machine and set up a virtualenv there with the dependencies it requires. It will only need to do this once.
The script will display a usage message and you can then bootstrap your server:
```shell
./piku-bootstrap root@yourserver.net
```
If you put the `piku-bootstrap` script on your `PATH` somewhere, you can use it again to provision other servers in the future.
See below for instructions on [installing other custom dependencies](#installing-other-dependencies) that your apps might need like a database etc.
* Use `[piku-bootstrap](https://github.com/piku/piku-bootstrap)` to reconfigure a new or existing Ubuntu virtual machine
### `piku` client
To make life easier you can also install the [piku](./piku) helper CLI. Install it into your path e.g. `~/bin` to run it from anywhere.
```shell
./piku-bootstrap install-cli ~/bin
curl https://raw.githubusercontent.com/piku/piku/master/piku > ~/bin/piku && chmod 755 ~/bin/piku
```
This shell script makes working with `piku` remotes a bit simpler. If you have a git remote called `piku` in the current folder it will infer the remote server and app name and insert those into the remote piku commands. This allows you to execute commands like the following on your running remote app:
@ -111,24 +91,6 @@ data ENV index.html package.json package-lock.json Procfile server.wisp
Tip: If you put this `piku` script on your `PATH` you can use the `piku` command across multiple apps on your local.
### Installing other dependencies
`piku-bootstrap` uses Ansible internally and it comes with several extra built-in playbooks which you can use to bootstrap common components onto your `piku` server.
Use `piku-bootstrap list-playbooks` to show a list of built-in playbooks, and then to install one add it as an argument to the bootstrap command.
For example, to deploy `nodeenv` onto your server:
```shell
piku-bootstrap root@yourserver.net nodeenv.yml
```
You can also use `piku-bootstrap` to run your own Ansible playbooks like this:
```shell
piku-bootstrap root@yourserver.net ./myplaybook.yml
```
## Virtual Hosts
If you are on a LAN and are accessing `piku` from macOS/iOS/Linux clients, you can try using [`piku/avahi-aliases`](https://github.com/piku/avahi-aliases) to announce different hosts via Avahi/mDNS/Bonjour.

Wyświetl plik

@ -4,10 +4,11 @@ This is a simple Piku app to demonstrate deploying a Postgres backed Django app.
During the `release` worker phase this app creates a Postgres database, as well as running the Django `collectstatic` and `migrate` tasks. The `release` worker will use the domain name (`NGINX_SERVER_NAME`) for the database name and the Django app assumes this in [settings.py](pikudjango/settings.py), so make sure you set the config variable to specify a domain name. See below for instructions.
In order for this to work you will first need to install `postgresql` on your Piku server. You can do this with the bootstrap script:
In order for this to work you will first need to install `postgresql` on your Piku server. You can do this with the [bootstrap script](https://github.com/piku/piku-bootstrap):
```shell
piku-bootstrap root@myserver.net postgres.yml
ssh root@my-piku-server
./piku-bootstrap postgres.yml
```
To publish this app to `piku`, make a copy of this folder and run the following commands inside the copy:

Wyświetl plik

@ -1,181 +0,0 @@
#!/bin/sh
# Usage:
# To bootstrap your machine called mybox.com with piku
#
# ./piku-bootstrap mybox.com
PBD=${PIKU_BOOTSTRAP_DIR:-~/.piku-bootstrap}
VENV="${PBD}/virtualenv"
REPO="${PBD}/piku"
VIRTUALENV_VERSION="16.0.0"
LOG="${PBD}/install.log"
main() {
# print a message if this is a first time run
if [ ! -d "${PBD}" ]; then
echo "Looks like this is your first time running piku-bootstrap."
echo "This script will self-install dependencies into ${PBD} now."
echo "Hit enter to continue or ctrl-C to abort."
read discarded
echo
fi
# check git dependencies
command -v git > /dev/null || bail "This script depends on git. Please install it to continue.";
# ensure we have a dir
mkdir -p "${PBD}"
# ensure we have a virtualenv setup
if [ ! -d "$VENV" ]; then
echo " #> Virtualenv setup not found. Installing it into ${PBD}."
ensure_virtualenv
fi
# get into virtualenv
. "$VENV/bin/activate"
# ensure we have the piku repo checked out
if [ ! -d "${REPO}" ]; then
echo " #> Piku repo not found. Installing it into ${REPO}."
git clone https://github.com/piku/piku "${REPO}"
fi
# ensure ansible
if [ "`command -v ansible-playbook`" = "" ]
then
echo " #> ansible-playbook binary not found. Installing it into ${PBD}."
pip install -q "ansible==2.7.10" >"${LOG}" 2>&1 || bail "Failed to install Ansible.\nSee ${LOG} for details (you may be missing a C compiler)."
fi
if [ "$1" = "" ]
then
echo
echo "Usage:"
echo " `basename $0` [USER@]HOST [PLAYBOOK] [ANSIBLE_ARGS...]"
echo " `basename $0` install-cli DESTINATION"
echo " `basename $0` list-playbooks"
echo " `basename $0` update"
echo
echo " HOST Creates a user 'piku' on the machine 'HOST',"
echo " installs git, and sets up the piku.py script"
echo " by default, unless PLAYBOOK is specified."
echo
echo " USER Optional non-root user to log in as (e.g. 'pi')."
echo
echo " PLAYBOOK Optional playbook to deploy on to the server."
echo " For example 'nodeenv.yml' installs nodeenv."
echo " Can be an absolute path to your own playbook."
echo
echo " list-playbooks"
echo " List available built-in playbooks."
echo
echo " install-cli DESTINATION"
echo " Install the 'piku' CLI helper to e.g. ~/bin."
echo
echo " update Pull the piku repo to get the latest playbooks."
echo
echo "Notes:"
echo
echo " * This script requires that you have root/sudo on HOST."
echo " * Use \`ssh-copy-id USER@HOST\` to upload your SSH key first."
echo " * HOST must be a Debian/Ubuntu based distribution."
echo
echo "Raspberry Pi example:"
echo
echo "\t`basename $0` pi@raspberrypi.local"
echo
echo " ** WARNING **"
echo " This script installs software and makes changes on the target"
echo " server. Only use a freshly provisioned server which you do not"
echo " mind being modified and reconfigured."
echo
else
case "$1" in
update)
echo "Updating piku repo."
cd "${REPO}"
git pull
;;
first-run)
echo
echo " #> Success!"
echo
echo "The piku-bootstrap command is now installed in the current folder."
echo "Copy it somewhere on your PATH, like ~/bin/ to make it accessible from anywhere."
echo "Run 'piku-bootstrap install-cli DESTINATION' to install the piku helper."
echo "Run 'piku-bootstrap' with no arguments for help."
echo ""
;;
install-cli)
if [ "$2" = "" ]
then
echo "Usage: piku-bootstrap install-cli ~/bin"
else
ln -s "${REPO}/piku" "$2"
echo "Installed piku cli to $2"
fi
;;
list-playbooks)
ls "${REPO}/playbooks"
;;
*)
host="$1"; shift
if [ ! "$1" = "" -a -z "${1##*.yml*}" ];
then
playbook="$1"; shift;
else
playbook="piku.yml"
fi
if [ -z "${playbook##*.yml*}" ]; then
echo "Bootstrapping piku onto ${host}"
builtin="${REPO}/playbooks/${playbook}"
if [ ! -f "${playbook}" -a -f "${builtin}" ]; then
echo "Using built-in playbook: ${playbook}"
playbook="${builtin}"
fi
PYTHONWARNINGS="ignore" ansible-playbook -i "${host}", "${playbook}" "$@" --extra-vars "piku_user=$PIKU_USER"
else
echo "${playbook} is not a valid playbook name."
fi
;;
esac
fi
}
bail_install() {
echo " #> Self-installation failed."
echo " #> Check ${LOG} for details."
exit 1;
}
ensure_virtualenv() {
# TODO: use local virtualenv instead if `command -v virtualenv` succeeds
[ -d "${PBD}/virtualenv" ] || (\
cd "${PBD}"
[ -f "./.virtualenv-source/virtualenv.py" ] || install_virtualenv;
echo " #> Setting up the virtual environment." && \
./.virtualenv-source/virtualenv.py -q "${PBD}/virtualenv" || bail_install)
rm -rf ./.virtualenv-source
}
install_virtualenv() {
VIRTUALENV_URL="https://pypi.io/packages/source/v/virtualenv/virtualenv-${VIRTUALENV_VERSION}.tar.gz"
echo " #> Downloading & installing Virtualenv."
rm -rf "./.virtualenv-source"
mkdir -p "./.virtualenv-source"
[ -f "./virtualenv.tar.gz" ] || curl -s -f -L -o "./virtualenv.tar.gz" "${VIRTUALENV_URL}" || bail_install
tar -zxf "./virtualenv.tar.gz" -C "./.virtualenv-source/" --strip-components=1 && \
[ -d "./.virtualenv-source" ] && (\
cd "./.virtualenv-source" && \
/usr/bin/env python setup.py build > ${LOG} 2>&1 ) \
|| bail_install;
}
bail() {
echo "$@"
exit 1;
}
main "$@"

Wyświetl plik

@ -1,7 +0,0 @@
---
- hosts: all
tasks:
- name: Install openjdk java packages
apt:
name: ["default-jre-headless", "default-jdk-headless", "maven"]

Wyświetl plik

@ -1,14 +0,0 @@
---
- hosts: all
become: true
become_user: piku
tasks:
- name: Make sure the bin directory exists
file: path=~/bin state=directory
- name: Install lein
get_url: url=https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein dest=~/bin/lein
- name: Set lein Executable permissions
file: path=~/bin/lein mode=0755

Wyświetl plik

@ -1,7 +0,0 @@
---
- hosts: all
tasks:
- name: Install nodeenv
apt:
name: ["nodeenv"]

Wyświetl plik

@ -1,21 +0,0 @@
---
- hosts: all
tasks:
- name: Install node packages
apt:
name: ["nodejs", "npm"]
- shell: which nodejs
args:
creates: /usr/sbin/node
register: nodejs_location
- name: Symlink expected node binary name
file:
src: "{{nodejs_location.stdout}}"
dest: /usr/sbin/node
owner: root
group: root
state: link
when: nodejs_location is changed

Wyświetl plik

@ -1,191 +0,0 @@
---
- hosts: all
become: yes
gather_facts: no
pre_tasks:
- name: Install python2 required by Ansible
raw: "( /usr/bin/python --version 2>&1 | grep -c 'Python' > /dev/null ) || ( apt-get update && apt-get -y install python )"
- hosts: all
become: yes
tasks:
- name: Add piku user
user:
name: "{{ piku_user | default('piku', true)}}"
password: !
comment: PaaS access
group: www-data
- name: Install Debian Packages
apt:
pkg: ['bc', 'git', 'build-essential', 'libpcre3-dev', 'zlib1g-dev', 'python', 'python3', 'python3-pip', 'python3-dev', 'python-pip', 'python-setuptools', 'python3-setuptools', 'nginx', 'incron', 'acl']
#, 'python-dev', 'python3', 'python3-virtualenv', 'python3-pip']
update_cache: true
state: present
- name: Install Python packages
pip:
executable: pip3
name: ['setuptools', 'click==7.0', 'virtualenv==15.1.0', 'uwsgi==2.0.15']
register: packages_installed
- shell: which uwsgi
register: uwsgi_location
when: packages_installed is changed
- name: Create uwgsi symlink
file:
src: "{{uwsgi_location.stdout}}"
dest: /usr/local/bin/uwsgi-piku
owner: root
group: root
state: link
when: packages_installed is changed
- name: Install uwsgi dist script
get_url:
url: https://raw.githubusercontent.com/piku/piku/master/uwsgi-piku.dist
dest: /etc/init.d/uwsgi-piku
mode: 0700
when: packages_installed is changed
- name: Install uwsgi-piku dist script
shell: update-rc.d uwsgi-piku defaults
args:
creates: /etc/rc2.d/S01uwsgi-piku
when: packages_installed is changed
- name: Install uwsgi-piku systemd script
get_url:
url: https://raw.githubusercontent.com/piku/piku/master/uwsgi-piku.service
dest: /etc/systemd/system/uwsgi-piku.service
mode: 0600
when: packages_installed is changed
- name: Create piku ansible tmp dir
file:
path: ~piku/.ansible/tmp
mode: 0700
owner: piku
group: www-data
state: directory
- hosts: all
become: yes
become_user: "{{ piku_user | default('piku', true)}}"
tasks:
### TODO: use pyenv like this instead
#- name: Download pyenv installer
# get_url:
# url: https://pyenv.run
# dest: ~/pyenv-installer
# mode: 0755
#- name: Run pyenv installer
# shell:
# argv: ~/pyenv-installer
# creates: ~/.pyenv
#- name: Install python3
# shell: ~/.pyenv/bin/pyenv install 3.6.8
#- name: Use python3
# shell: ~/.pyenv/bin/pyenv local 3.6.8
- name: Fetch piku.py script
get_url:
url: https://raw.githubusercontent.com/piku/piku/master/piku.py
dest: ~/piku.py
mode: 0700
- name: Run piku setup
shell: python3 ~/piku.py setup
args:
creates: ~/.piku
- name: Copy up my SSH key for piku
copy: src=~/.ssh/id_rsa.pub dest=/tmp/id_rsa.pub
- name: Ask piku to use SSH key
shell: python3 ~/piku.py setup:ssh /tmp/id_rsa.pub
args:
creates: ~/.ssh/authorized_keys
- name: Clean temp key
file:
state: absent
path: /tmp/id_rsa.pub
- name: Check if acme.sh is already installed
stat:
path: ~/.acme.sh/acme.sh
register: acme_stat_result
- name: Download acme.sh
get_url:
url: https://raw.githubusercontent.com/Neilpang/acme.sh/6ff3f5d/acme.sh
dest: ~/acme.sh
mode: 0755
when: acme_stat_result.stat.exists == False
register: acme_installer
- name: Execute acme.sh installer
shell: ./acme.sh --install
args:
chdir: ~/
creates: ~/.acme.sh/acme.sh
executable: /bin/bash
when: acme_installer is defined
- name: Remove acme.sh installer
file: path=~/acme.sh state=absent
when: acme_installer is defined
- hosts: all
become: yes
tasks:
- name: Test if systemctl is present
shell: command -v systemctl
register: systemctl
- name: Enable uwsgi-piku service
systemd:
name: uwsgi-piku
enabled: yes
state: started
masked: no
when: '"systemctl" in systemctl.stdout'
- name: Start uwsgi init script
service:
name: uwsgi-piku
state: started
when: '"systemctl" not in systemctl.stdout'
- name: Get nginx default config
get_url:
url: https://raw.githubusercontent.com/piku/piku/master/nginx.default.dist
dest: /etc/nginx/sites-available/default
force: yes
register: nginx_config_installed
- name: Restart nginx service
service:
name: nginx
state: restarted
when: nginx_config_installed is changed
- name: Get incron config
get_url:
url: https://raw.githubusercontent.com/piku/piku/master/incron.dist
dest: /etc/incron.d/piku
register: incron_config_installed
- name: Restart incron service
service:
name: incron
state: restarted
when: incron_config_installed is changed

Wyświetl plik

@ -1,13 +0,0 @@
---
- hosts: all
tasks:
- name: Install postgres
apt:
name: ["postgresql", "python-psycopg2"]
- name: Create piku postgres superuser
become: true
become_user: postgres
postgresql_user:
name: piku
role_attr_flags: SUPERUSER