From fff1deea44e40795a33f9acc3be82329ffb50b11 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Sun, 14 May 2023 12:35:31 +0200 Subject: [PATCH] [ydlpd] Configure automatic deployment and describe the repository. --- ydlpd.git/deploy.yaml | 66 ++++++++++++++++++++++++++++++++++ ydlpd.git/description | 1 + ydlpd.git/git-daemon-export-ok | 0 ydlpd.git/hooks/post-receive | 13 +++++++ 4 files changed, 80 insertions(+) create mode 100644 ydlpd.git/deploy.yaml create mode 100644 ydlpd.git/description create mode 100644 ydlpd.git/git-daemon-export-ok create mode 100755 ydlpd.git/hooks/post-receive diff --git a/ydlpd.git/deploy.yaml b/ydlpd.git/deploy.yaml new file mode 100644 index 0000000..c1147bc --- /dev/null +++ b/ydlpd.git/deploy.yaml @@ -0,0 +1,66 @@ +# Copyright (c) 2023 Jakub Czajka +# License: GPL-3.0 or later. + +- hosts: servers + vars: + dest: "{{ ansible_local.env.vars.prod_dir }}/ydlpd" + repo: "{{ ansible_local.env.vars.git_home_dir }}/ydlpd.git" + site: ydlpd.conf + tasks: + - name: Install yt-dlp + pip: + name: yt-dlp + extra_args: --break-system-packages + state: latest + become: true + - name: Install fcgiwrap, ffmpeg and nginx + package: + name: + - fcgiwrap + - ffmpeg + - nginx + state: latest + become: true + - name: Create destination directory + file: + path: "{{ dest }}" + state: directory + mode: 0775 + owner: git + group: www-data + become: true + - name: Checkout scripts to the destination directory + command: /usr/bin/git --work-tree={{ dest }} --git-dir={{ repo }} \ + checkout main --force *.sh + become: true + - find: + paths: "{{ dest }}" + file_type: file + patterns: "*.sh" + register: scripts + - name: Make ydlpd scripts executable + file: + path: "{{ item.path }}" + mode: 0744 + owner: www-data + group: www-data + become: true + with_items: "{{ scripts.files }}" + + - name: Checkout site to /etc/nginx/sites-available + command: /usr/bin/git --work-tree=/etc/nginx/sites-available \ + --git-dir={{ repo }} checkout main --force {{ site }} + become: true + - name: Enable site in nginx + shell: envsubst < /etc/nginx/sites-available/{{ site }} \ + > /etc/nginx/sites-enabled/{{ site }} + environment: "{{ ansible_local.env.vars }}" + become: true + - name: Restart fcgiwrap and nginx + service: + name: "{{ item }}" + state: restarted + become: true + with_items: + - fcgiwrap + - nginx diff --git a/ydlpd.git/description b/ydlpd.git/description new file mode 100644 index 0000000..0d3b2de --- /dev/null +++ b/ydlpd.git/description @@ -0,0 +1 @@ +HTTP interface for yt-dlp. diff --git a/ydlpd.git/git-daemon-export-ok b/ydlpd.git/git-daemon-export-ok new file mode 100644 index 0000000..e69de29 diff --git a/ydlpd.git/hooks/post-receive b/ydlpd.git/hooks/post-receive new file mode 100755 index 0000000..c64a663 --- /dev/null +++ b/ydlpd.git/hooks/post-receive @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (c) 2023 Jakub Czajka +# License: GPL-3.0 or later. + +while read old_revision new_revision branch +do + if [ "${branch}" != "refs/heads/main" ] + then + echo "${branch} is not the main branch so not deploying." + exit 0 + fi + sudo /usr/bin/ansible-playbook --connection=local deploy.yaml +done -- 2.39.5