Commit graph

454 commits

Author SHA1 Message Date
Ondřej Míchal
f246d20fa6 build: Install the tests
Installing the tests will let downstream distributors like Fedora run
them as part of their build and CI systems.

https://github.com/containers/toolbox/pull/511
2020-08-13 11:34:37 +02:00
Ondřej Míchal
6eba08ff9e Add CONTRIBUTING.md
Having some contributing guidelines is good!

I wrote of this mostly from top of my head (but I took inspiration from
projects like Podman or Atom). Maybe some parts are not very clear.
2020-08-12 11:57:41 +02:00
Harry Míchal
09896ebfcd Update issue templates
Bug reporters most of the time don't know what and how much info they
should share with us.

I heavily based the bug report template on Podman's[0].

[0] https://github.com/containers/podman/blob/master/.github/ISSUE_TEMPLATE.md

https://github.com/containers/toolbox/pull/459
2020-08-12 11:51:39 +02:00
Debarshi Ray
2befde83d1 cmd/initContainer: Mount a tmpfs at /tmp to match the host
Podman doesn't mount a tmpfs at /tmp by default - it needs to be
separately requested. However, doing it as part of 'podman create ...'
won't add a tmpfs at /tmp for existing toolbox containers. Therefore,
it's best done as part of the entry point.

The mount options are the same as used by systemd (see tmp.mount) to
provide a tmpfs at the host's /tmp.

For what it's worth, the mount flags do differ slightly from the host.

The host has:
$ findmnt --output OPTIONS,PROPAGATION /tmp
OPTIONS                  PROPAGATION
rw,nosuid,nodev,seclabel shared

The container has:
$ findmnt --output OPTIONS,PROPAGATION /tmp
OPTIONS                                        PROPAGATION
rw,nosuid,nodev,seclabel,uid=100000,gid=100000 private

The uid and gid options don't show up on the host because both are 0,
and hence skipped by the tools.

https://github.com/containers/toolbox/issues/513
2020-08-05 16:29:30 +02:00
Debarshi Ray
679680df59 cmd/run: Make it more obvious when falling back to /bin/bash
Users, who prefer shells other than Bash, tend to get confused when
Toolbox presents a Bash prompt to them. It would be better to be more
upfront about what the problem is, so that users can self-support
themselves.

https://github.com/containers/toolbox/issues/18
2020-08-04 14:11:51 +02:00
Debarshi Ray
238a678264 Prepare 0.0.93 2020-07-24 17:44:51 +02:00
Ondřej Míchal
8168e0f58c cmd/list: Handle API change of Podman 2.1 in podman images
Since Podman 2.1 the field 'Created' of `podman images --format json`
no longer holds a string with human-readable string but holds a Unix
time integer[0].

[0] https://github.com/containers/podman/pull/6815

https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:59 +02:00
Ondřej Míchal
e772207831 cmd/list, cmd/run: Decode image/container JSONs to typed structs
Every time Podman changes their JSON API Toolbox breaks horribly. That
is caused by the combination of decoding the JSON purely by hand and by
the complete lack of type assertions to make the process stable.

I previously didn't know that unmarshalling with Go works on the 'do
the best job it can' logic (thank you Owen!). This makes the need to
check for subtle changes in the names of fields go away and type
checking a bit more bearable (marking the questioned field as
interface{} and then immediatelly type switch).

If even now an existing field does not hold an expected value the field
will remain blank.

To take this a bit further, I created two types (toolboxImage and
toolboxContainer) that are used by both functions for returning the
list of images and containers. Instead of using getters for properties
that need some checks or adjustments this uses a custom unmarshaling
function (Owen's idea; thanks!).

The work around populating the two new types is a bit hacky
(marshalling and already unmarshalled JSON - that was unmarshalled to
[]map[string]interface{} - that is then unmarshalled to either
toolboxImage or toolboxContainer. This is done to prevent a major
refactoring before the 0.1.0 release. This should be changed for the
0.2.0 release.

https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:59 +02:00
Ondřej Míchal
4028c3ae3f pkg/utils: Add function creating human-readable duration strings
https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:57 +02:00
Ondřej Míchal
0e5c30d971 build: Add github.com/docker/go-units
This package will be used for generating a human-readable
representation of elapsed time (e.g., "5 minutes").

https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:51 +02:00
Debarshi Ray
06ef424c71 cmd/run: Adjust for changes in 'podman ps' in Podman 2.0
The key containing the container's name (ie., "Names") is no longer a
string, but a slice of strings.

https://github.com/containers/toolbox/pull/509
2020-07-23 15:28:02 +02:00
Ondřej Míchal
2aad8385e1 cmd/create: Update hint after creating a container
Rewritten version of Toolbox supports newer syntax for entering a
container: `toolbox enter <name-of-container>`. This new workflow should
be shown in the hint after creating a container with `toolbox create`.

https://github.com/containers/toolbox/issues/489
2020-07-22 23:56:26 +02:00
Harry Míchal
61a5f5158c cmd/list: Re-enable highlighting of running containers
The Go implementation did not highlight running containers because it
uses a special table writer from 'text/tabwriter' that does not
support colored output [0].

The trick used here is to use ANSI SGR terminal escape sequences [1]
on every line output by the table writer, including headers, and make
the escape sequences use the same number of characters. eg., even
though it's idiomatic to use "\033[0m" to reset the SGR attributes,
such as color; each non-colored line is prefixed with "\033[0;00m" to
ensure that it has the same number of characters as "\033[1;32m", which
is used for bold green output.

Therefore, not only are the non-colored lines wrapped in a redundant
pair of ANSI SGR terminal escape sequences, they are carefully crafted
to match the escape sequences for colored output.

Tested on VTE and xterm.

[0] https://github.com/golang/go/pull/35017
[1] https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters

https://github.com/containers/toolbox/pull/494
2020-07-22 23:29:44 +02:00
Ondřej Míchal
68c585f8b3 test/system: Don't check the output of 'toolbox run'
For some reason running 'toolbox run echo Hello World' in the tests in
the environment of Zuul is causing problems. Bats saves the output of
ran command to $output that can be then checked if it contains the right
output. This variable sometimes holds in this case the right output
("Hello World") but more often it is blank, causing the tests to fail.

I don't know the culprit, so for now I'm commenting out the checks to
make the CI pass again.

https://github.com/containers/toolbox/issues/410
2020-07-22 14:47:42 +02:00
Ondřej Míchal
8c971b381a playbooks, .zuul: Clarify naming and descriptions
Not all tests are the same and the ones we're currently running are
system tests. Also the mention of 'podman-stable' is not that important
because we're using the version in the 'stable' stream of Fedora
releases.

https://github.com/containers/toolbox/pull/508
2020-07-21 17:09:17 +02:00
Harry Míchal
cf1b74e1db .zuul, playbooks/fedora-32: Enable testing for Fedora 32
New release out, we need to run the tests there.

https://github.com/containers/toolbox/pull/507
2020-07-21 16:31:56 +02:00
Harry Míchal
5a651eae2f playbooks, test/system: Test the Go implementation and update tests
In the Go implementation, when the 'rm' and 'rmi' commands fail to
remove a container or image, they don't use a non-zero exit code.
There's currently no nice fix for this. So, the tests have been
adjusted as a temporary measure.

https://github.com/containers/toolbox/pull/507
2020-07-21 16:31:50 +02:00
Harry Míchal
9c5bc56bbd playbooks: Add Go to the list of build dependencies
Otherwise, the tests on Fedora 31 and Rawhide fail with:
  meson.build:8:0: ERROR: Program(s) ['go'] not found or not executable

https://github.com/containers/toolbox/pull/506
2020-07-21 16:04:40 +02:00
Debarshi Ray
bf815d3d73 cmd/create: Restore the spinner, when pulling an image, to stdout
This doesn't seem to have any user-visible effect. However, since the
line was inadvertently removed, it's good to put it back.

Fallout from 950f510872

https://github.com/containers/toolbox/pull/498
2020-07-10 12:36:03 +02:00
Harry Míchal
950f510872 cmd/create: Show the spinner only when connected to a terminal
It doesn't make sense to show a spinner when the output is redirected
to something other than a terminal. When the output is not connected
to a terminal, the terminal escape sequences and other control
characters used to render the spinner leads to some spurious
characters in the output, which confuses the test suite.

This uses the golang.org/x/crypto/ssh/terminal package to check if the
standard output is connected to a terminal or not, which is also what
Podman uses. The other option was the github.com/mattn/go-isatty
package but using it leads to a slightly bigger binary - 7778323 bytes
versus 7782284.

[0] https://github.com/briandowns/spinner

https://github.com/containers/toolbox/pull/496
2020-07-10 11:56:58 +02:00
Harry Míchal
d8f74b538f .zuul: Style fix
https://github.com/containers/toolbox/pull/495
2020-07-09 16:02:53 +02:00
Harry Míchal
6bcd9fd0c4 .zuul, playbooks/fedora-30: Drop testing for Fedora 30
Fedora 30 reached it's End of Life on the 26th of May, 2020 [1]; and
Toolbox requires Go 1.13 which is not available in Fedora 30.

[1] https://fedoraproject.org/wiki/End_of_life

https://github.com/containers/toolbox/pull/495
2020-07-09 16:02:49 +02:00
Debarshi Ray
85ada1e77c README.md: List out dependencies and installation instructions
Based on work done by Natanael.

https://github.com/containers/toolbox/pull/492
2020-07-07 19:36:58 +02:00
Mario Sebastian Chacon
9488c95038 cmd/root: Use the correct verb format for string
https://github.com/containers/toolbox/pull/480
2020-07-07 18:43:58 +02:00
Morten Linderud
0e5592bada build: Ensure reproducible builds
The Go compiler embeds full paths to modules and dependencies into the
binary. This prevents people from reconstructing a bit-for-bit identical
toolbox binary without going through several hoops.

Without patch:

    $ strings build/src/toolbox | grep "$HOME" | wc -l
    105

With patch:

    $ strings build/src/toolbox | grep "$HOME" | wc -l
    0

https://github.com/containers/toolbox/pull/448

Signed-off-by: Morten Linderud <morten@linderud.pw>
2020-07-07 18:11:38 +02:00
Ondřej Míchal
843d4ce2cc pkg/podman: Speed things up by caching the Podman version at runtime
We call `podman version` every time we want to check Podman's version.
This slows Toolbox down considerably. It's more efficient if we call
`podman version` just once and remember the output during runtime and
use the cached value.

https://github.com/containers/toolbox/pull/481
2020-07-03 19:09:39 +02:00
Debarshi Ray
bcacb1196c pkg/podman: Rename a variable
The subsequent commit will introduce a global variable called
podmanVersion, so this will prevent the local variable from colliding
with the global.

https://github.com/containers/toolbox/pull/481
2020-07-03 19:06:09 +02:00
Debarshi Ray
cb5c77eae5 Prepare 0.0.92 2020-07-03 15:54:02 +02:00
Debarshi Ray
b5552d3351 build, pkg/version: Embed the version from Meson into the binary
This removes the need to manually update the version in the Go source
code when making a release.

https://github.com/containers/toolbox/pull/487
2020-07-03 15:28:36 +02:00
Debarshi Ray
ad87a30caf pkg/version: Use a string, not a struct, to for the version information
The subsequent commit will automatically embed the project's version
encoded in Meson into the toolbox binary during the build. This will
remove the need to manually update the version information in the Go
source code. Consolidating the version information reduces the chances
of human error while making a new release. Note, how the 0.0.91 release
forgot to update the version in the Go sources.

This will be done by feeding the version string from Meson into
go-build-wrapper, which will use Go's -X linker flag to embed it into
the final toolbox binary. Since Meson stores the version information
as a string, it's convenient to have the Go code do the same.

https://github.com/containers/toolbox/pull/487
2020-07-03 15:28:36 +02:00
Debarshi Ray
982f10e29b pkg/version: Mark variable as private since there's an accessor for it
Clients of this package should use the GetVersion function to get the
version as a string. The variable that actually stores the version
information is an implementation detail and meant to be private.

https://github.com/containers/toolbox/pull/487
2020-07-03 15:28:28 +02:00
Debarshi Ray
38d6d4702c pkg/utils: Make it build on aarch64
The syscall.Dup2 wrapper isn't defined on aarch64, which breaks the
build as:
  ../../pkg/utils/utils.go:551:12: undefined: syscall.Dup2

https://github.com/containers/toolbox/pull/486
2020-06-30 18:32:49 +02:00
Debarshi Ray
387872c6a3 Prepare 0.0.91 2020-06-27 16:27:02 +02:00
Harry Míchal
dad7e99ea5 cmd/list, cmd/rm: Adjust for changes in 'podman ps' in Podman 2.0
These keys in 'podman ps --format json' were renamed in Podman 2.0:
  * "ID" to "Id"
  * "Created" to "CreatedAt"
  * "Status" to "State"

The key containing the container's name (ie., "Names") is no longer a
string, but a slice of strings.

https://github.com/containers/toolbox/pull/471
2020-06-25 02:16:02 +02:00
Harry Míchal
d0af91502e cmd/list, cmd/rmi: Adjust for changes in 'podman images' in Podman 2.0
The key containing the image's hash in 'podman images --format json'
was renamed to "Id" in Podman 2.0.

https://github.com/containers/toolbox/pull/471
2020-06-25 02:14:57 +02:00
Harry Míchal
5967ab6be5 cmd/list: Use utils.ShortID instead of open-coding the shortening
https://github.com/containers/toolbox/pull/479
2020-06-24 18:01:21 +02:00
Jose Miguel Parrella
89ff98d8c3 cmd/run, sh: Show an error if $PWD is missing inside the container
It might happen that the current working directory in the present
environment is missing inside the container that's going to be used.
So far, Toolbox would fail silently, which wasn't very obvious.

Some changes by Debarshi Ray and Harry Míchal.

https://github.com/containers/toolbox/issues/369
2020-06-23 19:26:59 +02:00
Debarshi Ray
1daa158385 images: Add gvfs-client to Fedoras 31, 32 and 33
The gvfs-client package is necessary for GIO-based processes inside
toolbox containers to use the GVfs backend and volume monitor daemons,
and it comes preinstalled on Fedora Silverblue and Workstation.

Only the images for currently maintained Fedoras (ie., 31, 32 and 33)
were updated.

https://github.com/containers/toolbox/pull/466
2020-06-10 15:40:27 +02:00
Debarshi Ray
dcaf06a950 cmd/create: Don't use gh.c/coreos/go-systemd
Fedora's golang-github-coreos-systemd package is still at version 19,
while the support for Go modules is only available from version 22.
Since all that's necessary is to retrieve the 'Listen' property from
the sssd-kcm.socket unit, it's quite easy to do so directly using Go's
D-Bus bindings.

The systemdNeedsEscape and systemdPathBusEscape functions are copied
from github.com/coreos/go-systemd's needsEscape and PathBusEscape
functions respectively.

The github.com/coreos/go-systemd code is licensed under the ASL 2.0,
the same as Toolbox. It's copyright notice lists 'CoreOS, Inc.', but
since CoreOS has been acquired by Red Hat [1], it should be covered by
Toolbox's existing copyright notices that list 'Red Hat, Inc'.

[1] https://www.redhat.com/en/about/press-releases/red-hat-acquire-coreos-expanding-its-kubernetes-and-containers-leadership

https://github.com/containers/toolbox/pull/444
2020-05-14 23:54:43 +02:00
Debarshi Ray
35752e9943 build: Lower the minimum gh.c/spf13/cobra version to 0.0.5
Fedora's golang-github-spf13-cobra package is still at 0.0.5. Since
there's no real need for anything newer, lowering the requirement will
make it easier to build on Fedora.

https://github.com/containers/toolbox/pull/444
2020-05-14 23:54:38 +02:00
Debarshi Ray
95d3953aec build: Lower the minimum gh.c/sirupsen/logrus version to 1.4.2
Fedora's golang-github-sirupsen-logrus package is still at 1.4.2. Since
there's no real need for anything newer, lowering the requirement will
make it easier to build on Fedora.

https://github.com/containers/toolbox/pull/444
2020-05-14 23:54:33 +02:00
Harry Míchal
1e3d25c426 Prepare 0.0.90
https://github.com/containers/toolbox/pull/435
2020-05-14 16:42:52 +02:00
Harry Míchal
493bc1ffd5 .zuul, playbooks/shellcheck: Use Go 1.13
Toolbox requires Go 1.13, while Fedora 30 only has Go 1.12.17.
Therefore the test environment needs to be upgraded to something more
recent.

Otherwise, the test fails with:
  note: module requires Go 1.13

The name of the go-md2man package changed in Fedora 31, and hence had
to be updated.

https://github.com/containers/toolbox/pull/442
2020-05-14 16:14:47 +02:00
Harry Míchal
c95aacc488 playbooks/shellcheck: Add Go to the list of build dependencies
Otherwise, the test fails with:
  meson.build:8:0: ERROR: Program(s) ['go'] not found or not executable

https://github.com/containers/toolbox/pull/441
2020-05-14 15:39:00 +02:00
Debarshi Ray
0b3c66434e build: Ship the Go implementation by default, not the POSIX shell one
The Go implementation is now considered stable enough for wider use,
and should have feature parity with its POSIX shell counterpart.

https://github.com/containers/toolbox/pull/437
2020-05-14 09:53:18 +02:00
TomSweeneyRedHat
edf6aa4d1c Add Security Policy
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2020-05-13 14:37:08 +02:00
Debarshi Ray
ebd92b9905 cmd/reset: Implement the reset command in Go
https://github.com/containers/toolbox/pull/318
2020-05-13 13:22:58 +02:00
Harry Míchal
662bd89931 cmd/enter: Implement the enter command in Go
The Go version supports specifying the name of the toolbox container as
'toolbox enter NAME', on top of the 'toolbox enter --container NAME'
form.

https://github.com/containers/toolbox/pull/318
2020-05-13 13:22:58 +02:00
Harry Míchal
238f2451e7 cmd/run: Implement the run command in Go
https://github.com/containers/toolbox/pull/318
2020-05-13 13:22:58 +02:00
Harry Míchal
cf5c58ab00 cmd/run: Add function to get the entry point PID of a container
For some reason, the State:Pid value in the JSON returned by
'podman inspect --format json --type container' is a float64 [1], even
though internally Podman represents it as an int.

[1] https://github.com/containers/libpod/issues/6105

https://github.com/containers/toolbox/pull/318
2020-05-13 13:22:58 +02:00