Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e60576b
Add initial droplet creation strategy
Mycobee Nov 16, 2022
2d93a90
Add inventory for runs
Mycobee Nov 16, 2022
683b5bc
Troubleshoot droplet counting conditionals
Mycobee Nov 16, 2022
5d6bac7
Loop through existing droplets and delete
Mycobee Nov 16, 2022
cadd194
Add automated_builder_vps creation
Mycobee Nov 16, 2022
46f1f12
Change ssh key to string
Mycobee Nov 16, 2022
b19bfc8
Create SSH key resource
Mycobee Nov 16, 2022
c8b4821
Create droplet with SSH key id
Mycobee Nov 16, 2022
d1bff22
Create and include delete inventory task
Mycobee Nov 16, 2022
c4b4f82
Change yml formatting
Mycobee Nov 16, 2022
8bb5d9d
Rename VPS per DigitalOcean requirements
Mycobee Nov 16, 2022
c89304b
Add teardown build script
Mycobee Nov 16, 2022
9958676
Add execution permission to teardown script
Mycobee Nov 16, 2022
efd9667
Add local connection and vault password arguments to teardown functio…
Mycobee Nov 16, 2022
4eacbcc
Add correct teardown task
Mycobee Nov 16, 2022
9bad0e9
Remove unnecessary inventory flag
Mycobee Nov 16, 2022
d76bae9
Restructure delete inventory playbook
Mycobee Nov 16, 2022
98e7010
Add VPS_IP variable definition
Mycobee Nov 16, 2022
ce0315e
Create ansible user, allow ssh, and passwordless sudo
Mycobee Nov 17, 2022
b2aca04
Temporarily change droplet size to account for account restrictions
Mycobee Nov 17, 2022
43631c5
Add formatting for localhost and create user block
Mycobee Nov 17, 2022
5e8e9ea
Add community general install
Mycobee Nov 17, 2022
a095947
Restructure tasks to common role
Mycobee Nov 20, 2022
8e3ac54
Refactor vars decryption and encryption paths
Mycobee Nov 20, 2022
d0fceac
Change ssh user for bootstrap play
Mycobee Nov 20, 2022
b928573
Restructure delete inventory play
Mycobee Nov 20, 2022
b97509b
Restructure ansible user authorized_keys copy
Mycobee Nov 20, 2022
011458c
Install VirtualBox keys and repository
Mycobee Nov 20, 2022
28ecdb1
Allow untagged builds for commit pipelines
Mycobee Nov 20, 2022
0559050
Restructure gather build logs task
Mycobee Nov 20, 2022
c436024
Add folder structure for different build types
Mycobee Nov 20, 2022
749a598
Fix broken VPS_IP assignment
Mycobee Nov 21, 2022
8cc5804
Restructure roles for small-resource builds
Mycobee Nov 21, 2022
acbbff3
Remove redundant call of common role
Mycobee Nov 25, 2022
5ccbd25
Restructure small resource build roles
Mycobee Nov 25, 2022
b77702a
Remove redundant cleanup logic and shutdown for loopbacks
Mycobee Nov 25, 2022
e27fa48
Restructure log logic
Mycobee Nov 25, 2022
485e51c
Rename build roles for clarity
Mycobee Nov 26, 2022
977c8fd
Call build VM script main function
Mycobee Nov 26, 2022
18cae24
Remove whitespace
Mycobee Nov 26, 2022
95e0cbb
Refactor source install
Mycobee Nov 27, 2022
0ac041d
Rotate SSH keys after accidental commit
Mycobee Nov 27, 2022
e2a23cb
Change droplet size for tier restrictions
Mycobee Nov 27, 2022
cc8cfab
Rename include gui-build role task
Mycobee Nov 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 36 additions & 32 deletions .github/workflows/run_automated_builder.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
name: Build VMs

---
name: Run automated builder
on: push

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
env:
env:
ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
REPO_URL: ${{ github.repository }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ansible

- name: Run automated builder
run: |
./automated_builder/scripts/run_automated_builder.sh $ANSIBLE_VAULT_PASSWORD

- name: Handle artifacts
if: always()
run: |
./automated_builder/scripts/handle_artifacts.sh $ANSIBLE_VAULT_PASSWORD

- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: logs
path: ./automated_builder/logs/
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ansible

- name: Run automated builder
run: |
./automated_builder/scripts/run_automated_builder.sh $ANSIBLE_VAULT_PASSWORD

- name: Handle artifacts
if: always()
run: |
./automated_builder/scripts/handle_artifacts.sh $ANSIBLE_VAULT_PASSWORD

- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: logs
path: ./automated_builder/logs/

- name: Teardown build
if: always()
run: |
./automated_builder/scripts/teardown_build.sh $ANSIBLE_VAULT_PASSWORD
43 changes: 43 additions & 0 deletions automated_builder/gather_build_logs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
- name: Gather build logs
hosts: vps_runner
gather_facts: false
vars_files:
- ./roles/common/vars/main.yml
- ./roles/common/vars/secrets.yml

tasks:
- name: Get droplet IP
community.digitalocean.digital_ocean_droplet_info:
oauth_token: "{{ DO_API_TOKEN }}"
name: "automated-builder-vps"
delegate_to: localhost
register: automated_builder_vps

- name: Set VPS_IP
set_fact:
VPS_IP: "{{ automated_builder_vps.data[0].networks.v4 | selectattr('type', 'equalto', 'public') | map(attribute='ip_address') | first }}"
delegate_to: localhost

- name: Gather facts
setup:

- name: Copy install_source log
fetch:
src: "/home/ansible/install_source.log"
dest: "./logs/install_source.log"

- name: Check logs
shell: "ls"
register: pwd
delegate_to: 127.0.0.1

- name: Copy gateway_build log
fetch:
src: "/home/ansible/gateway_build.log"
dest: "./logs/gateway_build.log"

- name: Copy workstation_build log
fetch:
src: "/home/ansible/workstation_build.log"
dest: "./logs/workstation_build.log"
22 changes: 22 additions & 0 deletions automated_builder/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Run automated_builder
hosts: vps_runner
gather_facts: false
vars_files:
- ./roles/common/vars/main.yml
- ./roles/common/vars/secrets.yml

tasks:
- name: Include common role
include_role:
name: common

- name: Include headless-build role
include_role:
name: headless-build
when: REF_TYPE != 'tag'

- name: Include gui-build role
include_role:
name: gui-build
when: REF_TYPE == 'tag'
35 changes: 35 additions & 0 deletions automated_builder/roles/common/tasks/bootstrap_vps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: Bootstrap VPS
become: true
vars:
ansible_ssh_user: root

block:
- name: Create ansible user
user:
name: ansible

- name: Create ansible user ssh directory
file:
path: /home/ansible/.ssh
state: directory
owner: ansible
group: ansible
mode: 0700

- name: Copy authorized_keys
copy:
src: /root/.ssh/authorized_keys
dest: /home/ansible/.ssh/authorized_keys
owner: ansible
group: ansible
mode: 0600
remote_src: true

- name: Allow passwordless sudo commands
community.general.sudoers:
name: ansible-passwordless-sudo
state: present
user: ansible
commands: ALL
nopassword: true
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
---
- name: Configure local environment
hosts: 127.0.0.1
connection: local
vars_files:
- ../vars/main.yml
- ../vars/secrets.yml

tasks:
delegate_to: 127.0.0.1
block:
- name: Create local_ssh directory
file:
path: ~/.ssh
Expand Down
22 changes: 22 additions & 0 deletions automated_builder/roles/common/tasks/delete_inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Destroy any existing droplets
hosts: 127.0.0.1
vars_files:
- ../vars/secrets.yml
tasks:
- name: Check for existing inventory
community.digitalocean.digital_ocean_droplet_info:
oauth_token: "{{ DO_API_TOKEN }}"
register: droplets

- name: Count existing droplets
set_fact:
droplet_count: "{{ droplets.data | length }}"

- name: Delete existing droplets
community.digitalocean.digital_ocean_droplet:
state: absent
oauth_token: "{{ DO_API_TOKEN }}"
id: "{{ item.id }}"
loop: "{{ droplets.data }}"
when: droplet_count != "0"
28 changes: 28 additions & 0 deletions automated_builder/roles/common/tasks/generate_inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: Create VPS resource
delegate_to: 127.0.0.1
block:
- name: Create SSH key
community.digitalocean.digital_ocean_sshkey:
oauth_token: "{{ DO_API_TOKEN }}"
name: "Ansible Key"
ssh_pub_key: "{{ SSH_PUBLIC_KEY }}"
state: present
register: public_key

- name: Create automated builder VPS
community.digitalocean.digital_ocean_droplet:
state: present
oauth_token: "{{ DO_API_TOKEN }}"
name: automated-builder-vps
size: s-4vcpu-8gb
region: nyc3
image: debian-11-x64
wait_timeout: 500
ssh_keys: ["{{ public_key.data.ssh_key.id }}"]
project: "Automated Builder"
register: automated_builder_vps

- name: set VPS_IP
set_fact:
VPS_IP: "{{ automated_builder_vps.data.droplet.networks.v4 | selectattr('type', 'equalto', 'public') | map(attribute='ip_address') | first }}"
36 changes: 36 additions & 0 deletions automated_builder/roles/common/tasks/install_dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Install dependencies
become: true
block:
- name: Install apt packages
apt:
pkg:
- git
- time
- curl
- lsof
- apt-cacher-ng
- lsb-release
- fakeroot
- dpkg-dev
- fasttrack-archive-keyring
- dnsutils
- software-properties-common
update_cache: true

- name: Install VirtualBox
include_tasks: install_virtualbox.yml

- name: Register LSB release
shell: "lsb_release -cs"
register: lsb_release

- name: Add VirtualBox apt repository
apt_repository:
repo: "deb [arch=amd64 signed-by=/usr/share/keyrings/{{ VBOX_ASC_KEY.name }}.asc.gpg] http://download.virtualbox.org/virtualbox/debian {{ lsb_release.stdout }} contrib"
state: present

- name: Install VirtualBox apt repository
apt:
name: "virtualbox-6.1"
update_cache: true
18 changes: 18 additions & 0 deletions automated_builder/roles/common/tasks/install_virtualbox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Install VirtualBox
become: true

block:
- name: Import VirtualBox GPG key
get_url:
dest: "/root/{{ VBOX_ASC_KEY.name }}.asc"
url: "{{ VBOX_ASC_KEY.url }}"

- name: Create gpg file
shell: "gpg --dearmor /root/{{ VBOX_ASC_KEY.name }}.asc > {{ VBOX_ASC_KEY.name }}.gpg"

- name: Move gpg key to shared keyrings
copy:
src: "/root/{{ VBOX_ASC_KEY.name }}.asc.gpg"
dest: "/usr/share/keyrings/{{ VBOX_ASC_KEY.name }}.asc.gpg"
remote_src: true
18 changes: 18 additions & 0 deletions automated_builder/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Configure local environment
include_tasks: configure_local_environment.yml

- name: Generate inventory
include_tasks: generate_inventory.yml

- name: Bootstrap VPS
include_tasks: bootstrap_vps.yml

- name: Gather facts
setup:

- name: Install dependencies
include_tasks: install_dependencies.yml

- name: Clean existing VirtualBox VMs
include_tasks: clean_existing_vbox_vms.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
REF_TYPE: "{{ lookup('env', 'GITHUB_REF_TYPE') }}"
GIT_REPO: "{{ lookup('env', 'REPO_URL') }}"
REF_NAME: "{{ lookup('env', 'GITHUB_REF_NAME') }}"
VBOX_ASC_KEY:
name: 'oracle_vbox_2016'
url: 'https://www.virtualbox.org/download/oracle_vbox_2016.asc'
38 changes: 38 additions & 0 deletions automated_builder/roles/common/vars/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
$ANSIBLE_VAULT;1.1;AES256
36613161353462363665326163373733653932646233663737356636623834366566386235313435
3365383733393738383863306661353339653261623533340a343537323738663234306265316238
32646364633136353664356631613436616462343962336264613761366638363364383133386531
3361303831616636340a663839653265353263323766353932333962343235343631653265316665
64613665356538363036666336633633323765326338623637323335613932616536633262356134
30653466336366646162313634326136366364656635303764336263313530373735653239393433
64306236333365303466616263626437363635323037626662613665303834396539306230303530
64383463653663613936626236353936616332383065643962353763313335353665333762313036
37326164663239623233643364383238616134393537316566326165623363323161656435623965
32386138666635323033383036643337663231363164306664366230323763626338366261373335
37643064633734386535393430346564366638303763313165663765646135353737333430396166
30613461343036376163636636353534613039616631313361333363383634643166643363633131
31353437376639356138366662383565663535323833356163373134323934663938333134393466
37383063336338656132376336623437626438316232313736313932646166383735303961636636
62383635653832393030343433333464343935306161373632336338666136323132623036623833
39373663633238623833643734623764313233306533393862653837326462666561366530626135
62333365623336613163633538303765343931346230613231613462653734363566383739646236
31656534613036646233306234336163616638366265643730346533343832613661386433326430
34353964303937373864343433653439643239646630633863333561663266623735326437393532
30636431643636623830643638363831393935616636386138343434353832653065663639363965
30343139303866383130653261323538623033353237623262353463663236613965316631623533
64356239323538616338323265613233666636376634613566643934356661393338343338333734
38333763663366396266663530356361626664663832363232623130383631616530383337343662
39623738386164663666386363653265386338616363373239386265306539346163643866666637
36303161623038376536626432393264613736393032613464643238343837643664386538643564
66386361393835613737363037636630613134333830653036643037343165663332356464623162
35653938653066666432633563393933626437313237383837663038623062363739306635303964
38333939626330396533613133623061343061343635643665393532326361323933646132386464
31383630323362306366366638646432633466393963356232363438353866343665336364656534
32326666653665663566636332366365613061613963376138336164656435386238353437666435
62396134313661336163363838313939326438353232306339313762393964376164613336633663
38353062663266326335633433336639633934333964376665663761636664643563316362313664
37363834656534383330303465313237386264303661393862646532313431323030316331393436
32656230326138663434336561663931633739393435383065363636626563353865616562353966
66303738613332333631333965663934643961633839306466663338656461636634373439646130
36393533316538646664363166303434343738373661393034373738313966663566363462393266
6434
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Install build_vms_from_tag script
template:
src: ../templates/build_vms_from_tag.sh
dest: /home/ansible/build_vms_from_tag.sh
mode: 0744

- name: Run build_vms_from_tag scripts
shell: "/home/ansible/build_vms_from_tag.sh"
9 changes: 9 additions & 0 deletions automated_builder/roles/gui-build/tasks/install_source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Create install_source script
template:
src: ./roles/common/templates/install_source.sh
dest: /home/ansible/install_source.sh
mode: 0744

- name: Run install_source script for tag
shell: "/home/ansible/install_source.sh {{ GIT_REPO }} {{ REF_NAME }} {{ REF_NAME }} > /home/ansible/install_source.log 2>&1"
6 changes: 6 additions & 0 deletions automated_builder/roles/gui-build/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Install source code for commit
include_tasks: install_source.yml

- name: Build VMs from tag
include_tasks: build_vms_from_tag.yml
Loading