Skip to content

Added new dynamic-ubuntu-wait.sh #4

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

Merged
merged 13 commits into from
Sep 9, 2020
Merged

Conversation

eak12913
Copy link
Contributor

A utility script that can be curled and used in our various packer builds when we construct ubuntu AMIs.

@eak12913 eak12913 requested a review from brikis98 May 23, 2018 18:31
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

Code looks great. Now it just needs an example and test :)

@brikis98
Copy link
Member

Oh, also, please add it to the root README and show an example one-liner of how it can be used (via curl and |).

@eak12913
Copy link
Contributor Author

Jim, I've added the example and the call-out in the README but I'm not entirely sure how to test this. The only test I can think of would have to be a go test of building an AMI using two different packer templates. One with the curling of this script and one without. The expectation being that the packer template that doesn't curl this script gets an error while the one that does curl this script gets no error. Is this what you are thinking of?

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

A Packer template built on Ubuntu that calls your script first and then apt-get update && apt-get install <something silly>, plus a test case for the same, would prob be enough.

README.md Outdated


`curl -Ls https://raw.githubusercontent.com/gruntwork-io/bash-commons/dynamic-ubuntu-waiter/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash`
Copy link
Member

Choose a reason for hiding this comment

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

-LsS. Also, that URL doesn't look quite right... And it should be versioned.

Choose a reason for hiding this comment

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

We should come up with an official Gruntwork standard for curl. I actually like to use the fully laid out options of:

curl --location --silent --fail --show-error ...

This will:

  • Follow redirects
  • Output nothing
  • ...unless there's an error
  • Return a non-zero exit code if anything other than a 2XX HTTP response code is returned.

The one issue is that sometimes an API will return a 2XX response but along with an error, but I haven't been able to come up with anything better.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed for scripts, but with the curl | bash one-liner, you typically prefer brevity...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jim - is this what you were thinking for the url with version?

curl -LsS https://raw.githubusercontent.com/gruntwork-io/bash-commons/[VERSION]/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash

Copy link
Member

Choose a reason for hiding this comment

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

Yup!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case: done :-)

Choose a reason for hiding this comment

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

Fair enough on the brevity, but I'm wondering if this should be:

curl -LsSf https://raw.githubusercontent.com/gruntwork-io/bash-commons/[VERSION]/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash

Try curling a URL that 404s and see if this returns a non-zero exit code (and therefore causes the entire script to exit), which is what we would want for an invalid URL. That's my goal in adding the -f / --fail. Otherwise, I'm worried that the curl call could fail (e.g. for transient reasons) and lead to confusing errors for users.

README.md Outdated
@@ -122,7 +124,9 @@ Here's an overview of the modules available in `bash-commons`:

* `string.sh`: A collection of string manipulation functions, such as checking if a string contains specific text,
stripping prefixes, and stripping suffixes.


* `dynamic-ubuntu-wait.sh`: A script that dynamically waits for Ubuntu automatic update mechanism to
Copy link
Member

Choose a reason for hiding this comment

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

Alphabetic order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@brikis98
Copy link
Member

Just add an example Packer template that uses this and a test for same, and this is good to go.

@yorinasub17
Copy link
Contributor

I am resurrecting this PR because we are using it in our ELK AMI examples and it feels sketchy to use unreleased code.

I added a go integration test for testing this (f32ccd6), but one problem is that the current circleCI build doesn't have AWS credentials, so it is failing. Is there any risk to adding the credentials?

The other issue I ran into is that the checksums for the shellcheck repo is now broken. Digging in I landed on this issue which suggest that we should be sourcing them from github now, so I fixed the docker container: b6ea582

@yorinasub17 yorinasub17 requested a review from brikis98 September 3, 2020 16:45
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

Adding AWS creds to this repo is fine.

Apparently, with the new CircleCi, you do that using contexts. I added our machine user data to a context called "Gruntwork Admin," and I think you can use it by adding context: Gruntwork Admin to a job:

workflows:
   my-workflow:
     jobs:
       - run-tests:
           context: Gruntwork Admin

@yorinasub17
Copy link
Contributor

Apparently, with the new CircleCi, you do that using contexts. I added our machine user data to a context called "Gruntwork Admin," and I think you can use it by adding context: Gruntwork Admin to a job:

Thanks! Just added in to see if it works.

@yorinasub17 yorinasub17 requested a review from brikis98 September 4, 2020 15:43
@yorinasub17
Copy link
Contributor

I believe I addressed all comments and the test is passing now!

Co-authored-by: Yevgeniy Brikman <brikis98@users.noreply.github.com>
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

LGTM!

@yorinasub17
Copy link
Contributor

Thanks for review! Going to merge and release this now.

@yorinasub17 yorinasub17 merged commit 013a0b4 into master Sep 9, 2020
@yorinasub17 yorinasub17 deleted the dynamic-ubuntu-waiter branch September 9, 2020 19:19
@brikis98 brikis98 restored the dynamic-ubuntu-waiter branch October 8, 2020 11:33
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.

4 participants