Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from sopel-irc/py3role
Browse files Browse the repository at this point in the history
Implemented Travis CI and used third-party python3 role to support multiple distros.
  • Loading branch information
Duckle29 committed Feb 5, 2019
2 parents 8f9b218 + c2b8c82 commit 37fc30c
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 32 deletions.
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
language: python
services: docker

env:
global:
- ROLE_NAME: sopel
matrix:
# Test defaults.
- MOLECULE_DISTRO: centos7
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: ubuntu1604
- MOLECULE_DISTRO: debian9

install:
# Install test dependencies.
- pip install molecule docker

before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-role-$ROLE_NAME sopel.$ROLE_NAME
- cd sopel.$ROLE_NAME

script:
# Run tests.
- molecule test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
7 changes: 4 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ sopel_config_dir: '/etc/sopel'
sopel_log_dir: '/var/log/sopel'
sopel_pid_dir: '/run/sopel'

sopel_install_systemd_service: yes
sopel_install_systemd_service: true

# The prefix used to call the bot. It's parsed as regex so remember to escape special characters
# The prefix used to call the bot.
# It's parsed as regex so remember to escape special characters
sopel_command_prefix: '\.'

# The nick sopel will present itself as in channels
Expand All @@ -34,4 +35,4 @@ sopel_ignored_hosts:

# Default timezone and time format. http://strftime.org/ for format info
sopel_timezone: 'Europe/Copenhagen'
sopel_time_format: '[%Y-%m-%d - %T %Z]'
sopel_time_format: '[%Y-%m-%d - %T %Z]'
3 changes: 2 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ galaxy_info:
- "bot"
- "networking"

dependencies: []
dependencies:
- "spk83.python3"
14 changes: 14 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
37 changes: 37 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
scenario:
name: default
test_sequence:
- lint
- destroy
- dependency
- syntax
- create
- converge
- idempotence
- destroy

verifier:
name: testinfra
lint:
name: flake8
12 changes: 12 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Converge
hosts: all

vars:
sopel_auth_method: 'nickserv'
sopel_bot_owner: 'testman'
sopel_auth_user: authUser
sopel_auth_pass: authPass

roles:
- role: ansible-sopel
2 changes: 2 additions & 0 deletions molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
- src: spk83.python3
51 changes: 25 additions & 26 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
---

- name: Install python3
become: yes
apt:
name: python3
state: present
update_cache: yes

- name: Install enchant
become: yes
apt:
become: true
package:
name: enchant
state: present

- name: Add universe repository for ubuntu
become: yes
apt_repository:
repo: 'deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release|lower }} universe'
become: true
apt_repository:
repo: >-
deb http://archive.ubuntu.com/ubuntu
{{ ansible_distribution_release|lower }} universe
state: present
when: ansible_distribution_version >= '16.04'
when:
- ansible_os_family == 'Debian'
- ansible_distribution_version >= '16.04'

- name: Install pip3
become: yes
apt:
name: python3-pip
state: present
- name: Install sopel RedHat
become: true
pip:
name: sopel
executable: pip3.6
when: ansible_os_family == 'RedHat'

- name: Install sopel
become: yes
become: true
pip:
name: sopel
executable: pip3
when: ansible_os_family == 'Debian'

- name: Add sopel system user
become: yes
become: true
user:
name: sopel
password: '!'
home: '{{ sopel_install_dir }}'
system: yes
system: true
state: present

- name: Make sopel folders
become: yes
become: true
file:
path: '{{ item }}'
owner: sopel
Expand All @@ -54,15 +53,15 @@
- '{{ sopel_pid_dir }}'

- name: Copy sopel config
become: yes
become: true
template:
owner: sopel
group: sopel
src: templates/sopel.cfg.j2
dest: '{{ sopel_config_dir }}/sopel.cfg'

- name: Add sopel systemd service
become: yes
become: true
template:
owner: sopel
group: sopel
Expand All @@ -71,8 +70,8 @@
when: sopel_install_systemd_service

- name: Start and enable sopel
become: yes
become: true
service:
name: sopel
state: started
enabled: yes
enabled: true
6 changes: 4 additions & 2 deletions templates/sopel.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ After=network.target
Type=simple
User=sopel
PIDFile={{ sopel_pid_dir }}/sopel-sopel.pid
ExecStart=/usr/local/bin/sopel -c /etc/sopel/sopel.cfg
ExecStart=/usr/bin/env sopel -c /etc/sopel/sopel.cfg
Restart=on-failure
RestartPreventExitStatus=2
RestartSec=30
Environment=LC_ALL=en_US.UTF-8
SyslogIdentifier=sopel

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target

0 comments on commit 37fc30c

Please sign in to comment.