Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further Optimizations #2092

Merged
merged 21 commits into from
Nov 9, 2023
Merged

Conversation

AlvinSchiller
Copy link
Collaborator

@AlvinSchiller AlvinSchiller commented Nov 6, 2023

This introduces further optimizations for maintenance and test runtime.

  • moved apt package definition in packages*.txt file (like requirements.txt for pip). The install/setup and test scripts now use this files.
  • use requirements.txt in test script to determine installed packages to test
  • optimized check of installed packages in test script, decreasing check runtime from several minutes to 30s
  • Dockerfile now uses new apt packages*.txt files to preinstall internal packages. This results in lowered runtime of the single tests (around 10 - 15 min), as most packages are already installed. The baseimage is cached so the installation is not performed in subsequent runs for that branch (considering cache policy).
    --- downside: image size in cache increases! from 300 MB to around 500 MB per debian version
  • save run specific image as artifact instead of using the cache (prevent cache trashing) (see Further Optimizations #2092 (comment))
  • correct variable usage
  • check homedir as prerequisite

Runtime summary:
after the first workflow run, which takes longer as it creates the docker image which is then cached, the subsequent runs finish in about 10 min (before around 25 min).

@coveralls
Copy link

coveralls commented Nov 6, 2023

Pull Request Test Coverage Report for Build 6805930329

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 76.82%

Totals Coverage Status
Change from base Build 6804842786: 0.0%
Covered Lines: 633
Relevant Lines: 824

💛 - Coveralls

Copy link
Collaborator

@Groovylein Groovylein left a comment

Choose a reason for hiding this comment

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

Looks good.

I currently don't have any setup available to test.

My suggestions are not blocking to integrate, but would make the code more readable.

shift

# read line from the file and remove comments. Pass it over xargs as arguments to the given command.
sed 's/#.*//g' ${package_file} | xargs "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it better understandable, if you call here the apt-get command instead of using the passed arguments?!

I mean:
sed 's/#.*//g' ${package_file} | xargs ${apt_get} install

The name of the function already implies, that something with apt will happen

Copy link
Collaborator Author

@AlvinSchiller AlvinSchiller Nov 6, 2023

Choose a reason for hiding this comment

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

yep could be done. I just wanted it to be in sync with the install and test script (see below) to not have the same logic solved in multiple ways.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed the function to call_with_args_from_file and added a function usage comment

shift

# read line from the file and remove comments. Pass it over xargs as arguments to the given command.
sed 's/#.*//g' ${package_file} | xargs "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it better understandable, if you call here the apt-get command instead of using the passed arguments?!

I mean:
sed 's/#.*//g' ${package_file} | xargs ${apt_get} install

The name of the function already implies, that something with apt will happen

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't want to define apt_get and allow_downgrades again as these are still used in the install_main function. And making them script wide available doesn't seem right either, as its only used in install_main.

The function body is used the same way in the test_installation script, only with the echo command.

Inthe test_installation script it named it "apt" mainly to distinguish from the function for the "pip" packages and carried over the name.

Choose a reason for hiding this comment

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

Shell scripts being shell scripts, maybe document the expected parameter(s) and that one should call this with a variant of sudo apt get install or something else that can take 1 parameter that takes a package name? (Obvious example: echo would just print the package and do nothing, but equally valid)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed the function to call_with_args_from_file and added a function usage comment

@@ -327,7 +334,7 @@ check_existing() {

# The install will be in the home dir of user pi
# Move to home directory now to check
cd ~ || exit
cd "${home_dir}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not your fault, but using now the same name for a local variable is confusing.

I would rename it within the function to local_home_diror something similar

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i just used the already existing variable home_dir to get rid of ~.

But i get your point. I renamed it to local_home_dir

shift

# read line from the file and remove comments. Pass it over xargs as arguments to the default echo command.
sed 's/#.*//g' ${package_file} | xargs "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it better understandable, if you call here the apt-get command instead of using the passed arguments?!

I mean:
sed 's/#.*//g' ${package_file} | xargs ${apt_get} install

The name of the function already implies, that something with apt will happen

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I named it "apt" mainly to distinguish from the function for the "pip" packages.
Also the command given here is not apt-get install but echo, as the test only reads the file content.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh right. That was just a copy paste fail.

Copy link
Collaborator Author

@AlvinSchiller AlvinSchiller Nov 8, 2023

Choose a reason for hiding this comment

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

merged "pip" and "apt" function into one. renamed the function to call_with_args_from_file and added a function usage comment

@AlvinSchiller
Copy link
Collaborator Author

AlvinSchiller commented Nov 7, 2023

I would make an additional change:
Currently the final docker images for the testjobs are also put in the cache, but they are only valid for a single workflow run (see #2082). With the additional file size and the soon coming bookworm test, this will most likely cause cache trashing (to many new items so the older but still need ones are already purged, causing a new creation of items). The explicit deletion of cache items is possible but not for pull request as the needed write permissions can't be granted (what makes this approach unusable).

The proposed change:
The final images are not put in the cache put uploaded as workflow artifacts. This does not count to the cache limits.
A new clean up job after the tests will delete this artifacts if the run was successful or cancelled.
If the tests failed the artifacts will be kept with a retention time of 2 days (possible values: 1-90 days). This makes reruns of single failured test possible in this period.
I didn't find any documentation about a maximum storage limit for artifact though.

This strategie will take a few minutes longer to run (upload) but is much safer in regards of health and time saving from using the cache properly.

@s-martin
Copy link
Collaborator

s-martin commented Nov 8, 2023

@AlvinSchiller, I just mergend #2084, so now your PR has some conflicts. Can you fix this?

@AlvinSchiller
Copy link
Collaborator Author

Fixed also the mpd service enablement for Spotify Installations ->
#2084 (comment)

Develop: https://github.com/MiczFlor/RPi-Jukebox-RFID/actions/runs/6804326866/job/18501808766#step:6:2496

@s-martin
Copy link
Collaborator

s-martin commented Nov 8, 2023

Sorry, I think the merge of the docs PR caused also conflicts again.

@s-martin s-martin added this to the 2.5 milestone Nov 9, 2023
@s-martin s-martin merged commit f610e5e into MiczFlor:develop Nov 9, 2023
33 of 34 checks passed
@AlvinSchiller AlvinSchiller deleted the feature/optimizations branch November 9, 2023 06:47
AlvinSchiller added a commit to AlvinSchiller/RPi-Jukebox-RFID that referenced this pull request Dec 21, 2023
* optimize check for installed packages (apt, pip)

* fix jukebox_dir

* remove package optimization from dockerfile

add comments in package step

* add package installation from file

test reads the same file. only one place to maintain

* install internal packages in Dockerfile

dont install resolvconf as it will fail in containers

* added textfile for arm sepcific packages

* removed as already part of install script

* add package textfile for autohotspot setup

* correct variable usage.

* check homedir as prerequisite

* some fixes

* read modules to test from file

* renamed package txt for raspberry pi specifics

* update sed call

* renamed local variable

* save images as artifact

* clarify function name. add function comment

* fixed mpd service enablement

* fix unnecessary rebuild of unrelated package files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants