Skip to content

Commit

Permalink
create recipe for dev build of snap
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfect5th committed Sep 5, 2023
1 parent ff05719 commit dc7c141
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 120 deletions.
10 changes: 10 additions & 0 deletions landscape/client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

IS_SNAP = os.getenv("LANDSCAPE_CLIENT_SNAP")

USER = "root" if IS_SNAP else "landscape"
GROUP = "root" if IS_SNAP else "landscape"

DEFAULT_CONFIG = (
"/etc/landscape-client.conf" if IS_SNAP else "/etc/landscape/client.conf"
)
11 changes: 4 additions & 7 deletions landscape/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from functools import partial
from urllib.parse import urlparse

from landscape.client import GROUP
from landscape.client import USER
from landscape.client.broker.amp import RemoteBrokerConnector
from landscape.client.broker.config import BrokerConfiguration
from landscape.client.broker.registration import Identity
Expand Down Expand Up @@ -643,13 +645,8 @@ def setup(config):
def bootstrap_tree(config):
"""Create the client directories tree."""
bootstrap_list = [
BootstrapDirectory("$data_path", "landscape", "root", 0o755),
BootstrapDirectory(
"$annotations_path",
"landscape",
"landscape",
0o755,
),
BootstrapDirectory("$data_path", USER, "root", 0o755),
BootstrapDirectory("$annotations_path", USER, GROUP, 0o755),
]
BootstrapList(bootstrap_list).bootstrap(
data_path=config.data_path,
Expand Down
3 changes: 2 additions & 1 deletion landscape/client/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from twisted.logger import globalLogBeginner

from landscape import VERSION
from landscape.client import DEFAULT_CONFIG
from landscape.client.upgraders import UPGRADE_MANAGERS
from landscape.lib import logging
from landscape.lib.config import BaseConfiguration as _BaseConfiguration
Expand Down Expand Up @@ -37,7 +38,7 @@ class BaseConfiguration(_BaseConfiguration):

version = VERSION

default_config_filename = "/etc/landscape/client.conf"
default_config_filename = DEFAULT_CONFIG
if _is_script():
default_config_filenames = (
"landscape-client.conf",
Expand Down
6 changes: 4 additions & 2 deletions landscape/client/manager/aptsources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from twisted.internet.defer import succeed

from landscape.client import GROUP
from landscape.client import USER
from landscape.client.manager.plugin import ManagerPlugin
from landscape.client.package.reporter import find_reporter_command
from landscape.constants import FALSE_VALUES
Expand Down Expand Up @@ -167,8 +169,8 @@ def _run_reporter(self):
args.append(f"--config={self.registry.config.config}")

if os.getuid() == 0:
uid = pwd.getpwnam("landscape").pw_uid
gid = grp.getgrnam("landscape").gr_gid
uid = pwd.getpwnam(USER).pw_uid
gid = grp.getgrnam(GROUP).gr_gid
else:
uid = None
gid = None
Expand Down
6 changes: 4 additions & 2 deletions landscape/client/package/changer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from twisted.internet.defer import maybeDeferred
from twisted.internet.defer import succeed

from landscape.client import GROUP
from landscape.client import USER
from landscape.client.manager.manager import FAILED
from landscape.client.manager.shutdownmanager import ShutdownProcessProtocol
from landscape.client.monitor.rebootrequired import REBOOT_REQUIRED_FILENAME
Expand Down Expand Up @@ -118,8 +120,8 @@ def run_package_reporter(self):
return

if os.getuid() == 0:
os.setgid(grp.getgrnam("landscape").gr_gid)
os.setuid(pwd.getpwnam("landscape").pw_uid)
os.setgid(grp.getgrnam(GROUP).gr_gid)
os.setuid(pwd.getpwnam(USER).pw_uid)
command = find_reporter_command(self._config)
if self._config.config is not None:
command += f" -c {self._config.config}"
Expand Down
6 changes: 4 additions & 2 deletions landscape/client/package/releaseupgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from twisted.internet.defer import succeed

from landscape.client import GROUP
from landscape.client import USER
from landscape.client.manager.manager import FAILED
from landscape.client.manager.manager import SUCCEEDED
from landscape.client.package.reporter import find_reporter_command
Expand Down Expand Up @@ -289,8 +291,8 @@ def finish(self):
shutil.rmtree(self._config.upgrade_tool_directory)

if os.getuid() == 0:
uid = pwd.getpwnam("landscape").pw_uid
gid = grp.getgrnam("landscape").gr_gid
uid = pwd.getpwnam(USER).pw_uid
gid = grp.getgrnam(GROUP).gr_gid
else:
uid = None
gid = None
Expand Down
2 changes: 1 addition & 1 deletion landscape/client/serviceconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def stop_landscape() -> None:

@staticmethod
def is_configured_to_run() -> bool:
completed_process = SnapdConfig._call_snapctl("services")
completed_process = SnapdConfig._call_snapctl("services", text=True)
stdout = completed_process.stdout

return stdout and "enabled" in stdout
Expand Down
44 changes: 15 additions & 29 deletions landscape/client/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from twisted.internet.error import ProcessExitedAlready
from twisted.internet.protocol import ProcessProtocol

from landscape.client import USER
from landscape.client.broker.amp import RemoteBrokerConnector
from landscape.client.broker.amp import RemoteManagerConnector
from landscape.client.broker.amp import RemoteMonitorConnector
Expand Down Expand Up @@ -78,7 +79,7 @@ class Daemon:
program. Defaults to False.
"""

username = "landscape"
username = USER
max_retries = 3
factor = 1.1
options = None
Expand Down Expand Up @@ -649,41 +650,26 @@ def _remove_pid(self):

bootstrap_list = BootstrapList(
[
BootstrapDirectory("$data_path", "landscape", "root", 0o755),
BootstrapDirectory("$data_path/package", "landscape", "root", 0o755),
BootstrapDirectory(
"$data_path/package/hash-id",
"landscape",
"root",
0o755,
),
BootstrapDirectory(
"$data_path/package/binaries",
"landscape",
"root",
0o755,
),
BootstrapDirectory("$data_path", USER, "root", 0o755),
BootstrapDirectory("$data_path/package", USER, "root", 0o755),
BootstrapDirectory("$data_path/package/hash-id", USER, "root", 0o755),
BootstrapDirectory("$data_path/package/binaries", USER, "root", 0o755),
BootstrapDirectory(
"$data_path/package/upgrade-tool",
"landscape",
USER,
"root",
0o755,
),
BootstrapDirectory("$data_path/messages", "landscape", "root", 0o755),
BootstrapDirectory("$data_path/sockets", "landscape", "root", 0o750),
BootstrapDirectory("$data_path/messages", USER, "root", 0o755),
BootstrapDirectory("$data_path/sockets", USER, "root", 0o750),
BootstrapDirectory(
"$data_path/custom-graph-scripts",
"landscape",
USER,
"root",
0o755,
),
BootstrapDirectory("$log_dir", "landscape", "root", 0o755),
BootstrapFile(
"$data_path/package/database",
"landscape",
"root",
0o644,
),
BootstrapDirectory("$log_dir", USER, "root", 0o755),
BootstrapFile("$data_path/package/database", USER, "root", 0o644),
],
)

Expand Down Expand Up @@ -724,12 +710,12 @@ def run(args=sys.argv, reactor=None):
config.load(args)

try:
landscape_uid = pwd.getpwnam("landscape").pw_uid
landscape_uid = pwd.getpwnam(USER).pw_uid
except KeyError:
sys.exit("The 'landscape' user doesn't exist!")
sys.exit(f"The '{USER}' user doesn't exist!")

if os.getuid() not in (0, landscape_uid):
sys.exit("landscape-client can only be run as 'root' or 'landscape'.")
sys.exit(f"landscape-client can only be run as 'root' or '{USER}'.")

init_logging(config, "watchdog")

Expand Down
154 changes: 78 additions & 76 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,98 +1,100 @@
name: landscape-client
base: core22
version: '0.1'
version: '0.0.1'
icon: snap/gui/landscape-logo-256.png
website: https://ubuntu.com/landscape
summary: Client for the Canonical systems management product Landscape
description: |
This client, when installed, allows a machine to connect to the
Landscape server and be remotely managed by it. Be aware that
this snap is not a replacement for the apt package that is
traditionally used. This snap is specifically designed for
coreXX based systems and as such can only interact with other
snaps, not apt packages.
Landcape is a web-based tool for managing Ubuntu systems. This snap, or the
equivalent debian package is necessary if you want your machine to be managed
in a Landscape account. It provides the Landscape client and requires a
Landscape account.
grade: devel # must be 'stable' to release into candidate/stable channels
architectures:
- build-on: amd64
- build-on: arm64
- build-on: ppc64el
- build-on: s390x
architectures: [amd64, arm64, armhf, ppc64el, s390x]
confinement: strict

layout:
/var/lib/landscape:
bind: $SNAP_DATA/var/lib/landscape

environment:
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/x86_64-linux-gnu
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$SNAP/usr/lib/python3.10/dist-packages

apps:
landscape-client:
daemon: simple
command: bin/landscape-client
plugs:
- network
landscape-config:
command: bin/landscape-config
plugs:
- network
install-mode: disable
command: usr/bin/landscape-client
plugs: [network-bind, system-observe]
environment:
LANDSCAPE_CLIENT_SNAP: 1
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
config:
command: usr/bin/landscape-config
plugs: [network-bind]
environment:
LANDSCAPE_CLIENT_SNAP: 1
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

layout:
/etc/landscape-client.conf:
bind-file: $SNAP_DATA/etc/landscape-client.conf
/var/lib/landscape/client:
bind: $SNAP_DATA/var/lib/landscape/client
/var/log/landscape:
bind: $SNAP_DATA/var/log/landscape

package-repositories:
- type: apt
ppa: landscape/self-hosted-beta

parts:
landscape-client:
plugin: python
source: https://github.com/CanonicalLtd/landscape-client.git
python-packages:
- convoy-python
- distutils-extra-python
- sasl
- twisted
plugin: dump
source: .
source-type: local # Don't use 'git' - it forces you to commit your changes
build-packages:
- build-essential
- libsasl2-2
- libsasl2-dev
- libsasl2-modules
- libsasl2-modules-db
- libsasl2-modules-gssapi-mit
- python3-distutils
- python3-flake8
- python3-configobj
- python3-coverage
- debhelper
- devscripts
- dh-python
- gawk
- libdistro-info-perl
- lsb-release
- net-tools
- po-debconf
- python3-apt
- python3-configobj
- python3-dev
- python3-distutils-extra
- python3-mock
- python3-netifaces
- python3-pycurl
- python3-pip
- python3-twisted
- software-properties-common
- python3-twisted
override-build: |
python3 -m venv build/venv --system-site-packages
ln -sf build/venv/bin bin
bin/pip install -U convoy-python distutils-extra-python twisted pre-commit sasl
make build3
git commit -n -a -m "dev build for snap" --no-gpg-sign
cat << EOF > debian/changelog
landscape-client (0.0.1) UNRELEASED; urgency=medium
* Test build for snap
-- Guy Incognito <[email protected]> Fri, 1 Sep 2023 00:00:00 +0000
EOF
git archive --prefix landscape-client-0.0.1/ HEAD | tar -x
rm -rf landscape-client-0.0.1/debian
tar -czf landscape-client-0.0.1.tar.gz landscape-client-0.0.1
cp -r debian landscape-client-0.0.1
cd landscape-client-0.0.1 && debuild -b --no-sign
cp ../landscape-*_0.0.1_*.deb $CRAFT_PART_INSTALL
stage-packages:
- landscape-client
- landscape-common
- language-pack-en
- libsasl2-2
- libsasl2-dev
- libsasl2-modules
- libsasl2-modules-db
- libsasl2-modules-gssapi-mit
- python3-oops
- python3-pip
- adduser
- bc
- ca-certificates
- debconf
- libpam-modules
- lsb-base
- lsb-release
- lshw
- python3
- python3-apt
- python3-configobj
- python3-gdbm
- python3-netifaces
- python3-pycurl
- python3-twisted
override-stage: |
- ubuntu-advantage-tools
override-prime: |
craftctl default
# Copy the landscape-config script over
mkdir -p "${SNAPCRAFT_PRIME}/bin"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-broker" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-client" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-config" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-manager" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-monitor" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-package-changer" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-package-reporter" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-release-upgrader" "${SNAPCRAFT_PRIME}/bin/"
cp "${SNAPCRAFT_PART_SRC}/scripts/landscape-sysinfo" "${SNAPCRAFT_PRIME}/bin/"
rm $CRAFT_PRIME/landscape-*_0.0.1_*.deb
dpkg-deb -x $CRAFT_STAGE/landscape-common_0.0.1_*.deb $CRAFT_PRIME
dpkg-deb -x $CRAFT_STAGE/landscape-client_0.0.1_*.deb $CRAFT_PRIME

0 comments on commit dc7c141

Please sign in to comment.