From 72cb7a9b16f9d32d05aed847a8c85ca76e0f5e18 Mon Sep 17 00:00:00 2001 From: Chris McCormick Date: Thu, 23 Sep 2021 12:40:28 +0800 Subject: [PATCH 1/2] Remove piku-bootstrap in favour of standalone repo. See #199 where @rcarmo asked for this. Fixes #166. Fixes #168. Fixes #206 --- README.md | 42 +------- piku-bootstrap | 181 ----------------------------------- playbooks/java-openjdk.yml | 7 -- playbooks/lein.yml | 14 --- playbooks/nodeenv.yml | 7 -- playbooks/nodejs.yml | 21 ---- playbooks/piku.yml | 191 ------------------------------------- playbooks/postgres.yml | 13 --- 8 files changed, 2 insertions(+), 474 deletions(-) delete mode 100755 piku-bootstrap delete mode 100644 playbooks/java-openjdk.yml delete mode 100644 playbooks/lein.yml delete mode 100644 playbooks/nodeenv.yml delete mode 100644 playbooks/nodejs.yml delete mode 100644 playbooks/piku.yml delete mode 100644 playbooks/postgres.yml diff --git a/README.md b/README.md index 92e5947..bcffc2f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/piku-bootstrap b/piku-bootstrap deleted file mode 100755 index 4117bb8..0000000 --- a/piku-bootstrap +++ /dev/null @@ -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 "$@" diff --git a/playbooks/java-openjdk.yml b/playbooks/java-openjdk.yml deleted file mode 100644 index 31ad050..0000000 --- a/playbooks/java-openjdk.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- hosts: all - tasks: - - name: Install openjdk java packages - apt: - name: ["default-jre-headless", "default-jdk-headless", "maven"] - diff --git a/playbooks/lein.yml b/playbooks/lein.yml deleted file mode 100644 index 16c6f0c..0000000 --- a/playbooks/lein.yml +++ /dev/null @@ -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 - diff --git a/playbooks/nodeenv.yml b/playbooks/nodeenv.yml deleted file mode 100644 index c539cb6..0000000 --- a/playbooks/nodeenv.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- hosts: all - tasks: - - name: Install nodeenv - apt: - name: ["nodeenv"] - diff --git a/playbooks/nodejs.yml b/playbooks/nodejs.yml deleted file mode 100644 index e7ddbb3..0000000 --- a/playbooks/nodejs.yml +++ /dev/null @@ -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 - diff --git a/playbooks/piku.yml b/playbooks/piku.yml deleted file mode 100644 index fa2be63..0000000 --- a/playbooks/piku.yml +++ /dev/null @@ -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 diff --git a/playbooks/postgres.yml b/playbooks/postgres.yml deleted file mode 100644 index 6fa7189..0000000 --- a/playbooks/postgres.yml +++ /dev/null @@ -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 From e9e8c7cdc1096b5a2a94bdf126d8488a907d9668 Mon Sep 17 00:00:00 2001 From: Chris McCormick Date: Thu, 23 Sep 2021 12:43:59 +0800 Subject: [PATCH 2/2] Update postgres example README with new bootstrap. --- examples/python-postgres/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/python-postgres/README.md b/examples/python-postgres/README.md index 30091a5..2297c2b 100644 --- a/examples/python-postgres/README.md +++ b/examples/python-postgres/README.md @@ -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: