website icon indicating copy to clipboard operation
website copied to clipboard

Optimising deploy script to use GNU parallel

Open mohitsaxenaknoldus opened this issue 3 years ago • 25 comments

Fixes #674

mohitsaxenaknoldus avatar Oct 02 '21 08:10 mohitsaxenaknoldus

Thank you for making your first PR on website!

We are glad about every contribution!

Feel free to add yourself to our AUTHORS file to appear as a contributor on our websites.

welcome[bot] avatar Oct 02 '21 08:10 welcome[bot]

I need some help fixing this Netlify thing. It says it can't find apk. @mal-tee

mohitsaxenaknoldus avatar Oct 02 '21 08:10 mohitsaxenaknoldus

I think we have to install that manually. ~~@baltpeter Can you do us the honors?~~

But in general we want to move the installation outside of the deploy.sh script. Mohit, can you please add parallel as a requirement to the README and add it to our CI config: https://github.com/datenanfragen/website/blob/master/.circleci/config.yml

mal-tee avatar Oct 02 '21 09:10 mal-tee

Can you try it again without the install-step? It might be preinstalled in netlify.

mal-tee avatar Oct 02 '21 09:10 mal-tee

Can you try it again without the install-step? It might be preinstalled in netlify.

Looks like it doesn't.

mohitsaxenaknoldus avatar Oct 02 '21 09:10 mohitsaxenaknoldus

Sad. CI stuff. :( That means we have to check if we are in netlify and if we are, we should obtain a binary from somewhere and just use that. Or build it ourselves in the script.

mal-tee avatar Oct 02 '21 09:10 mal-tee

I've just tested the improved script and I am quite happy:

# old:
./deploy.sh  218,96s user 28,39s system 191% cpu 2:09,35 total
# this PR:
./deploy.sh  221,53s user 19,38s system 250% cpu 1:36,34 total

mal-tee avatar Oct 02 '21 09:10 mal-tee

I've just tested the improved script and I am quite happy:

# old:
./deploy.sh  218,96s user 28,39s system 191% cpu 2:09,35 total
# this PR:
./deploy.sh  221,53s user 19,38s system 250% cpu 1:36,34 total

Not sure whether this will yield a noticeable improvement, but it would be nice if we could benchmark whether also parallelizing the copying of the companies and supervisory authorities is worth it.

baltpeter avatar Oct 02 '21 09:10 baltpeter

Thanks! Other than the comments below, if you install parallel in Netlify, this is good to go as far as I'm concerned.

Resolved the comments. How can I install parallel in Netlify?

mohitsaxenaknoldus avatar Oct 02 '21 19:10 mohitsaxenaknoldus

That's unfortunately not so easy. You don't have root in the container (https://answers.netlify.com/t/apt-get-install-build-dependency/3095/2) and there doesn't seem to be a binary distribution of parallel (https://www.gnu.org/software/parallel/).

And compiling it each time would likely negate the benefits of using parallel. But you could try this:

https://git.savannah.gnu.org/cgit/parallel.git/tree/README#n84

baltpeter avatar Oct 02 '21 20:10 baltpeter

That's unfortunately not so easy. You don't have root in the container (https://answers.netlify.com/t/apt-get-install-build-dependency/3095/2) and there doesn't seem to be a binary distribution of parallel (https://www.gnu.org/software/parallel/).

And compiling it each time would likely negate the benefits of using parallel. But you could try this:

https://git.savannah.gnu.org/cgit/parallel.git/tree/README#n84

Is it not possible to install it on your Netlify runner from the backend?

mohitsaxenaknoldus avatar Oct 02 '21 21:10 mohitsaxenaknoldus

Is it not possible to install it on your Netlify runner from the backend?

No.

baltpeter avatar Oct 02 '21 21:10 baltpeter

@baltpeter So I've added the --embed solution but now we are stuck at apk: command not found. @mal-tee You said this needs to be installed manually?

mohitsaxenaknoldus avatar Oct 07 '21 08:10 mohitsaxenaknoldus

I was slightly mistaken. We need to install it manually as in getting it in the deploy-script, cause we can not install things. Did you try to acquire a binary, as @baltpeter proposed?

https://git.savannah.gnu.org/cgit/parallel.git/tree/README#n84

mal-tee avatar Oct 07 '21 08:10 mal-tee

I was slightly mistaken. We need to install it manually as in getting it in the deploy-script, cause we can not install things. Did you try to acquire a binary, as @baltpeter proposed?

https://git.savannah.gnu.org/cgit/parallel.git/tree/README#n84

That part is done! But to install the binary we need dpkg installed and for that, we need to have apk on Netlify.

mohitsaxenaknoldus avatar Oct 07 '21 08:10 mohitsaxenaknoldus

Sorry, I can't follow you. I've checked the install script at pi.dk/3/ and the source code's configure and makefile and couldn't find a reference to dpkg.

mal-tee avatar Oct 07 '21 08:10 mal-tee

Sorry, I can't follow you. I've checked the install script at pi.dk/3/ and the source code's configure and makefile and couldn't find a reference to dpkg.

This is what I am trying to do:

wget "https://download.opensuse.org/repositories/home:/tange/xUbuntu_14.04/all/parallel_20210922_all.deb"
apk add dpkg
dpkg -x parallel_20210922_all.deb ~

I downloaded its .deb and was trying to install it using dpkg.

mohitsaxenaknoldus avatar Oct 07 '21 09:10 mohitsaxenaknoldus

A couple of notes:

  • The --embed won't work here. I was referring to the "= Minimal installation =" heading, that's the line I linked to.
  • As I said, you don't have root in Netlify. Thus, it isn't possible to run dpkg, apt, apk or any of the common package managers. I know that's annoying but there is nothing we can do about that.
  • In this case, this isn't really a problem, though. The instructions I have linked show that you can just download parallel as a script, make that executable and add it to the $PATH.
  • You'll need to make sure to run these installation steps only for Netlify. See the Netlify docs on how to detect that, pretty sure they set an environment variable.

baltpeter avatar Oct 07 '21 09:10 baltpeter

A couple of notes:

  • The --embed won't work here. I was referring to the "= Minimal installation =" heading, that's the line I linked to.
  • As I said, you don't have root in Netlify. Thus, it isn't possible to run dpkg, apt, apk or any of the common package managers. I know that's annoying but there is nothing we can do about that.
  • In this case, this isn't really a problem, though. The instructions I have linked show that you can just download parallel as a script, make that executable and add it to the $PATH.
  • You'll need to make sure to run these installation steps only for Netlify. See the Netlify docs on how to detect that, pretty sure they set an environment variable.

Thanks for the clarification! I've done it and tested it on my Ubuntu 20.04 and it works. However, it still fails to find parallel on Netlify. Maybe it is using some other version of Ubuntu that is following a different structure. Which Ubuntu container is it using? @mal-tee @baltpeter

mohitsaxenaknoldus avatar Oct 07 '21 10:10 mohitsaxenaknoldus

Ok so after adding exit to the loop it is now missing the public folder which is being ignored by the .gitignore. I think we are close!

mohitsaxenaknoldus avatar Oct 07 '21 11:10 mohitsaxenaknoldus

Ok so after adding exit to the loop it is now missing the public folder which is being ignored by the .gitignore. Is it supposed to fail at this point guys? I think we are close!

mohitsaxenaknoldus avatar Oct 07 '21 11:10 mohitsaxenaknoldus

Which Ubuntu container is it using? @mal-tee @baltpeter

Seems like netlify are using 20.04 (https://github.com/netlify/build-image/blob/focal/Dockerfile)

Ok so after adding exit to the loop it is now missing the public folder which is being ignored by the .gitignore. Is it supposed to fail at this point guys?

No.

It was missing the public folder due to this branch filter: if [ "$NETLIFY" = "true" ] && [ "$BRANCH" = "master" ]; All checks are passing now! You can re-run your performance tests again @mal-tee @baltpeter

mohitsaxenaknoldus avatar Oct 11 '21 11:10 mohitsaxenaknoldus

As @mal-tee said, disabling the deploy previews with Netlify is obviously not an option.

I will look at solving the Netlify problem myself on your branch. But I can't make any promises as to when that is going to happen, there's a lot of other stuff I have to do first.

baltpeter avatar Oct 11 '21 15:10 baltpeter

As @mal-tee said, disabling the deploy previews with Netlify is obviously not an option.

I will look at solving the Netlify problem myself on your branch. But I can't make any promises as to when that is going to happen, there's a lot of other stuff I have to do first.

Hey, were you guys able to fix it?

mohitsaxenaknoldus avatar Nov 26 '21 15:11 mohitsaxenaknoldus

Hey, were you guys able to fix it?

No, unfortunately, I didn't have time for that yet.

baltpeter avatar Dec 01 '21 19:12 baltpeter

Seems like parallel is (or was?) a single perl script: https://www.gnu.org/software/parallel/parallel_design.html

mal-tee avatar Mar 19 '23 18:03 mal-tee