From b7cd1ce78e0f36cb832fa040b422d9435080c5e2 Mon Sep 17 00:00:00 2001 From: James Pace Date: Tue, 9 Aug 2022 21:56:28 -0400 Subject: [PATCH] Add deployment implementation. --- Jenkinsfile | 47 +++++++++++++++ debian/changelog | 4 +- debian/control | 2 +- playbooks/build.yaml | 124 +++++++++++++++++++++++++++++++++++++++ playbooks/inventory.yaml | 5 ++ 5 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 Jenkinsfile create mode 100644 playbooks/build.yaml create mode 100644 playbooks/inventory.yaml diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..af99f48 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,47 @@ +pipeline { + agent any + + options + { + skipDefaultCheckout(true) + } + stages + { + stage('Checkout') + { + steps + { + cleanWs() + checkout scm + } + } + stage('Run') + { + steps + { + sh 'ansible-playbook -vvvv --skip-tags cleanup,deploy -i ./playbooks/inventory.yaml ./playbooks/build.yaml' + } + } + stage('Deploy') + { + when + { + expression + { + currentBuild.result == null || currentBuild.result == 'SUCCESS' + } + } + steps + { + sh 'ansible-playbook --tags deploy -i ./playbooks/inventory.yaml ./playbooks/build.yaml' + } + } + } + post + { + always + { + sh 'ansible-playbook --tags cleanup -i ./playbooks/inventory.yaml ./playbooks/build.yaml' + } + } +} diff --git a/debian/changelog b/debian/changelog index a591f84..3b08a3f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,5 @@ -j7s-mosquitto-plugin (0.0.7-1) unstable; urgency=medium +j7s-mosquitto-plugin (0.0.7-1) stable; urgency=medium * New release. - -- James Pace Fri, 15 Apr 2022 01:53:50 +0000 + -- James Pace Tues, 09 August 2022 01:53:50 +0000 diff --git a/debian/control b/debian/control index 35a77e7..f323767 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Section: misc Priority: optional Package: j7s-mosquitto-plugin -Architecture: any +Architecture: amd64 Depends: ${shlibs:Depends}, ${misc:Depends} Description: Authentication plugin for mosquitto for the j7s project. Authentication plugin for mosquitto for the j7s project. diff --git a/playbooks/build.yaml b/playbooks/build.yaml new file mode 100644 index 0000000..e0b9622 --- /dev/null +++ b/playbooks/build.yaml @@ -0,0 +1,124 @@ +--- +- name: Setup container for building. + hosts: localhost + tasks: + - name: Create a container + containers.podman.podman_container: + name: j7s-mosquitto-debian-builder + image: docker.io/library/debian:bullseye + volume: "{{ playbook_dir }}/..:/work/src:Z" + command: 'sleep infinity' + state: started + - name: Add the container to inventory. + ansible.builtin.add_host: + name: j7s-mosquitto-debian-builder + ansible_connection: containers.podman.podman + ansible_user: root + ansible_python_interpreter: /usr/bin/python3 + changed_when: false + - name: Set the container up for normal ansible stuff. + delegate_to: j7s-mosquitto-debian-builder + raw: bash -c "apt update && apt install -y python3" + +- name: Setup build environment. + hosts: j7s-mosquitto-debian-builder + become: true + tasks: + - name: Update cache + ansible.builtin.apt: + update_cache: true + - name: Install build dependencies. + ansible.builtin.apt: + package: + - build-essential + - cmake + - dh-cmake + - mosquitto-dev + - libmosquitto-dev + - libssl-dev + - libyaml-cpp-dev + - fakeroot + - devscripts + - debhelper + state: latest + +- name: Build package. + hosts: j7s-mosquitto-debian-builder + tasks: + - name: Call debuild. + ansible.builtin.shell: + chdir: "/work/src" + cmd: ls && debuild -us -uc -b + - name: Copy deb file back to the main directory. + ansible.builtin.shell: + cmd: "cp -r /work/*.deb /work/src/." + - name: Copy changes file back to the main directory. + ansible.builtin.shell: + cmd: "cp -r /work/*.changes /work/src/." + - name: Copy buildinfo file back to the main directory. + ansible.builtin.shell: + cmd: "cp -r /work/*.buildinfo /work/src/." + +- name: Upload to packaging server. + hosts: packaging + tags: deploy + tasks: + - name: Copy package to packaging server. + ansible.builtin.copy: + src: "{{ item }}" + dest: ~/public/apt/mini-dinstall/incoming/ + with_fileglob: ../j7s-*.deb + register: copied_files + - name: Fail if we didn't copy exactly two files. (debug and normal) + ansible.builtin.fail: + msg: "Didn't find exactly two deb file." + when: copied_files.results | length != 2 + - name: Ditto the changes file. + ansible.builtin.copy: + src: "{{ item }}" + dest: ~/public/apt/mini-dinstall/incoming/ + with_fileglob: ../j7s-*.changes + register: copied_changes + - name: Fail if we didn't copy exactly one file. + ansible.builtin.fail: + msg: "Didn't find exactly one changes file." + when: copied_changes.results | length != 1 + - name: Ditto the buildinfo file. + ansible.builtin.copy: + src: "{{ item }}" + dest: ~/public/apt/mini-dinstall/incoming/ + with_fileglob: ../j7s-*.buildinfo + register: copied_buildinfo + - name: Fail if we didn't copy exactly one file. + ansible.builtin.fail: + msg: "Didn't find exactly one buildinfo file." + when: copied_buildinfo.results | length != 1 + - name: Run mini-dinstall. + ansible.builtin.shell: + cmd: "mini-dinstall --batch" + - name: wait dinstall to do its thing + ansible.builtin.pause: + seconds: 3 + +- name: Build and push image. + hosts: localhost + tags: deploy + tasks: + - name: Build and push image. + containers.podman.podman_image: + name: j7s-mosquitto + tag: latest + force: true + path: .. + push: yes + push_args: + dest: registry.jpace121.net + +- name: Cleanup + hosts: localhost + tags: cleanup + tasks: + - name: Stop the container. + containers.podman.podman_container: + name: j7s-mosquitto-debian-builder + state: absent \ No newline at end of file diff --git a/playbooks/inventory.yaml b/playbooks/inventory.yaml new file mode 100644 index 0000000..981dadc --- /dev/null +++ b/playbooks/inventory.yaml @@ -0,0 +1,5 @@ +all: + hosts: + packaging: + ansible_host: packages.jpace121.net + ansible_user: packaging \ No newline at end of file