Skip to content

Commit 44f996e

Browse files
committed
update plugins bundler
1 parent e4019b3 commit 44f996e

3 files changed

Lines changed: 192 additions & 84 deletions

File tree

.github/workflows/cockpit-plugins.yml

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ jobs:
2525
strategy:
2626
fail-fast: false
2727
matrix:
28-
arch:
29-
- amd64
30-
- arm64
28+
include:
29+
- plugin: zfs
30+
arch: amd64
31+
- plugin: zfs
32+
arch: arm64
33+
- plugin: s3
34+
arch: amd64
35+
- plugin: s3
36+
arch: arm64
3137
steps:
3238
- uses: actions/checkout@v4
3339

@@ -46,14 +52,40 @@ jobs:
4652
puts "s3_ref=#{defaults.fetch("terrarium_cockpit_s3_ref")}"
4753
RUBY
4854
55+
- name: Resolve bundle basename
56+
id: bundle
57+
env:
58+
PLUGIN: ${{ matrix.plugin }}
59+
TARGET_ARCH: ${{ matrix.arch }}
60+
run: |
61+
sanitize() {
62+
printf '%s' "$1" | tr -cs 'A-Za-z0-9._-' '-'
63+
}
64+
case "${PLUGIN}" in
65+
zfs) PLUGIN_REF='${{ steps.refs.outputs.zfs_ref }}' ;;
66+
s3) PLUGIN_REF='${{ steps.refs.outputs.s3_ref }}' ;;
67+
esac
68+
PLUGIN_REF_SAFE="$(sanitize "${PLUGIN_REF}")"
69+
BASENAME="cockpit-plugin-${PLUGIN}-${PLUGIN_REF_SAFE}-linux-${TARGET_ARCH}.tar.gz"
70+
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
71+
echo "artifact_name=${BASENAME%.tar.gz}" >> "${GITHUB_OUTPUT}"
72+
4973
- name: Build Cockpit plugin bundle
5074
env:
75+
PLUGIN: ${{ matrix.plugin }}
5176
TARGET_ARCH: ${{ matrix.arch }}
52-
ZFS_REPO: ${{ steps.refs.outputs.zfs_repo }}
53-
ZFS_REF: ${{ steps.refs.outputs.zfs_ref }}
54-
S3_REPO: ${{ steps.refs.outputs.s3_repo }}
55-
S3_REF: ${{ steps.refs.outputs.s3_ref }}
77+
BUNDLE_BASENAME: ${{ steps.bundle.outputs.basename }}
5678
run: |
79+
case "${PLUGIN}" in
80+
zfs)
81+
PLUGIN_REPO='${{ steps.refs.outputs.zfs_repo }}'
82+
PLUGIN_REF='${{ steps.refs.outputs.zfs_ref }}'
83+
;;
84+
s3)
85+
PLUGIN_REPO='${{ steps.refs.outputs.s3_repo }}'
86+
PLUGIN_REF='${{ steps.refs.outputs.s3_ref }}'
87+
;;
88+
esac
5789
mkdir -p release-assets
5890
chmod +x scripts/build-cockpit-plugins-bundle.sh
5991
docker run --rm \
@@ -62,26 +94,37 @@ jobs:
6294
-w /workspace \
6395
ubuntu:24.04 \
6496
bash -lc "./scripts/build-cockpit-plugins-bundle.sh \
65-
--output /workspace/release-assets/terrarium-cockpit-plugins-linux-${TARGET_ARCH}.tar.gz \
66-
--zfs-repo ${ZFS_REPO@Q} \
67-
--zfs-ref ${ZFS_REF@Q} \
68-
--s3-repo ${S3_REPO@Q} \
69-
--s3-ref ${S3_REF@Q}"
97+
--plugin ${PLUGIN@Q} \
98+
--output /workspace/release-assets/${BUNDLE_BASENAME} \
99+
--repo ${PLUGIN_REPO@Q} \
100+
--ref ${PLUGIN_REF@Q}"
70101
71102
- uses: actions/upload-artifact@v4
72103
with:
73-
name: cockpit-plugins-${{ matrix.arch }}
74-
path: release-assets/terrarium-cockpit-plugins-linux-${{ matrix.arch }}.tar.gz
104+
name: ${{ steps.bundle.outputs.artifact_name }}
105+
path: release-assets/${{ steps.bundle.outputs.basename }}
75106
if-no-files-found: error
76107

77108
publish:
78109
runs-on: ubuntu-24.04
79110
needs: build
80111
steps:
112+
- uses: actions/checkout@v4
113+
81114
- uses: actions/download-artifact@v4
82115
with:
83116
path: artifacts
84117

118+
- name: Resolve pinned plugin refs
119+
id: refs
120+
run: |
121+
ruby <<'RUBY' >> "${GITHUB_OUTPUT}"
122+
require "yaml"
123+
defaults = YAML.load_file("ansible/roles/cockpit_plugins/defaults/main.yml")
124+
puts "zfs_ref=#{defaults.fetch("terrarium_cockpit_zfs_ref")}"
125+
puts "s3_ref=#{defaults.fetch("terrarium_cockpit_s3_ref")}"
126+
RUBY
127+
85128
- name: Resolve publish ref
86129
id: ref
87130
env:
@@ -96,16 +139,29 @@ jobs:
96139
fi
97140
98141
- name: Prepare release assets
142+
env:
143+
ZFS_REF: ${{ steps.refs.outputs.zfs_ref }}
144+
S3_REF: ${{ steps.refs.outputs.s3_ref }}
99145
run: |
146+
sanitize() {
147+
printf '%s' "$1" | tr -cs 'A-Za-z0-9._-' '-'
148+
}
149+
ZFS_REF_SAFE="$(sanitize "${ZFS_REF}")"
150+
S3_REF_SAFE="$(sanitize "${S3_REF}")"
100151
mkdir -p release-assets
101-
cp artifacts/cockpit-plugins-amd64/terrarium-cockpit-plugins-linux-amd64.tar.gz release-assets/
102-
cp artifacts/cockpit-plugins-arm64/terrarium-cockpit-plugins-linux-arm64.tar.gz release-assets/
152+
for BASENAME in \
153+
"cockpit-plugin-zfs-${ZFS_REF_SAFE}-linux-amd64.tar.gz" \
154+
"cockpit-plugin-zfs-${ZFS_REF_SAFE}-linux-arm64.tar.gz" \
155+
"cockpit-plugin-s3-${S3_REF_SAFE}-linux-amd64.tar.gz" \
156+
"cockpit-plugin-s3-${S3_REF_SAFE}-linux-arm64.tar.gz"
157+
do
158+
cp "artifacts/${BASENAME%.tar.gz}/${BASENAME}" "release-assets/${BASENAME}"
159+
done
103160
104161
- name: Publish plugin bundles
105162
uses: softprops/action-gh-release@v2
106163
with:
107164
tag_name: ${{ steps.ref.outputs.value }}
108165
files: |
109-
release-assets/terrarium-cockpit-plugins-linux-amd64.tar.gz
110-
release-assets/terrarium-cockpit-plugins-linux-arm64.tar.gz
166+
release-assets/*.tar.gz
111167
prerelease: ${{ steps.ref.outputs.value == 'cockpit-plugins-main' || contains(steps.ref.outputs.value, '-') }}

ansible/roles/cockpit_plugins/tasks/main.yml

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
)
3939
}}
4040
41+
- name: Compute sanitized Cockpit plugin refs
42+
ansible.builtin.set_fact:
43+
terrarium_cockpit_zfs_ref_safe: "{{ terrarium_cockpit_zfs_ref | regex_replace('[^A-Za-z0-9._-]+', '-') }}"
44+
terrarium_cockpit_s3_ref_safe: "{{ terrarium_cockpit_s3_ref | regex_replace('[^A-Za-z0-9._-]+', '-') }}"
45+
46+
- name: Compute versioned Cockpit plugin bundle filenames
47+
ansible.builtin.set_fact:
48+
terrarium_cockpit_zfs_bundle_filename: >-
49+
cockpit-plugin-zfs-{{ terrarium_cockpit_zfs_ref_safe }}-linux-{{ terrarium_cockpit_plugin_bundle_arch }}.tar.gz
50+
terrarium_cockpit_s3_bundle_filename: >-
51+
cockpit-plugin-s3-{{ terrarium_cockpit_s3_ref_safe }}-linux-{{ terrarium_cockpit_plugin_bundle_arch }}.tar.gz
52+
4153
- name: Check cockpit-zfs install
4254
ansible.builtin.stat:
4355
path: /usr/share/cockpit/zfs/index.html
@@ -48,41 +60,71 @@
4860
path: /usr/share/cockpit/cockpit-s3-browser/index.html
4961
register: terrarium_cockpit_s3_installed
5062

51-
- name: Download prebuilt Cockpit plugin bundle
63+
- name: Download prebuilt cockpit-zfs bundle
5264
ansible.builtin.get_url:
53-
url: "https://github.com/{{ terrarium_cockpit_plugin_bundle_repo }}/releases/download/{{ terrarium_cockpit_plugin_bundle_ref }}/terrarium-cockpit-plugins-linux-{{ terrarium_cockpit_plugin_bundle_arch }}.tar.gz"
54-
dest: "/tmp/terrarium-cockpit-plugins-{{ terrarium_cockpit_plugin_bundle_ref }}-{{ terrarium_cockpit_plugin_bundle_arch }}.tar.gz"
65+
url: "https://github.com/{{ terrarium_cockpit_plugin_bundle_repo }}/releases/download/{{ terrarium_cockpit_plugin_bundle_ref }}/{{ terrarium_cockpit_zfs_bundle_filename }}"
66+
dest: "/tmp/{{ terrarium_cockpit_plugin_bundle_ref }}-{{ terrarium_cockpit_zfs_bundle_filename }}"
5567
mode: "0644"
56-
register: terrarium_cockpit_plugin_bundle_download
68+
register: terrarium_cockpit_zfs_bundle_download
5769
failed_when: false
5870
when:
5971
- terrarium_cockpit_plugin_bundle_enabled
6072
- terrarium_cockpit_plugin_bundle_arch | length > 0
6173
- terrarium_cockpit_plugin_bundle_ref | length > 0
6274

63-
- name: Determine whether prebuilt Cockpit plugin bundle is usable
75+
- name: Download prebuilt cockpit-s3 bundle
76+
ansible.builtin.get_url:
77+
url: "https://github.com/{{ terrarium_cockpit_plugin_bundle_repo }}/releases/download/{{ terrarium_cockpit_plugin_bundle_ref }}/{{ terrarium_cockpit_s3_bundle_filename }}"
78+
dest: "/tmp/{{ terrarium_cockpit_plugin_bundle_ref }}-{{ terrarium_cockpit_s3_bundle_filename }}"
79+
mode: "0644"
80+
register: terrarium_cockpit_s3_bundle_download
81+
failed_when: false
82+
when:
83+
- terrarium_cockpit_plugin_bundle_enabled
84+
- terrarium_cockpit_plugin_bundle_arch | length > 0
85+
- terrarium_cockpit_plugin_bundle_ref | length > 0
86+
87+
- name: Determine whether prebuilt cockpit-zfs bundle is usable
88+
ansible.builtin.set_fact:
89+
terrarium_cockpit_zfs_bundle_usable: >-
90+
{{
91+
terrarium_cockpit_zfs_bundle_download is defined
92+
and terrarium_cockpit_zfs_bundle_download is succeeded
93+
and terrarium_cockpit_zfs_bundle_download.dest is defined
94+
}}
95+
96+
- name: Determine whether prebuilt cockpit-s3 bundle is usable
6497
ansible.builtin.set_fact:
65-
terrarium_cockpit_plugin_bundle_usable: >-
98+
terrarium_cockpit_s3_bundle_usable: >-
6699
{{
67-
terrarium_cockpit_plugin_bundle_download is defined
68-
and terrarium_cockpit_plugin_bundle_download is succeeded
69-
and terrarium_cockpit_plugin_bundle_download.dest is defined
100+
terrarium_cockpit_s3_bundle_download is defined
101+
and terrarium_cockpit_s3_bundle_download is succeeded
102+
and terrarium_cockpit_s3_bundle_download.dest is defined
70103
}}
71104
72-
- name: Install prebuilt Cockpit plugin bundle
105+
- name: Install prebuilt cockpit-zfs bundle
106+
ansible.builtin.unarchive:
107+
src: "{{ terrarium_cockpit_zfs_bundle_download.dest }}"
108+
dest: /
109+
remote_src: true
110+
when:
111+
- terrarium_cockpit_zfs_bundle_usable | default(false)
112+
- terrarium_cockpit_zfs_bundle_download.changed or not terrarium_cockpit_zfs_installed.stat.exists
113+
114+
- name: Install prebuilt cockpit-s3 bundle
73115
ansible.builtin.unarchive:
74-
src: "{{ terrarium_cockpit_plugin_bundle_download.dest }}"
116+
src: "{{ terrarium_cockpit_s3_bundle_download.dest }}"
75117
dest: /
76118
remote_src: true
77119
when:
78-
- terrarium_cockpit_plugin_bundle_usable | default(false)
79-
- terrarium_cockpit_plugin_bundle_download.changed or not terrarium_cockpit_zfs_installed.stat.exists or not terrarium_cockpit_s3_installed.stat.exists
120+
- terrarium_cockpit_s3_bundle_usable | default(false)
121+
- terrarium_cockpit_s3_bundle_download.changed or not terrarium_cockpit_s3_installed.stat.exists
80122

81123
- name: Install cockpit plugin build dependencies
82124
ansible.builtin.apt:
83125
name: "{{ terrarium_cockpit_plugin_build_deps }}"
84126
state: present
85-
when: not (terrarium_cockpit_plugin_bundle_usable | default(false))
127+
when: not (terrarium_cockpit_zfs_bundle_usable | default(false)) or not (terrarium_cockpit_s3_bundle_usable | default(false))
86128

87129
- name: Enable corepack for yarn-managed builds
88130
ansible.builtin.shell: |
@@ -92,14 +134,14 @@
92134
args:
93135
executable: /bin/bash
94136
changed_when: false
95-
when: not (terrarium_cockpit_plugin_bundle_usable | default(false))
137+
when: not (terrarium_cockpit_zfs_bundle_usable | default(false)) or not (terrarium_cockpit_s3_bundle_usable | default(false))
96138

97139
- name: Ensure plugin source directory exists
98140
ansible.builtin.file:
99141
path: /usr/local/src
100142
state: directory
101143
mode: "0755"
102-
when: not (terrarium_cockpit_plugin_bundle_usable | default(false))
144+
when: not (terrarium_cockpit_zfs_bundle_usable | default(false)) or not (terrarium_cockpit_s3_bundle_usable | default(false))
103145

104146
- name: Checkout cockpit-zfs source
105147
ansible.builtin.git:
@@ -108,7 +150,7 @@
108150
version: "{{ terrarium_cockpit_zfs_ref }}"
109151
force: true
110152
register: terrarium_cockpit_zfs_checkout
111-
when: not (terrarium_cockpit_plugin_bundle_usable | default(false))
153+
when: not (terrarium_cockpit_zfs_bundle_usable | default(false))
112154

113155
- name: Build and install cockpit-zfs
114156
ansible.builtin.shell: |
@@ -119,7 +161,7 @@
119161
chdir: /usr/local/src/cockpit-zfs
120162
executable: /bin/bash
121163
when:
122-
- not (terrarium_cockpit_plugin_bundle_usable | default(false))
164+
- not (terrarium_cockpit_zfs_bundle_usable | default(false))
123165
- terrarium_cockpit_zfs_checkout.changed or not terrarium_cockpit_zfs_installed.stat.exists
124166

125167
- name: Checkout cockpit-S3ObjectBroswer source
@@ -129,7 +171,7 @@
129171
version: "{{ terrarium_cockpit_s3_ref }}"
130172
force: true
131173
register: terrarium_cockpit_s3_checkout
132-
when: not (terrarium_cockpit_plugin_bundle_usable | default(false))
174+
when: not (terrarium_cockpit_s3_bundle_usable | default(false))
133175

134176
- name: Build and install cockpit-S3ObjectBroswer
135177
ansible.builtin.shell: |
@@ -140,7 +182,7 @@
140182
chdir: /usr/local/src/cockpit-S3ObjectBroswer
141183
executable: /bin/bash
142184
when:
143-
- not (terrarium_cockpit_plugin_bundle_usable | default(false))
185+
- not (terrarium_cockpit_s3_bundle_usable | default(false))
144186
- terrarium_cockpit_s3_checkout.changed or not terrarium_cockpit_s3_installed.stat.exists
145187

146188
- name: Restart cockpit socket after plugin install

0 commit comments

Comments
 (0)