16 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
f566e04888 chore: enable more linters and fix all critical issues
Enabled additional linters from fakemachine configuration:
- errorlint: Error wrapping with %w
- misspell: Spelling checks
- revive: Code quality checks
- whitespace: Formatting checks

Fixed all issues including:
- Error handling: Added proper error checks for all function returns
- Error wrapping: Changed %v to %w for proper error wrapping
- Type assertions: Used errors.As instead of direct type assertions
- Unused parameters: Renamed to underscore where appropriate
- Variable naming: Fixed ALL_CAPS constants and underscored names
- Whitespace: Removed unnecessary leading/trailing newlines
- Code flow: Removed unnecessary else blocks

Renamed types (breaking internal API changes):
- DebosState → State
- DebosContext → Context
- DownloadHttpUrl → DownloadHTTPURL

Fixed struct field naming with proper YAML tags:
- Url → URL (with yaml:"url" tag)
- TlsClientCertPath → TLSClientCertPath (kept yaml:"tls-client-cert-path")
- TlsClientKeyPath → TLSClientKeyPath (kept yaml:"tls-client-key-path")
- validateUrl → validateURL method

Co-authored-by: sjoerdsimons <22603932+sjoerdsimons@users.noreply.github.com>
2025-10-01 21:21:22 +02:00
Christopher Obbard
158ed7c09a chore: run go fmt
Signed-off-by: Christopher Obbard <christopher.obbard@linaro.org>
2025-08-11 14:33:38 +01:00
Julien Massot
840b1df5c2 Add support for alternate sectorsize
Newer storage, such as UFS or NVMe disk, may not support the
default 512 sector size.

For these devices, the partition table and the partition offset
need to be aligned with sector size boundaries. The GPT partition
table is 34 sectors in length, so we can't have compatible disk images
between 512 and 4096 sector-size devices.

This patch introduces a major breakage with the {{ sector 64 }}
template.
At template processing, we can't guess the appropriate sector size
for the image since this value can be defined as a YAML header.
Instead of multiplying the sector number by the default 512 bytes
boundary, append a 's' suffix. This defers the work of computing
the value to the different Actions.
The 's' suffix is chosen to be compatible with parted (ImagePartition)
and support has been added to raw action.

Signed-off-by: Julien Massot <julien.massot@collabora.com>
2025-03-04 07:16:15 +01:00
Emil Velikov
7de585a707 action: move and inline LogStart() further up
Currently each action starts with LogStart(), adding some annoying
duplication. In addition we have a LogStart(), whereas there's no
end/stop equivalent.

Instead add the on-line log.Print() wihtin the debos action loop, just
prior to calling Run(). The same file deals with all the other pretty
logging.

v2: Drop pacman/pacstrap hunks

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2023-12-08 11:44:04 +00:00
Sjoerd Simons
07af4c497f Add helper to retrieve origin
The origins hash table is inside the commonContext structure which is
shared by all Contexts. This mostly works correctly as most origins are
not specific to the recipe that's executed but to either the run or the
progress of a run. Such as "filesystem" or "artifacts".

However this is not the case for the "recipe" origin. To resolve that
add a helper function which returns the current context RecipeDir and
otherwise simply the respective value in the common Origins table.

Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
2022-04-27 17:18:51 +02:00
Frédéric Danis
704e42329c Split DebosContext in generic and recipe specific parts
To be able to load recipe from directory not under main recipe
directory, new "recipe" action needs to be able overwrite some
properties, architecture and recipe path. But other properties
needs to be shared between actions, as some of them can change
their values.
To allow this, move shared properties in new CommonContext structure
and add to remaining properties a new pointer to the CommonContext.

Signed-off-by: Frédéric Danis <frederic.danis@collabora.com>
2019-03-26 09:34:43 +01:00
Frédéric Danis
cf3fc481f2 actions: Dump actions for each recipe
Dump Recipe structure in Recipe.Parse() method to allow to do it before
Verify() method is called for a given recipe or sub-recipe.

Sub-recipes are loaded by recipe action's Verify(). Dump of Recipe
structure can be done in Verify() or Parse() methods.
Doing it in Recipe.Parse() allows to have it done in one place.

Signed-off-by: Frédéric Danis <frederic.danis@collabora.com>
2019-03-19 22:50:23 +01:00
Frédéric Danis
74df488fb6 actions: Add recipe action
This action includes the recipe actions at the given path, and can
optionally overrides or adds new template variables.

To allow recipes to operate both stand-alone and when included, template
variable "included_recipe" is added and set to "true" to indicate that
the recipe is part of a longer chain.
This allows a recipe to skip the unpack step if it's not the first to be
executed or to optionally skip a pack action when it's not the last.

For compatibility, both the parent recipe and all included recipes have
to be for the same architecture.

Limitations of combined recipes are equivalent to limitations within a
single recipe (e.g. there can only be one image partition action).

Print-recipe option is saved in DebosContext to allow each "recipe action"
to print its source during Parse.

Signed-off-by: Frédéric Danis <frederic.danis@collabora.com>
2019-03-19 22:50:23 +01:00
Frédéric Danis
3cac6f8bb3 Revert "cmd: Add options to print recipe used for build"
This reverts commit 9522b3bfc6485289516fd5ced7f08f79cd2d8df2.
2019-02-19 11:54:55 +01:00
Frédéric Danis
9db472dc14 cmd: Add options to print recipe used for build
This adds debos options:
- --print-recipe to print final recipe
- --dry-run to compose final recipe to build but without any real work
  started

Signed-off-by: Frédéric Danis <frederic.danis@collabora.com>
2019-02-19 11:54:55 +01:00
Peter Senna Tschudin
d5de0f1f46 Add support to environment variables
This change makes debos read a predefined set of environment variables
from the host and propagates it to fakemachine. The set of environment
variables is defined by environ_vars on cmd/debos/debos.go. Currently
the list of environment variables is configured to the proxy environment
variables as documented here[1]:

  http_proxy, https_proxy, ftp_proxy, rsync_proxy, all_proxy, no_proxy

While the elements of environ_vars are in lower case, for each element
both lower and upper case variants are probed on the host, and if found
propagated to fakemachine. So if the host has the environment variables
HTTP_PROXY and no_proxy defined, both will be propagated to fakemachine
respecting the case.

This patch also adds --environ-var and -e command line options that can
be used to specify, overwrite, and unset environment variables for
fakemachine with the syntax:

  $ debos -e ENVIRONVAR:VALUE ...

To unset an enviroment variable, or in other words, to prevent an
environment variable to be propagated to fakemachine, use the same
syntax without a value. debos accept multiple -e simultaneously.

[1] - https://wiki.archlinux.org/index.php/proxy_settings

This change depends on:

  8b7eea7096cd015771cf9862647b7cd04bb41904 - machine.go: Add support to
  environment variables

on fakemachine repository.

Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
2018-11-05 09:28:46 +01:00
Denis Pynkin
1d91766e05 Reworked the cleanup logic
Cleanup logic for actions is reworked by this change:
- Cleanup() gets called only if the Run for an action was started and
  in the same machine (host or fake) as Run has run
- Add new method PostMachineCleanup(). This method gets called for the
  actions with Pre*Machine() method called. This method is always executed
  on the host with user's permissions.
- Due to all the deferring both *Cleanup methods get called in reverse
  order; Cleanup always happens first (either on host or fake).
- Add global variable "State" in DebosContext structure to represent the
  current build state. This could be used for correct cleanup in Actions.
- Changed API for "Action" interface -- now all methods use the pointer
  to context data instead of the copy to have a real context for deffered
  calls.

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2018-07-05 08:47:45 +02:00
Sjoerd Simons
a050a9ff08 Expose partition to device mapping to other actions
After create partitions put a partition -> device mapping in the context
such that other actions can use that to allow the user to refer to
partition names in other actions.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
2017-12-13 09:04:52 +01:00
Sjoerd Simons
32bc54c7b6 Use fakemachine from go-debos
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
2017-10-27 20:50:14 +02:00
Denis Pynkin
ffa64473a5 debug: run interactive shell on error
Launch interactive shell in context of failed action for issues
investigation and debug.

Add options to debos:
--debug-shell -- to start a shell in case of any failure
--shell <path> -- use selected shell instead of default bash

Fixes #30

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2017-10-25 15:23:16 +03:00
Denis Pynkin
8a89531a6a Split debos main file
Initially 'debos.go' contained a lot of additions and logical parts in
single file. So move logical parts from 'debos.go' to appropriate packages:
- 'debos' package: actions interface and filesystem addons
- 'recipe' package: logic of Yaml-based recipe parsing

Use correct imports, naming and syntax for splitted files.

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2017-09-05 15:24:37 +03:00