Skip to content

base: docker-ce: Untar images before running docker#200

Merged
ricardosalveti merged 1 commit intomasterfrom
preload-container-images
Aug 4, 2020
Merged

base: docker-ce: Untar images before running docker#200
ricardosalveti merged 1 commit intomasterfrom
preload-container-images

Conversation

@mike-sul
Copy link
Copy Markdown
Contributor

@mike-sul mike-sul commented Jul 30, 2020

Systemd service that extracts container images from a tarball into /var/lib/docker so they become 'preloaded'
before running dockerd service.
The tarball is generated and injected into a system image/rootfs (WIC) either by lmp or container build or by fioctl (TBD).
This should go with foundriesio/ci-scripts#73 and https://git.foundries.io/development/cloudplatforms/infrastructure/repoz/merge_requests/15

Signed-off-by: Mike Sul [email protected]


# pre-load container images into the docker data root directory (only works for overlay2 graph driver)
ExecStartPre=-/bin/sh -c 'mkdir -p /var/lib/docker && for f in `find /var/sota/import -name "*.tar"`; do echo "compose app: preloading $f" && tar -xf $f -C /var/lib/docker/ && rm $f; done'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever - so it only runs once, unless you add to that folder on subsequent boots? I'm guessing you may have thoughts on (ab)using this later on?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we should just create a separated service file just for importing the containers, as that way we can probably control the process better and avoid changing the main docker service file. That way the user can add or remove the logic by deciding what to include at the lmp image.

If we create another service we can make it run before docker and only when there are known tar files at var/sota/import (e.g. ConditionPathExistsGlob=/var/sota/import/*.tar).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way the user can add or remove the logic by deciding what to include at the lmp image.

This is actually for the container build. An assumption is that a customer makes lmp builds rarely and normally works with container build and if at some point he/she decides to get a system image pre-loaded with his/her latest apps' container images then these ci-scripts params should be turned on https://source.foundries.io/factories/msul-dev01/ci-scripts.git/tree/factory-config.yml#n38. Moreover, @doanac thinks that we should add an additional command to fioctl that would trigger a job (container build run) that produces a system image with pre-loaded container images taking Target as an input. Such 'interface/API' assumes that each Target's lmp build/image should include the given logic unconditionally, so users could assemble a "preloaded" image for any Target they choose.

Having said that, I think it's not a big deal to add a new a systemd service. I agree that it would "probably control the process better and avoid changing the main docker service file". I just think that we might not need it at all in the future once we move to ostree.

@mike-sul mike-sul force-pushed the preload-container-images branch 4 times, most recently from 3e6113a to d7e6d2a Compare August 3, 2020 21:27
@@ -0,0 +1,17 @@
[Unit]
Description=Docker container images preloading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I put it there deliberately, IMHO it makes 'code' more readable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so we can separate the blocks via an empty line.


After=local-fs.target
Before=docker.service

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line.

ConditionPathExistsGlob=/var/sota/import/*.tar

[Service]
Type=oneshot
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is also recommended to use 'RemainAfterExit=yes' here, otherwise the service will show up as dead after being executed. This is not particularly clear to, but it seems the standard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read about it and tried it, but I don't see any reason it's needed in this particular case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just double-checked it once more, I don't see any difference in the service behavior with or without RemainAfterExit=yes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there is some difference. With RemainAfterExit=yes and if the conditions are met and the ExecStart* scripts return(s) 0 then the service state will be at Active: active (exited) state while without RemainAfterExit=yes or if the conditions are not met or one of ExecStart* scripts fail then it will be at Active: inactive (dead). Also, the service will be at this state Active: inactive (dead) after the second boot regardless of RemainAfterExit=yes.
If the service is at Active: inactive (dead) then the docker service restart causes a restart of the given service. It's not quite what we need but it doesn't cause any issue anyway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for investigating that one.

Type=oneshot

# pre-load container images into the docker data root directory (only works for overlay2 graph driver)
ExecStart=/bin/sh -c 'mkdir -p /var/lib/docker && for f in `find /var/sota/import -name "*.tar"`; do echo "Compose App: preloading $f" && tar -xf $f -C /var/lib/docker/ && rm $f; done'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move 'mkdir -p /var/lib/docker' to ExecStartPre.

Copy link
Copy Markdown
Contributor Author

@mike-sul mike-sul Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

After=local-fs.target
Before=docker.service

ConditionPathExists=/var/sota/import/installed_versions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this file is removed by aktualizr once it starts for the first time, so probably also good to add a dependency on aktualizr-lite (Before).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't bring any value.

Systemd service that extracts container images from a tarball into
/var/lib/docker, so they become 'preloaded' before running dockerd.
The tarball is generated and injected into a system image/rootfs (WIC)
either by lmp or container build or by fioctl (TBD).
We might have more than one tarball file in the future.

Signed-off-by: Mike Sul <[email protected]>
@mike-sul mike-sul force-pushed the preload-container-images branch from d7e6d2a to 0d56343 Compare August 4, 2020 08:32
@mike-sul
Copy link
Copy Markdown
Contributor Author

mike-sul commented Aug 4, 2020

@rsalveti Updated according to your comments and verified on qemu and rpi4 under different conditions, with available an image tarball, without it, behavior after rebooting, etc.

Copy link
Copy Markdown
Member

@ricardosalveti ricardosalveti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@ricardosalveti ricardosalveti merged commit 53f410a into master Aug 4, 2020
@mike-sul mike-sul deleted the preload-container-images branch October 7, 2020 07:33
quaresmajose pushed a commit that referenced this pull request Nov 9, 2022
Relevant changes:
- d323df3 Merge pull request #208 from Freescale/backport-207-to-honister
- 32aff9b linux-boundary: bump revision to bb58f0ee
- b123854 Merge pull request #204 from boundarydevices/honister
- 9e698af u-boot-boundary: fix fw_env.config management
- b4df0cf Merge pull request #201 from chrisdimich/honister
- 2ebd2e0 nitrogen8mp: Define nxp as default BSP
- 657e750 Merge pull request #200 from chrisdimich/honister
- 8f6984a u-boot-boundary: bump revision to 3d5e7f60
- b30688b linux-boundary: bump revision to 04f4286f

Signed-off-by: Ricardo Salveti <[email protected]>
quaresmajose pushed a commit that referenced this pull request Jan 10, 2023
Bumping go-errors to version v0.8.1-32-g5dd12d0, which comprises the following commits:

    5dd12d0 AddingPowerSupport_CI/Testing (#234)
    614d223 Revert "Support Go 1.13 error chains in `Cause` (#215)" (#220)
    49f8f61 Support Go 1.13 error chains in `Cause` (#215)
    004deef remove unnecessary use of fmt.Sprintf (#217)
    6d954f5 feat: support std errors functions (#213)
    7f95ac1 Add support for Go 1.13 error chains (#206)
    91f1693 travis.yml: add Go 1.13
    ca0248e fix travis, 1.10 doesnt support by unconvert anymore
    27936f6 travis.yml: add Go 1.12 (#200)
    856c240 Add json.Marshaler support to the Frame type. (#197)
    ffb6e22 Reduce allocations in StackTrace.Format (#194)
    e9933c1 Restore performance improvements from #150
    ee1923e Return errors.Frame to a uintptr
    72fa05e errors: detect unknown frames correctly (#192)
    c38ea53 Remove errors.Frame to runtime.Frame conversions (#189)
    c9e70be Makefile: switch to staticcheck (#187)
    ee4766c Fix error during merge
    584cbac Remove checks for old style anon funcs (#186)
    42ce1b6 Remove Frame methods (#185)
    937e8c5 gofmt -w
    e19cb69 Remove last reference to runtime.FuncForPC (#184)
    4f47277 Switch to runtime.CallersFrames (#183)
    537896a travis: remove Go 1.8 and earlier (#182)
    31aac83 travis: use Makefile (#181)
    5ac96ae Update README.md
    ba968bf gofmt -w errors.go (#179)
    059132a Update .travis.yml (#168)
    d58f942 Bump Travis versions (#172)
    6ed0a2e Fix StackTrace print example
    2233dee Copyedit the package documentation (#135)
    e981d1a Add WithMessagef function (#118)
    c059e47 fixed spelling (#156)
    816c908 travis.yml: add Go 1.10 (#154)
    e1ac100 reduce allocations when printing stack traces (#149)
    30136e2 Remove deadcode (#146)
    e881fd5 Fix minor typo in README.md (#142)
    8842a6e Add badge for number of dependent libraries (#109)
    e4f5060 Fix doc comment for exported Format func (#137)
    f15c970 Remove an unused argument of utility test func (#139)
    2b3a18b travis: add 1.9.x to go versions (#133)
    c605e28 Add doc comment for exported Format func (#115)
    ff09b13 Bump Go versions, use latest patch releases (#110)
    bfd5150 Move benchmark assigned err to global exported variable (#106)
    248dadf Bump Go versions (#91)

Signed-off-by: Bruce Ashfield <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants