Skip to content

Commit

Permalink
Pip venv (#9)
Browse files Browse the repository at this point in the history
* virtualenv used by service

* userdel -r

* virtualenv creation

* service

* prompts

* ansible-core in venv

* de-couple

* Kubspray has transitive dependencies

* Ansible must be between 2.16.4 and 2.17.0 exclusive

* unused

* dependencies
  • Loading branch information
bbaassssiiee authored Dec 3, 2024
1 parent a4f26e1 commit 9fb94a2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
3 changes: 0 additions & 3 deletions files/collections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ collections:
- name: community.docker
- name: community.general
- name: community.postgresql
- name: kubernetes.core
- name: https://github.com/kubernetes-sigs/kubespray.git
type: git
1 change: 1 addition & 0 deletions files/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ansible-core<2.17.0
distlib
docker
jmespath
Expand Down
2 changes: 0 additions & 2 deletions provision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
msg: |
run this shell command before this playbook:
read -sp "Enter database password: " DB_PASS && export DB_PASS ; echo
no_log: true
roles:
- role: postgres
Expand Down Expand Up @@ -82,7 +81,6 @@
msg: |
run this shell command before this playbook:
read -sp "Enter ssh key passphrase: " SSH_PASS && export SSH_PASS ; echo
no_log: true
roles:
- role: semaphore
Expand Down
5 changes: 5 additions & 0 deletions roles/semaphore/tasks/absent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
state: absent
force: true

- name: Remove home directory
ansible.builtin.file:
path: /home/semaphore
state: absent

- name: Remove semaphore package
ansible.builtin.package:
name: semaphore
Expand Down
7 changes: 7 additions & 0 deletions roles/semaphore/tasks/present.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@
- requirements.yml
- collections.yml

- name: Create python3.12 venv
become_user: semaphore
ansible.builtin.command: /usr/bin/python3.12 -m venv venv --upgrade-deps
args:
chdir: /home/semaphore
creates: /home/semaphore/venv

- name: Deploy Semaphore Config
become: true
ansible.builtin.template:
Expand Down
18 changes: 13 additions & 5 deletions roles/semaphore/templates/semaphore.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ User=semaphore
Group=semaphore
Environment=LANG="en_US.UTF-8"
Environment=LC_ALL="en_US.UTF-8"
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:~/.local/bin"
ExecStart=/usr/bin/semaphore server --config /etc/semaphore/config.json
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
Expand All @@ -21,10 +20,19 @@ WorkingDirectory=/home/semaphore
StandardOutput=journal
StandardError=journal
SyslogIdentifier=semaphore

# to auto-upgrade python modules at service startup
ExecStartPre=/bin/bash -c 'source /home/semaphore/venv/bin/activate \
&& pip install --upgrade -r /home/semaphore/requirements.txt'

ExecStartPre=/bin/bash -c 'pip3.12 install --upgrade --user -r /home/semaphore/requirements.txt'
ExecStartPre=/bin/bash -c 'ansible-galaxy collection install -p /home/semaphore/tmp/.ansible/collections -r /home/semaphore/collections.yml'
ExecStartPre=/bin/bash -c 'ansible-galaxy install -p /home/semaphore/tmp/.ansible/roles/ -r /home/semaphore/requirements.yml'
# to auto-upgrade ansible collections and roles at service startup
ExecStartPre=/bin/bash -c 'source /home/semaphore/venv/bin/activate \
&& ansible-galaxy collection install -r /home/semaphore/requirements.yml \
&& ansible-galaxy role install -r /home/semaphore/requirements.yml'

# REPLACE THE EXISTING 'ExecStart'
ExecStart=/bin/bash -c 'source /home/semaphore/venv/bin/activate \
&& /usr/bin/semaphore server --config /etc/semaphore/config.json'

[Install]
WantedBy=multi-user.target

0 comments on commit 9fb94a2

Please sign in to comment.