Skip to content

Commit

Permalink
Deploy via GitHub Actions (#20)
Browse files Browse the repository at this point in the history
* chore(ci): Lint and test in GitHub Actions

* chore(ci): Error w.r.t. directory

* chore(ci): Interjob dependency

* chore(ci): Fix YAML lint errors

* chore(ci): Fix path to code base for Molecule

* chore(ci): Install playbook dependencies

* chore(ci): Add PHP role to requirements file

* chore(ci): Workaround for idempotence failure

* chore: Change name in license

* chore: Deploy via GitHub Actions

* chore(cd): Fix YAML lint error

Line too long.
  • Loading branch information
geoffreyvanwyk authored Nov 9, 2023
1 parent b2a766b commit 12a9da0
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 36 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
# This file is part of Learning Sandbox Online.
#
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Continuous integration in GitHub Actions that lints the Ansible code and tests
# the playbooks with Molecule.
#
# @copyright 2023 Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
# @see GitHub Actions {@link https://docs.github.com/en/actions}
##

name: Build
"on":
pull_request:
push:
branches:
- master

jobs:
yamllint:
name: YAML Lint
runs-on: ubuntu-latest

steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install test dependencies.
run: pip3 install yamllint

- name: Lint code.
run: yamllint .

ansible-lint:
name: Ansible Lint
needs: yamllint
runs-on: ubuntu-latest

steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install test dependencies.
run: pip3 install ansible-lint

- name: Lint code.
run: ansible-lint .

molecule:
name: Molecule
needs: ansible-lint
runs-on: ubuntu-22.04

steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install test dependencies.
run: pip3 install ansible molecule molecule-plugins[docker] docker

- name: Install playbooks dependencies
run: ansible-galaxy role install --role-file requirements.yml

- name: Run Molecule tests.
run: molecule test
env:
PY_COLORS: "1"
ANSIBLE_FORCE_COLOR: "1"
64 changes: 64 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# This file is part of Learning Sandbox Online.
#
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Continuous delivery in GitHub Actions that runs the Ansible playbooks on the
# public website's servers.
#
# @copyright 2023 Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
# @see GitHub Actions {@link https://docs.github.com/en/actions}
##

name: Deploy
"on":
push:
branches:
- master

jobs:
ansible-playbook:
name: Run playbook
runs-on: ubuntu-22.04

steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install Ansible.
run: pip3 install ansible

- name: Install playbooks dependencies
run: ansible-galaxy role install --role-file requirements.yml

- name: Install SSH key.
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}

- name: Run plays.
run: |
ansible-playbook main.yml
--inventory ${{ secrets.ANSIBLE_INVENTORY }},
--user ${{ secrets.ANSIBLE_USER }}
env:
PY_COLORS: "1"
ANSIBLE_FORCE_COLOR: "1"
7 changes: 7 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
extends: default

rules:
truthy:
allowed-values: ["true", "false", "yes", "no"]
check-keys: true
10 changes: 5 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
# This file is part of Online Learning Sandbox.
# This file is part of Learning Sandbox Online.
#
# Online Learning Sandbox is free software: you can redistribute it
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Online Learning Sandbox is distributed in the hope that it will be
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Online Learning Sandbox. If not, see <https://www.gnu.org/licenses/>.
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Default values for sandbox variables.
#
# @copyright 2023 Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
##

sandbox_environment: production # other values: development
sandbox_environment: production # other values: development

sandbox_name: Learning Sandbox Online
sandbox_domain: learningsandbox.online
Expand Down
16 changes: 10 additions & 6 deletions homepage.playbook.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
# This file is part of Online Learning Sandbox.
# This file is part of Learning Sandbox Online.
#
# Online Learning Sandbox is free software: you can redistribute it
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Online Learning Sandbox is distributed in the hope that it will be
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Online Learning Sandbox. If not, see <https://www.gnu.org/licenses/>.
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Playbook for creating the parent website.
Expand Down Expand Up @@ -49,12 +49,14 @@
- "{{ sandbox_domain }}-ssl.conf"
ansible.builtin.command: a2ensite {{ item }}
changed_when: true
tags:
- molecule-idempotence-notest

- name: Deploy and enable Apache virtualhost configurations for sandbox aliases
- name: Deploy and enable Apache virtualhosts for sandbox aliases
loop: "{{ sandbox_domain_aliases }}"
loop_control:
loop_var: sandbox_domain_alias
ansible.builtin.include_tasks: tasks/deploy_and_enable_sandbox_domain_alias_virtualhosts.yml
ansible.builtin.include_tasks: tasks/deploy_domain_alias_virtualhosts.yml

- name: Enable SSL module for Apache
become: true
Expand All @@ -67,6 +69,8 @@
ansible.builtin.sysvinit:
name: apache2
state: restarted
tags:
- molecule-idempotence-notest

- name: Deploy home page
become: true
Expand Down
10 changes: 5 additions & 5 deletions main.playbook.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
# This file is part of Online Learning Sandbox.
# This file is part of Learning Sandbox Online.
#
# Online Learning Sandbox is free software: you can redistribute it
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Online Learning Sandbox is distributed in the hope that it will be
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Online Learning Sandbox. If not, see <https://www.gnu.org/licenses/>.
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Primary playbook of this project.
Expand All @@ -27,7 +27,7 @@
become: yes
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600 # seconds == 1 hour
cache_valid_time: 3600 # seconds == 1 hour

- name: Install Moodle instances
ansible.builtin.import_playbook: moodle.playbook.yml
Expand Down
8 changes: 4 additions & 4 deletions moodle.playbook.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
# This file is part of Online Learning Sandbox.
# This file is part of Learning Sandbox Online.
#
# Online Learning Sandbox is free software: you can redistribute it
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Online Learning Sandbox is distributed in the hope that it will be
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Online Learning Sandbox. If not, see <https://www.gnu.org/licenses/>.
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Playbook for installing the Moodle instances.
Expand Down
9 changes: 5 additions & 4 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
# This file is part of Online Learning Sandbox.
# This file is part of Learning Sandbox Online.
#
# Online Learning Sandbox is free software: you can redistribute it
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Online Learning Sandbox is distributed in the hope that it will be
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Online Learning Sandbox. If not, see <https://www.gnu.org/licenses/>.
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# List of roles on which this project depends.
#
# @copyright 2023 Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
##

- name: geoffreyvanwyk.php
- name: geoffreyvanwyk.moodle
- name: geerlingguy.certbot
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
# This file is part of Online Learning Sandbox.
# This file is part of Learning Sandbox Online.
#
# Online Learning Sandbox is free software: you can redistribute it
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Online Learning Sandbox is distributed in the hope that it will be
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Online Learning Sandbox. If not, see <https://www.gnu.org/licenses/>.
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Deploy and enable Apache virtual host configuration files.
Expand Down
8 changes: 4 additions & 4 deletions tasks/install_moodle.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
# This file is part of Online Learning Sandbox.
# This file is part of Learning Sandbox Online.
#
# Online Learning Sandbox is free software: you can redistribute it
# Learning Sandbox Online is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Online Learning Sandbox is distributed in the hope that it will be
# Learning Sandbox Online is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Online Learning Sandbox. If not, see <https://www.gnu.org/licenses/>.
# Learning Sandbox Online. If not, see <https://www.gnu.org/licenses/>.

##
# Tasks for installing a particular version of Moodle.
Expand Down
Loading

0 comments on commit 12a9da0

Please sign in to comment.