Skip to content

Commit

Permalink
Revert "Fix snap to support cryptography module"
Browse files Browse the repository at this point in the history
This reverts commit 27db9dd.
  • Loading branch information
dosaboy committed Mar 12, 2023
1 parent f244dd4 commit bacceb7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 182 deletions.
Binary file removed .github/workflows/fake_data_root/ssl-cert.xz
Binary file not shown.
63 changes: 4 additions & 59 deletions .github/workflows/snapfunctionaltest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
run: |
sudo snap install --dangerous --classic ${{ steps.snapcraft.outputs.snap }}
- name: Run snap (functional test)
run: hotsos | tee output.yaml
run: hotsos > output.yaml
- name: Run snap (JSON output)
run: hotsos --format json tests/unit/fake_data_root/openstack | tee output.json
run: hotsos --format json tests/unit/fake_data_root/openstack > output.json
- name: Run snap (HTML output)
run: hotsos --format html tests/unit/fake_data_root/openstack | tee output.html
run: hotsos --format html tests/unit/fake_data_root/openstack > output.html
- name: Run snap (Markdown output)
run: hotsos --format markdown tests/unit/fake_data_root/openstack | tee output.md
run: hotsos --format markdown tests/unit/fake_data_root/openstack > output.md
- name: Upload snap
uses: actions/upload-artifact@v3
with:
Expand All @@ -40,58 +40,3 @@ jobs:
name: functional-test-outputs
path: output.*

ssl-test-on-focal:
runs-on: ubuntu-20.04
needs: [snap]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
id: snap
with:
name: snap
- name: Install snap
run: |
sudo snap install --dangerous --classic ${{ steps.snap.outputs.download-path }}/*.snap
- name: Install faketime
run: |
DEBIAN_FRONTEND=noninteractive sudo apt update
DEBIAN_FRONTEND=noninteractive sudo apt install --yes --no-install-recommends faketime
- name: Run snap
run: |
tar -xJf .github/workflows/fake_data_root/ssl-cert.xz
faketime '2024-01-01' hotsos --openstack --format yaml ssl-cert | tee output.yaml
grep "The following certificates will expire in less than 60 days: ssl-cert/etc/apache2/ssl/keystone/cert_10.5.1.45" output.yaml
- name: Upload outputs
uses: actions/upload-artifact@v3
if: always()
with:
name: focal-ssl-test
path: output.*

ssl-test-on-jammy:
runs-on: ubuntu-22.04
needs: [snap]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
id: snap
with:
name: snap
- name: Install snap
run: |
sudo snap install --dangerous --classic ${{ steps.snap.outputs.download-path }}/*.snap
- name: Install faketime
run: |
DEBIAN_FRONTEND=noninteractive sudo apt update
DEBIAN_FRONTEND=noninteractive sudo apt install --yes --no-install-recommends faketime
- name: Run snap
run: |
tar -xJf .github/workflows/fake_data_root/ssl-cert.xz
faketime '2024-01-01' hotsos --openstack --format yaml ssl-cert | tee output.yaml
grep "The following certificates will expire in less than 60 days: ssl-cert/etc/apache2/ssl/keystone/cert_10.5.1.45" output.yaml
- name: Upload outputs
uses: actions/upload-artifact@v3
if: always()
with:
name: jammy-ssl-test
path: output.*
14 changes: 9 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
click
cryptography
fasteners
jinja2
progress
propertree
pyyaml
searchkit
simplejson
jinja2
# Pin to cryptography==3.4.8 since the cryptography-3.4.x branch is the
# last branch that can be built without the Rust toolchain.
# More info on issue: https://github.com/canonical/hotsos/issues/326
# [TODO] Bump cryptography to more recent release
cryptography==3.4.8
searchkit
propertree
fasteners
153 changes: 35 additions & 118 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ description:
common Cloud applications.
confinement: classic
grade: stable
base: core22
base: core20
environment:
LANG: C.UTF-8
REPO_INFO_PATH: $SNAP/repo-info
LC_ALL: C.UTF-8
PYTHONHOME: ${SNAP}/usr
PYTHONPATH: ${SNAP}/usr/lib/python3.10:${SNAP}/lib/python3.10/site-packages
REPO_INFO_PATH: ${SNAP}/repo-info
LANG: C.UTF-8
PYTHONPATH: $SNAP/lib/python3.8/site-packages

# dpkg won't work without this
layout:
Expand All @@ -25,126 +24,44 @@ layout:
apps:
hotsos:
command: bin/hotsos

parts:
hotsos:
hotsos-cli:
plugin: dump
source: .
build-packages:
- git
- python3-pip
- python3-venv
- rsync
override-build: |
rm -rf tests
git rev-parse --short HEAD > repo-info
snapcraftctl build
organize:
defs: etc/hotsos/defs
templates: etc/hotsos/templates
build-packages: [git]
hotsos:
plugin: python
source: .
stage-packages:
- bsdmainutils
- coreutils
- dpkg
- libc6
- libpython3.10-minimal
- libpython3.10-stdlib
- python3.10-minimal
- systemd
override-build: |
PYTHON=python3.10
# In case we are debugging this snap and are running the build stage
# multiple times (as in `snapcraft build --shell`), we have to guard
# against running `venv` multiple times.
if [[ ! -x ${SNAPCRAFT_PART_INSTALL}/bin/activate ]]; then
/usr/bin/python3 -m venv ${SNAPCRAFT_PART_INSTALL}
fi
# Do not source `activate` so that consecutive rebuilding the snap (for
# debugging) works.
${SNAPCRAFT_PART_INSTALL}/bin/pip install wheel
${SNAPCRAFT_PART_INSTALL}/bin/pip install -r requirements.txt
# Build `hotsos`
#
# Note that we will need `dist-info` when loading `hotsos` which is not
# built with a simple `setup.py install`. Building a `bdist_wheel` and
# then installing it via `pip` addresses this shortcoming.
${SNAPCRAFT_PART_INSTALL}/bin/python3 setup.py bdist_wheel
${SNAPCRAFT_PART_INSTALL}/bin/pip install dist/hotsos-*.whl
# Update repo-info
git rev-parse --short HEAD > repo-info
# Install repo-info
install --mode 0644 repo-info ${SNAPCRAFT_PART_INSTALL}
# Rewrite the shebang to point to the correct Python interpreter. Only
# touch the first line and absorb the whole line. Note that the matching
# expression cannot be more specific since the path to the Python
# interpreter depends on the build environment. Notably, local builds
# (`/root`) differ from builds on launchpad (`/build`).
sed --in-place \
--expression "1 s:^#\!/.*$:#\!/snap/hotsos/current/usr/bin/${PYTHON}:" \
${SNAPCRAFT_PART_INSTALL}/bin/hotsos
# Add a missing link in snap to Python interpreter.
ln -sf ../usr/bin/${PYTHON} ${SNAPCRAFT_PART_INSTALL}/bin/python3
# Do not use `craftctl default` and `organize` because this simply copies
# the whole repository to the install directory. Using rsync on `defs` is
# cleaner.
mkdir -p ${SNAPCRAFT_PART_INSTALL}/etc/hotsos
rsync -av defs ${SNAPCRAFT_PART_INSTALL}/etc/hotsos/
rsync -av templates ${SNAPCRAFT_PART_INSTALL}/etc/hotsos/
stage:
python-packages:
- cryptography==3.4.8
- pip
- setuptools
- wheel
requirements:
- requirements.txt
build-environment:
- "CRYPTOGRAPHY_DONT_BUILD_RUST": "1"
filesets:
# need to exclude these files since they are dangling symlinks
# that cause the snapstore to reject the upload.
- -lib/systemd/system/cryptdisks-early.service
- -lib/systemd/system/cryptdisks.service
- -lib/systemd/system/hwclock.service
- -lib/systemd/system/rc.service
- -lib/systemd/system/rcS.service
- -lib/systemd/system/x11-common.service
- -tests

patchelf:
after:
- hotsos
plugin: nil
build-packages:
- file
- patchelf
override-prime: |
# patchelf
#
# To allow for a classic snap that works across multiple operating system
# runtime environments, we need to ensure all shipped binaries consume
# libraries from the core or shipped snap. We accomplish this by patching
# `RPATH`` or interpreter into dynamically linked binaries.
#
# /snap/${CORE}/current/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
# /snap/${CORE}/current/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
# /snap/${CORE}/current/lib/powerpc64le-linux-gnu/ld64.so.2
# /snap/${CORE}/current/lib/s390x-linux-gnu/ld64.so.1
set -e -u -x
CORE=core22
interpreter_prefix=/snap/${CORE}/current/lib/${SNAPCRAFT_ARCH_TRIPLET}
snap_prefix=/snap/${SNAPCRAFT_PROJECT_NAME}/current
ld_arch=$(echo ${SNAPCRAFT_TARGET_ARCH} | sed -e 's,amd64,x86-64,' -e 's,arm64,aarch64,')
for interpreter in "ld-linux-${ld_arch}.so.?" "ld64.so.?" "/dev/null"; do
if [ -e ${interpreter_prefix}/${interpreter} ]; then
break
fi
done
if [[ ${interpreter} == /dev/null ]]; then
echo "Unable to determine name of shared library interpreter."
exit 1
fi
for binary in \
$(find . -exec file {} \; | awk -F : '/ELF.*dynamic/ { print $1 }'); do
patchelf \
--force-rpath \
--set-rpath ${interpreter_prefix}:${snap_prefix}/lib:${snap_prefix}/lib/${SNAPCRAFT_ARCH_TRIPLET}:${snap_prefix}/usr/lib:${snap_prefix}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET} \
${binary}
# Setting the interpreter might harmlessly fail and we need to ignore
# the exit code in case it does.
patchelf --set-interpreter ${interpreter_prefix}/${interpreter} ${binary} || true
done
exclude-systemd-files:
- -lib/systemd/system/hwclock.service
- -lib/systemd/system/rc.service
- -lib/systemd/system/x11-common.service
- -lib/systemd/system/cryptdisks-early.service
- -lib/systemd/system/rcS.service
- -lib/systemd/system/cryptdisks.service
stage:
- $exclude-systemd-files

0 comments on commit bacceb7

Please sign in to comment.