43 Commits

Author SHA1 Message Date
Reagan Lopez eda20b16a8 Log bsdiff errors at Debug level
To avoid cluttering stdout with bsdiff errors, log them at Debug level
instead of Warning level.

Signed-off-by: Reagan Lopez <reagan.lopez@intel.com>
2020-05-01 16:48:19 -07:00
Ashlesha Atrey f6dcd44f21 Implement logging for mixer
Implement the logging package for mixer.

A common log file can be set for all the mixer commands in the
builder.conf. E.g. `mixer config set Mixer.LOG <filepath>`

The log file and level can also be set for individual mixer
commands using the `--log` and `--log-level` flags respectively.

The various log levels are:
ERROR (1), WARNING (2), INFO (3), DEBUG (4) and VERBOSE (5).
Default log level is 4.

Fixes #666

Signed-off-by: Ashlesha Atrey ashlesha.atrey@intel.com
2020-04-30 13:57:58 -07:00
John Akre bfc02ef322 Set file perms after creating the dest file
When calling the copyFileWithFlags function with the preserveSrc flag
set, file permissions must be set after creating the destination file
and setting the file owner. This is necessary because umask can prevent
newly created files from acquiring the source file's permissions and
file ownership changes can impact the setuid/setgid permissions.

Similarly directory permissions are set after creating the directory to
avoid unexpected permission behavior caused by umask.

Signed-off-by: John Akre <john.w.akre@intel.com>
2020-03-03 16:23:41 -08:00
John Akre 60dcf63ce2 Preserve file ownership when using content chroots
When using content chroots, file uid/gid values should be preserved when
copying them to the full chroot.

Fixes #727

Signed-off-by: John Akre <john.w.akre@intel.com>
2020-02-25 17:29:39 -08:00
John Akre e9cf491dbc helpers: Add CopyFileWithOptions function
The CopyFileWithOptions function has the ability to disable symlink
resolution, preserve the source file permissions, and disable disk syncs.

Signed-off-by: John Akre <john.w.akre@intel.com>
2020-01-31 13:54:12 -08:00
Rodrigo Chiossi 01e6ca3e43 lint: Fix errors identified by golangci-lint
golangci-lint identified a couple errors that were not found by
gometalinter. This patch fixes the detected errors.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2019-09-19 16:57:37 +02:00
Rodrigo Chiossi 70a3f68c58 global: Use log package for Warnings and Errors
This patch changes how Warnings and Error messages are printed
throughout the code to use the `log` package instead of `fmt`. This
allows for finer control over what is printed and where it is printed
to.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-10-23 10:04:52 -07:00
Rodrigo Chiossi 4c3f790d77 helpers: Handle error on output buffer write fail
If an error occurred when running an external program, the user should
receive a full report of that program's output. If mixer is unable to
write that output, the user should get and error indicating the problem
instead of an incomplete output, making it easier to debug the problem.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-10-23 10:04:52 -07:00
Rodrigo Chiossi 20cacb9757 Revert "helpers: Reduce download timeout"
This reverts commit 9cf854d8d6.

The reduction to the timeout has caused failures for users on slow
networks, so this must be reverted to the default values.

The reduction to the timeout was added to improve user experience when
connection failed due to a proxy error. It would take mixer too long to
fail and the error message didn't indicate what the problem could be.

The error is now properly indicated, so even if it takes a while for the
error to occur the first time, the user should be able to identify the
problem on the spot.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-09-20 21:35:39 +02:00
Auke Kok 5d42cfdb14 gofmt -s this file. 2018-08-30 11:06:38 -07:00
Rodrigo Chiossi 0c9f0e3dd8 bundles: Enforce UTF-8 when running dnf
In some situations dnf may try to combine files from different
encodings. If the command is not running is a UTF-8 locale, this
combination will be missing a new line, causing and error.

An example of this occurrence is the command `dnf repoquery --quiet -l
systemd ca-certs-static ...` which combines a file list from systemd and
ca-certs-static

This patch enforces UTF-8 locale on every dnf execution.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-08-30 00:32:25 -07:00
Rodrigo Chiossi 07b3a3c182 builder: Improve download upstream error message
The error when mixer failed to download the upstream version was too
confusing since there were many layers of wrapped errors.
This patch removes the excessive wrapping and suggests a missing proxy
configuration to the user in case this error occurs.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-08-30 00:32:11 -07:00
Rodrigo Chiossi 9cf854d8d6 helpers: Reduce download timeout
Instead of the default 30 seconds timeout, use 10 seconds when trying to
download files.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-08-30 00:32:11 -07:00
Tudor Marcu 03711f29a1 Return error from timeout
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2018-06-12 23:59:47 +00:00
Tudor Marcu 0020262f2b Set timeout on bsdiff delta creation
Set timeout to 1 minute for bsdiff. The majority of all delta creations
take significantly less than 1 minute to run, which signifies that bsdiff
is working on a delta that may be very large, or very difficult to diff. In
all the cases where bsdiff took multiple minutes to finish, the delta ended
up not being used because it was larger than the compressed fullfile. This
attempts to skip those cases and improve delta creation time.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2018-06-12 16:51:51 -07:00
Kevin C. Wells cebb0b1a81 Misc bug fixes
Fix a number of AFB bugs:

- Previous build's upstream format was being incorrectly looked up,
resulting in upstream format boundary crossing detection failing.

- PreRun check was incorrectly skipping format build commands, resulting
in "stage for mix" being run twice.

- Only the UInt32 upstream version was being modified, resulting in the
second half of 'mixer build upstream-format' being run in the wrong
container.

- The wrong format was being printed out for 'mixer versions' if
crossing an upstream format boundary.

Refactor Cobra command PreRun

Simplified the PreRun logic that happens before every command. This also
fixes an issue where format bump build commands could be run with
--native=false, when they need to be run natively.

Fix AFB mixversion and LAST_VER setting

1) Changes how the format bump builds set mixversion so that it no
longer skips a version number in some situations.

2) Updates the update/image/LAST_VER file after the +10 build back
to the +20 build value, so mixer is ready to do the next mix.

Refactor file download code

This patch refactors and consolidates the different file download code
scattered throughout helper.go and builder.go.

Signed-off-by: Kevin C. Wells <kevin.c.wells@intel.com>
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2018-06-07 17:13:47 -07:00
Rodrigo Chiossi 265301fb30 builder: move file download to helpers
Download a file is a generic operation. This patch moves this
functionality from builder to helpers to allow it to be reused
by other packages.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-05-29 13:33:08 -07:00
Icarus Sparry d5114b6010 Ignore filenames starting with '.'
Previously the code was using ioutils.ReadDir which does a stat call
on every file, but none of the code required the results of the stat
calls, just the names.

In addition programs such as git would like to hold information in the
directories. The usual unix way to do this is to have filenames
beginning with '.', and these are ignored by default by things such as
shell globbing and the ls program.

fixes #269

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
2018-05-02 16:51:12 -07:00
Matthew Johnson 341891f55f Build bundle information using dnf commands
Deprecate use of chroot-building for each individual bundle. This allows
us to scale much easier on machines with limited disk space. Because
chroots are decoupled from manifest creation this also makes it possible
in the future to move to doing bundle builds on distributed machines and
allows our bundle numbers to scale. The bundle file list is stored in a
JSON file that is read later by the manifest creation step.

This leaves a fallback in swupd/fullchroot.go to allow users to add
content to a chroot in order to extend a typical build.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-03-09 11:36:27 -08:00
Kevin C. Wells 424031e5aa Add mixer bundle edit command
Adds new command, 'mixer bundle edit', that allows a user to edit local
and upstream bundle definition files. This command will locate the
bundle (looking first in local-bundles, then in upstream-bundles), and launch
an editor to edit it. If the bundle is only found upstream, the bundle file will
first be copied to your local-bundles directory for editing. When the editor
closes, the bundle file is then parsed for validity.

The editor is configured via environment variables. VISUAL takes precedence to
EDITOR. If neither are set, the tool defaults to nano. If nano is not installed,
the tool will skip editing, and act as if '--copy-only' had been passed.

Passing '--copy-only' will suppress launching the editor, and will thus only copy
the bundle file to local-bundles if it is only found upstream. This can be
useful if you want to add a bundle to local-bundles, but wish to edit it at a
later time.

Passing '--add' will also add the bundle(s) to your mix. Please note that
bundles are added after all bunles are edited, and thus will not be added if any
errors are encountered earlier on.

Signed-off-by: Kevin C. Wells <kevin.c.wells@intel.com>
2018-02-13 14:52:30 -08:00
Caio Marcelo de Oliveira Filho 12afb78509 helpers: make failure output concise in Run commands
When RunCommandOutput (or RunCommandSilent) fails, only add the STDOUT
and STDERR to the error string if they have any content (otherwise
omit).

Also add some text without a newline in the end of the string to allow
the underlying error to be printed correctly. If you've seen lines
with ": exit status NNN" this last change will make things looks
better.

In RunCommand, simplify the error message taking in account that the
wrap will append the underlying error when printed.
2018-02-12 14:52:54 -08:00
Kevin C. Wells aedc1023e6 Fix CopyFile bug
Previously, helpers.CopyFile left off os.O_TRUNC, meaning that
if the destination is larger than the source, the rest of the
destination remained at the end. Now the file is overwritten
completely.

Signed-off-by: Kevin C. Wells <kevin.c.wells@intel.com>
2018-02-09 16:47:40 -08:00
Kevin C. Wells 2c9c9144c7 Refactor mix bundles
This commit refactors the way you specify what bundles are included
in your mix, as well as how the mix-bundles directory gets
generated.

Major changes in this commit:
- Introduces the Mix Bundles List, a newline-separated file in the
  working directory that lists the bundles that must be in the mix.
  Other bundles (included by those in the list) will be added
  automatically.
- Introduces the local-bundles directory that stores any bundles
  that the user created or that have been edited from upstream.
  Bundles in the local-bundles directory take precedence over
  upstream bundles of the same name.
- Generates the mix-bundles/ directory (used as input to the BCB)
  automatically on-the-fly when chroots are built. The Mix Bundles
  List is recursed to find all bundles needed for the mix, and the
  bundle definition files are copied from either the local or
  upstream bundles.
- If '--new-chroots' is passed, the mix-bundles/ directory is
  skipped entirely, as the new BCB is capable of reading the
  files from anywhere.
- Modifies the 'mixer bundle add' command to now edit the Mix
  Bundles List. Bundles are verified to exist in either the local
  or upstream bundles. The user is informed whether the added
  bundles came from local or upstream.
- Adds a new 'list' command to 'mixer bundle' that prints out
  the bundles in the Mix Bundle List (including those
  recursively included), all bundles available in local bundles,
  or all bundles available in upstream bundles. The mix bundle
  list, bundle names are annotated with information about their
  origin (local or upstream) and whether they are part of the
  Mix Bundle List or just included. For the local and upstream
  lists, bundle names are annotated with whether or not they are
  currently included in the mix. All three of the above list
  types support a '--tree' option that prints them as a formatted
  tree view, visually showing the include relationship for bundles
  and how the full list is being generated.

Minor changes in this commit:
- As the mix-bundles directory is now created on-the-fly, it is no
  longer tracked as a git repository. Instead, the entire mixer
  working directory is tracked, with temporary, tool-generated
  files ignored. This allows one to track and correlate the Mix
  Bundle List, mix version, and upstream version as they are changed.
- The above-mentioned git revision tracking is now optional, and
  is only set up if '--git' is passed to 'mixer init'. 'mixer
  bundle add' still supports '--git', which mirrors this behavior.
- The '--all' flags for 'mixer init' and 'mixer bundle add' have
  been split up into '--all-local' and '--all-upstream'. This
  allows a user to add or start with all local or upstream bundles,
  or both.
2018-02-08 18:34:34 -08:00
Caio Marcelo de Oliveira Filho ee63b720d2 builder: port chroot building to Go
This rewrites bundle-chroot-builder.py in Go to be part of Mixer
code. Mixer is the only user of that software, and both Mixer and
bundle-chroot-builder.py the same configuration file, with overlapping
fields.

Main differences from bundle-chroot-builder.py:

- New bundleset type was added, that cares about collecting as much
  information as possible from the bundles themselves. This type and
  related functions also sets us up for success when upcoming changes
  to how bundles are specified happen. There is no assumption all
  bundles are in the same directory.

- We are not using m4, instead a bundleset takes care of parsing. If
  format of individual bundle files change. The upside is that we can
  give nicer error messages, specially for the circular case.

- Read the configuration file directly (with go-ini) to peek at values
  that Mixer didn't read before. Done that to avoid conflicting with
  existing patch in-flight that parses configuration.

- Some individual steps were reordered for code clarity. E.g.: since
  we have bundleset, we can upfront generate all the *-include files.

- Fixed the output for versions file. Due to the way yum list output
  works, parsing it is not very friendly. Comments around the code
  tells the story.

- Removed the network testing step. It wasn't covering every case in
  the Python version, so I'm leaning to let the failure come from
  yum/dnf itself. I'm usually in favor of such early tests, but in
  this case the price of parsing yet another config file didn't felt
  worth.

- Removed the "yum clean all" step from the bootstrap. There isn't any
  cache at that point, and the next yum call will bootstrap the
  necessary files for yum to operate.

- Removed generation of files-* files (and the pkgmap-* files used to
  generate them). I couldn't find any tool or team making use of this
  information. Those (or their content) might be relevant in future
  changes to use a single chroot, but we should add when we need them.

- Added more detailed commentary to individual steps, collecting
  information from the developers of bcb and related software.

- The port still don't parallelize the work into multiple
  goroutines. I plan to do this in a similar way than what was done in
  CreateFullfiles, but in a separated patch.

Fixes #42.

Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
2018-01-26 13:05:09 -08:00
Tudor Marcu a0fe64fd1c Add delta creation code
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2018-01-24 13:16:42 -08:00
Rodrigo Chiossi dc8ce665c5 Allow non-overwrite file copy
When initializing the mix workspace, if a file that would be initialized
already exists, it should be preserved. This patch introduces a generic
implementation of CopyFile that accepts custom flags and provides two
interfaces with pre-defined flags: CopyFile, which keeps the original
implementation and CopyFileNoOverwrite, which adds the new functionality.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2018-01-24 11:52:22 -08:00
Kevin C. Wells 5c0064a965 Refactor download of upstream bundles
Split up the download/unpacking of upstream bundles and the
creation of the mix-bundles directory.

Fetching upstream bundles now lives in a standalone function that
is called by any function that relies on having upstream bundle
definitions. This means the tool automatically handles the caching
of upstream bundles, making the 'mixer bundle get' command
obsolete.

Creation of the mix-bundles directory has been moved to InitMix.

This patch also includes general cleanup and error handling,
especially for InitMix and AddBundles.

This patch has the following side-effects:
1) The upstream bundles are now considered temporary, sausage-
making data. As such, they now live in .mixer/upstream-bundles/,
and the .tar.gz file used to fetch them is cleaned up.
2) The method for fetching upstream bundles has an optional
parameter ('prune') that will clean up the bundle cache for other
versions of upstream. This should be considered the default value
as part of standard clean-up behavior; a value of false should only
be used in cases where a method needs to have multiple versions
of upstream bundles cached simultaneously.

Signed-off-by: Kevin C. Wells <kevin.c.wells@intel.com>
2018-01-23 13:39:40 -08:00
Kevin C. Wells 69c49983e8 Replace exec to tar with native function
When unpacking upstream bundle defintions, previously an exec
was made to 'tar'. This patch replaces the exec call with a
native function that uses the Go tar and gzip packages instead.

Signed-off-by: Kevin C. Wells <kevin.c.wells@intel.com>
2018-01-23 13:39:40 -08:00
Caio Marcelo de Oliveira Filho 6047d2e363 builder: clean up BuildUpdate
Main changes:

- Rename parameters to reflect better their intention. In particular
  "signflag" -> "skipSigning"

- Remove unnecessary Stat check for dir creation: MkdirAll will do
  that and not fail if the directory already exists.

- Changed commands to do like the swupd_create_update and their output
  the error directly to the os.Stdout/os.Stderr.

- Changed most of file path building to use filepath.Join.

- Inline setVersion, since these two steps make sense at build
  update level.

- Only create upstreamver file if we create an upstreamurl file, and do
  that before the final publishing step.

- Added comments to clarify some of the steps.

Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
2018-01-08 10:43:12 -08:00
Caio Marcelo de Oliveira Filho f4dbef6f44 helpers: remove unused ENOVERSION constant
Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
2018-01-04 15:27:19 -08:00
Caio Marcelo de Oliveira Filho 60209cd740 builder: clean up the 'mixer add-rpms' codepath
Make it return errors, check for more cases and avoid the Chdir by
setting the relevant directory in the exec.Cmd.

Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
2018-01-04 15:26:10 -08:00
Tudor Marcu c3fb081eaf Fix linter errors and warnings
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2018-01-02 09:43:30 -08:00
Tudor Marcu da03c913ee Mixer: Update CLI to use cobra package
The cobra package is very mature for writing CLIs, and makes the code
much easier to maintain and add new commands to. This feature ports the
current implementation over to using cobra, maintaining the same calling
convention for the commands. However, it would be trivial and perhaps
better to update the form from:
mixer build-chroots --flags

to

mixer build chroots --flags

with chroots being a subcommand of build, as the code is currently
structured in cmd.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2018-01-02 09:43:30 -08:00
Tudor Marcu 9607078d6d Update mixer-tools structure and Makefile
Follow the expected Go convention for packages, and put the project
under github.com/clearlinux/mixer-tools with the correct hierarchy.
Simplify Makfile for the time being.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-12-18 17:12:15 -08:00
Tudor Marcu 17897b54f7 Remove deprecated mixer-tools
The old tools will remain in the archaeology branch for historical reasons
and ease of cloning.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-03-01 01:49:47 -08:00
Patrick McCarty 37e52b7541 Prefix tag names with refs/tags/
Because Clear version numbers use numeric digits only, it's possible for
the tag names to conflict with the prefix of a git object hash in the
repo. To remove the possibility of conflict, use the refs/tags/ prefix
when querying the tag names.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2017-02-27 11:27:22 -08:00
Patrick McCarty a3e26d8a35 Improve clr-bundles branch updates
With the current workflow, the "mix-bundles" repo is used for
mix-specific bundle changes, and the "clr-bundles" repo is treated as
read-only.

So in clr-bundles, the CLRVER_mix branches should always point to the
commit tagged with CLRVER. To make this handling more robust, first
verify that CLRVER exists and is a tag. Then create the CLRVER_mix
branch based on CLRVER, or if the branch already exists, reset it
appropriately.

Since this is the best place to detect invalid CLEAR_VERSION numbers
passed in the builder.conf, I've added that error handling too.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2017-02-27 11:27:22 -08:00
Tudor Marcu df981c3903 Declare increment variable
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-01-09 12:21:17 -08:00
Patrick McCarty ec5ddfd3eb helpers: fix error handling for dependency checks
Because 'set -e' is enabled for init-mix.sh, the exit status of 'type'
is not checked, so an error raised by 'type' would exit immediately, not
running the $? conditional logic.

To fix, disable 'set -e' for the dependency check function.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-12-06 16:10:35 -08:00
Tudor Marcu 80da4998c0 Force version numbers to be set
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-11-28 16:02:15 -08:00
Tudor Marcu 7a0f60453a Fix path error on signature output
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-11-16 15:23:55 -08:00
Tudor Marcu 52f28e0425 Fix location of Manifest.MoM for signing
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-11-14 17:13:05 -08:00
Tudor Marcu 5dbc222b10 Add helpers file for the scripts to use
This will do a lot of the ugly work that does not need to be taking up space
in the main scripts, and should be abstracted out so they are easier to read.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2016-10-27 15:09:04 -07:00