From fe54ced45966a5af046ce07eae698ed87aff5ae0 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 25 Apr 2021 23:19:51 +0200 Subject: [PATCH 1/7] Add support for Ubuntu 20.04. --- README.md | 14 ++++++++++---- .../roles/st2_dev/files/generate_stanley_key.sh | 16 ++++++++++++++++ ansible/roles/st2_dev/files/st2_bash_profile.sh | 7 ++++--- ansible/roles/st2_dev/tasks/mongo.yml | 2 +- ansible/roles/st2_dev/tasks/python.yml | 12 ++++++++++-- ansible/roles/st2_dev/tasks/rabbitmq.yml | 4 ++-- ansible/roles/st2_dev/tasks/system.yml | 14 +------------- 7 files changed, 44 insertions(+), 25 deletions(-) create mode 100755 ansible/roles/st2_dev/files/generate_stanley_key.sh diff --git a/README.md b/README.md index f9bb501..56920be 100644 --- a/README.md +++ b/README.md @@ -31,16 +31,22 @@ automatically reflected inside the virtual machine immediately after you make th Note: Make sure to run step 5 (`make requirements`) inside `~/st2` to have the `PYTHONPATH` point to the modules inside `~/st2`. -### Specifying a Python and MongoDB version +### Specifying Distro, Python and MongoDB version -By default, the image is provisioned using Python 3.6 and Mongo DB 4.0. If you want to us Python -3.8 and MongoDB 4.4 you can do that editing corresponding variables in ``Vagrantfile`` before -running ``vagrant up`` / ``vagrant provision``. +By default, the image is provisioned using Python 3.6 and Mongo DB 4.0 on Ubuntu 18.04. + +If you want to use a different distro, Python or MOngoDB version, you can do that by editing +corresponding variables in ``Vagrantfile`` before running ``vagrant up`` / ``vagrant provision``. For example: ```ruby ... +# For Ubuntu 18.04 (default) +VM_BOX = "ubuntu/bionic64" +# For Ubuntu 20.04 +VM_BOX = "ubuntu/focal64" + PYTHON_VERSION = "3.8" MONGODB_VERSION = "4.4" ... diff --git a/ansible/roles/st2_dev/files/generate_stanley_key.sh b/ansible/roles/st2_dev/files/generate_stanley_key.sh new file mode 100755 index 0000000..81ee0f8 --- /dev/null +++ b/ansible/roles/st2_dev/files/generate_stanley_key.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +if [ -f "/home/stanley/.ssh/authorized_keys" ]; then + echo "Key already exists, skipping thos step" + exit 0 +fi + +echo "Generating stanley SSH key" +ssh-keygen -b 2048 -t rsa -f "/home/vagrant/.ssh/stanley_rsa" -q -N "" -m pem +mkdir -p /home/stanley/.ssh +chmod 660 /home/stanley/.ssh +chmod +x /home/stanley/.ssh +cp /home/vagrant/.ssh/stanley_rsa.pub /home/stanley/.ssh/authorized_keys +chmod 660 /home/stanley/.ssh/authorized_keys +chown -R stanley: /home/stanley/.ssh/ +chown -R vagrant: /home/vagrant/.ssh/ diff --git a/ansible/roles/st2_dev/files/st2_bash_profile.sh b/ansible/roles/st2_dev/files/st2_bash_profile.sh index 2568a0a..c1a58ca 100644 --- a/ansible/roles/st2_dev/files/st2_bash_profile.sh +++ b/ansible/roles/st2_dev/files/st2_bash_profile.sh @@ -4,6 +4,7 @@ PRINT_INFO=${PRINT_INFO:-"1"} ST2_SHARE_DIR="/home/vagrant/st2" PYTHON_BINARY_FILE_PATH="/home/vagrant/.st2_python_binary" +DISTRO_NAME=$(lsb_release -c | awk '{print $2}') if [ ! -f "${PYTHON_BINARY_FILE_PATH}" ]; then >&2 echo "${PYTHON_BINARY_FILE_PATH} file doesn't exist. Make sure you ran vagrant provision" @@ -17,9 +18,9 @@ export PYTHON_VERSION=${PYTHON_BINARY_NAME} PYTHON_VERSION_SHORT_STRING=$(${PYTHON_BINARY} --version | sed "s/Python //g" | sed "s/\.//g" | tr -d "\n") -export VIRTUALENV_DIR=virtualenv-py${PYTHON_VERSION_SHORT_STRING} -export VIRTUALENV_ST2CLIENT_DIR=virtualenv-st2client-py${PYTHON_VERSION_SHORT_STRING} -export VIRTUALENV_COMPONENTS_DIR=virtualenv-components-py${PYTHON_VERSION_SHORT_STRING} +export VIRTUALENV_DIR=virtualenv-${DISTRO_NAME}-py${PYTHON_VERSION_SHORT_STRING} +export VIRTUALENV_ST2CLIENT_DIR=virtualenv-st2client-${DISTRO_NAME}-py${PYTHON_VERSION_SHORT_STRING} +export VIRTUALENV_COMPONENTS_DIR=virtualenv-components-${DISTRO_NAME}-py${PYTHON_VERSION_SHORT_STRING} if [ "${PRINT_INFO}" = "1" ]; then echo "" diff --git a/ansible/roles/st2_dev/tasks/mongo.yml b/ansible/roles/st2_dev/tasks/mongo.yml index bc0c625..5dcbe6f 100644 --- a/ansible/roles/st2_dev/tasks/mongo.yml +++ b/ansible/roles/st2_dev/tasks/mongo.yml @@ -10,7 +10,7 @@ mode: 0644 dest: /etc/apt/sources.list.d/mongodb.list content: > - deb https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/{{ mongodb_version }} multiverse + deb https://repo.mongodb.org/apt/ubuntu {{ distro_type }}/mongodb-org/{{ mongodb_version }} multiverse - name: Install mongo become: yes apt: diff --git a/ansible/roles/st2_dev/tasks/python.yml b/ansible/roles/st2_dev/tasks/python.yml index 91bf30a..a2262f4 100644 --- a/ansible/roles/st2_dev/tasks/python.yml +++ b/ansible/roles/st2_dev/tasks/python.yml @@ -17,12 +17,20 @@ - libsasl2-dev - libldap2-dev - libssl-dev +- name: Download pip installer + become: true + get_url: + url: https://bootstrap.pypa.io/get-pip.py + dest: /tmp/ + mode: 0755 +# NOTE: In some version of ansible ansible.builtin.{shell,command} is broken +# https://github.com/ansible/ansible/issues/71817 - name: Install pip become: true - ansible.builtin.shell: curl https://bootstrap.pypa.io/get-pip.py | sudo python{{ python_version }} + command: python{{ python_version }} /tmp/get-pip.py - name: Install virtualenv become: true - ansible.builtin.shell: python{{ python_version }} -m pip install virtualenv + command: python{{ python_version }} -m pip install virtualenv # NOTE: We can't update default python3 binary on the system using update # alternatives since it breaks apt, and a bunch of other system tools which # depends on a specific Python version diff --git a/ansible/roles/st2_dev/tasks/rabbitmq.yml b/ansible/roles/st2_dev/tasks/rabbitmq.yml index 2b0ec93..20f586b 100644 --- a/ansible/roles/st2_dev/tasks/rabbitmq.yml +++ b/ansible/roles/st2_dev/tasks/rabbitmq.yml @@ -15,14 +15,14 @@ mode: 0644 dest: /etc/apt/sources.list.d/rabbitmq-erlang.list content: > - deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu bionic main + deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu {{ distro_type }} main - name: Add RabbitMQ server apt repo list become: yes copy: mode: 0644 dest: /etc/apt/sources.list.d/rabbitmq-server.list content: > - deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ bionic main + deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ {{ distro_type }} main # This step is needed so correct latest versions of erlang packages get installed - name: Install Erlang become: yes diff --git a/ansible/roles/st2_dev/tasks/system.yml b/ansible/roles/st2_dev/tasks/system.yml index 4887222..74154aa 100644 --- a/ansible/roles/st2_dev/tasks/system.yml +++ b/ansible/roles/st2_dev/tasks/system.yml @@ -26,16 +26,4 @@ validate: 'visudo -cf %s' - name: Generate and add SSH key for stanley user for remote actions become: true - ansible.builtin.shell: | - if [ -f "/home/stanley/.ssh/authorized_keys" ]; then - exit 0 - fi - - ssh-keygen -b 2048 -t rsa -f "/home/vagrant/.ssh/stanley_rsa" -q -N "" -m pem - mkdir -p /home/stanley/.ssh - chmod 660 /home/stanley/.ssh - chmod +x /home/stanley/.ssh - cp /home/vagrant/.ssh/stanley_rsa.pub /home/stanley/.ssh/authorized_keys - chmod 660 /home/stanley/.ssh/authorized_keys - chown -R stanley: /home/stanley/.ssh/ - chown -R vagrant: /home/vagrant/.ssh/ + shell: bash /vagrant/ansible/roles/st2_dev/files/generate_stanley_key.sh From 07b7dac5b14f780b016e99d9011bf53667246ce9 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 26 Apr 2021 23:06:11 +0200 Subject: [PATCH 2/7] Add tests for focal to CI. --- .github/workflows/ci.yaml | 15 +++++++++++---- Vagrantfile | 6 +++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dcfd2f8..0f8b6a0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -69,10 +69,16 @@ jobs: fail-fast: false matrix: include: - - name: 'Python 3.6 + MongoDB 4.0' + - name: 'Ubuntu 18.04 + Python 3.6 + MongoDB 4.0' + vm_image: "ubuntu/bionic64" python_version: "3.6" mongodb_version: "4.0" - - name: 'Python 3.8 + MongoDB 4.4' + - name: 'Ubuntu 18.04 + Python 3.8 + MongoDB 4.4' + vm_image: "ubuntu/bionic64" + python_version: "3.8" + mongodb_version: "4.4" + - name: 'Ubuntu 20.04 + Python 3.8 + MongoDB 4.4' + vm_image: "ubuntu/focal64" python_version: "3.8" mongodb_version: "4.4" @@ -83,7 +89,7 @@ jobs: uses: actions/cache@v2 with: path: ~/.vagrant.d/boxes - key: ${{ runner.os }}-vagrant-ubuntu-bionic64 + key: ${{ runner.os }}-vagrant-ubuntu-${{ matrix.vm_image }} restore-keys: | ${{ runner.os }}-vagrant- @@ -95,9 +101,10 @@ jobs: #env: # ANSIBLE_DEBUG: "true" run: | - sed -i".bak" -E -e "s#\.\./st2#/tmp/st2#g" Vagrantfile + sed -i".bak" -E -e "s#ubuntu/bionic64#${{ matrix.vm_image }}#g" Vagrantfile sed -i".bak" -E -e "s#3.6#${{ matrix.python_version }}#g" Vagrantfile sed -i".bak" -E -e "s#4.0#${{ matrix.mongodb_version }}#g" Vagrantfile + sed -i".bak" -E -e "s#\.\./st2#/tmp/st2#g" Vagrantfile cat Vagrantfile vagrant up diff --git a/Vagrantfile b/Vagrantfile index f7f7e67..2031bb7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -13,7 +13,10 @@ MONGODB_VERSION = "4.0" ERLANG_VERSION = "1:23.3.1-1rmq1ppa1~ubuntu18.04.1" RABBITMQ_VERSION = "3.8.14-1" -VM_NAME = "st2-dev-py-" + PYTHON_VERSION.sub(".", "") + "-mongo-" + MONGODB_VERSION.sub(".", "") +# ubuntu/bionic-64 -> bionic, ubuntu/focal64 -> focal +DISTRO_TYPE = VM_BOX.gsub("ubuntu/", "").gsub("64", "") + +VM_NAME = "st2-dev-py-" + PYTHON_VERSION.sub(".", "") + "-mongo-" + MONGODB_VERSION.sub(".", "") + "focal" ANSIBLE_DEBUG = ENV.has_key?('ANSIBLE_DEBUG') ? "vvv" : "" @@ -37,6 +40,7 @@ Vagrant.configure("2") do |config| ansible.playbook = "/vagrant/ansible/main.yml" ansible.verbose = ANSIBLE_DEBUG ansible.extra_vars = { + distro_type: DISTRO_TYPE, python_version: PYTHON_VERSION, mongodb_version: MONGODB_VERSION, rabbitmq_version: RABBITMQ_VERSION, From c3bc3ccdfe11bb69fb0d8bb56ed979d07093a4bb Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 26 Apr 2021 23:32:43 +0200 Subject: [PATCH 3/7] Fix ansible lint. --- ansible/roles/st2_dev/tasks/python.yml | 4 ++-- ansible/roles/st2_dev/tasks/system.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ansible/roles/st2_dev/tasks/python.yml b/ansible/roles/st2_dev/tasks/python.yml index a2262f4..9a99c96 100644 --- a/ansible/roles/st2_dev/tasks/python.yml +++ b/ansible/roles/st2_dev/tasks/python.yml @@ -25,10 +25,10 @@ mode: 0755 # NOTE: In some version of ansible ansible.builtin.{shell,command} is broken # https://github.com/ansible/ansible/issues/71817 -- name: Install pip +- name: Install pip # noqa: no-changed-when become: true command: python{{ python_version }} /tmp/get-pip.py -- name: Install virtualenv +- name: Install virtualenv # noqa: no-changed-when become: true command: python{{ python_version }} -m pip install virtualenv # NOTE: We can't update default python3 binary on the system using update diff --git a/ansible/roles/st2_dev/tasks/system.yml b/ansible/roles/st2_dev/tasks/system.yml index 74154aa..386a0d0 100644 --- a/ansible/roles/st2_dev/tasks/system.yml +++ b/ansible/roles/st2_dev/tasks/system.yml @@ -24,6 +24,6 @@ regexp: '^stanley' line: 'stanley ALL=(ALL) NOPASSWD: ALL' validate: 'visudo -cf %s' -- name: Generate and add SSH key for stanley user for remote actions +- name: Generate and add SSH key for stanley user for remote actions # noqa: no-changed-when become: true - shell: bash /vagrant/ansible/roles/st2_dev/files/generate_stanley_key.sh + command: bash /vagrant/ansible/roles/st2_dev/files/generate_stanley_key.sh From 833b1c63cdd99f17c869bae26d93b08044445ea0 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 26 Apr 2021 23:48:08 +0200 Subject: [PATCH 4/7] Update Vagrantfile. --- Vagrantfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 2031bb7..344994e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,13 +10,18 @@ PYTHON_VERSION = "3.6" # Valid values are 4.0 and 4.4 MONGODB_VERSION = "4.0" -ERLANG_VERSION = "1:23.3.1-1rmq1ppa1~ubuntu18.04.1" -RABBITMQ_VERSION = "3.8.14-1" - # ubuntu/bionic-64 -> bionic, ubuntu/focal64 -> focal DISTRO_TYPE = VM_BOX.gsub("ubuntu/", "").gsub("64", "") -VM_NAME = "st2-dev-py-" + PYTHON_VERSION.sub(".", "") + "-mongo-" + MONGODB_VERSION.sub(".", "") + "focal" +if DISTRO_TYPE == "bionic" + ERLANG_VERSION = "1:23.3.1-1rmq1ppa1~ubuntu18.04.1" +elsif DISTRO_TYPE == "focal" + ERLANG_VERSION = "1:23.3.1-1rmq1ppa1~ubuntu20.04.1" +end + +RABBITMQ_VERSION = "3.8.14-1" + +VM_NAME = "st2-dev-" + DISTRO_TYPE + "-py-" + PYTHON_VERSION.sub(".", "") + "-mongo-" + MONGODB_VERSION.sub(".", "") ANSIBLE_DEBUG = ENV.has_key?('ANSIBLE_DEBUG') ? "vvv" : "" From 444256d0560989c3f9a6268a56bfa2f2da772586 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 26 Apr 2021 23:56:49 +0200 Subject: [PATCH 5/7] Add missing dep. --- ansible/roles/st2_dev/tasks/system.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ansible/roles/st2_dev/tasks/system.yml b/ansible/roles/st2_dev/tasks/system.yml index 386a0d0..85cfec0 100644 --- a/ansible/roles/st2_dev/tasks/system.yml +++ b/ansible/roles/st2_dev/tasks/system.yml @@ -1,9 +1,10 @@ --- -- name: Install st2 system dependencies +- name: Install st2 system and build dependencies become: true apt: state: present name: + - build-essential - libffi-dev - libssl-dev - libxslt1-dev From c976b7cad939931c56d7d9e2888ea574a083fbd9 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 27 Apr 2021 11:37:45 +0200 Subject: [PATCH 6/7] Update verify script. --- scripts/ci/verify-provision.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/ci/verify-provision.sh b/scripts/ci/verify-provision.sh index eea167a..9ae0e2d 100755 --- a/scripts/ci/verify-provision.sh +++ b/scripts/ci/verify-provision.sh @@ -6,6 +6,8 @@ set -e PYTHON_VERSION=$1 MONGODB_VERSION=$2 +lsb_release -a + ls -la /home/vagrant/st2 ls -la /home/vagrant ls -la /home/vagrant/.st2_bash_profile.sh From b8ed6ea7715352e7f80e4218c08b4e2f900430f9 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sat, 1 May 2021 18:02:25 +0200 Subject: [PATCH 7/7] Update erlang versions. --- Vagrantfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 344994e..da477f4 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -14,9 +14,9 @@ MONGODB_VERSION = "4.0" DISTRO_TYPE = VM_BOX.gsub("ubuntu/", "").gsub("64", "") if DISTRO_TYPE == "bionic" - ERLANG_VERSION = "1:23.3.1-1rmq1ppa1~ubuntu18.04.1" + ERLANG_VERSION = "1:23.3.2-1rmq1ppa1~ubuntu18.04.1" elsif DISTRO_TYPE == "focal" - ERLANG_VERSION = "1:23.3.1-1rmq1ppa1~ubuntu20.04.1" + ERLANG_VERSION = "1:23.3.2-1rmq1ppa1~ubuntu20.04.1" end RABBITMQ_VERSION = "3.8.14-1"