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

chore: improve the run_macaron.sh script #521

Merged
merged 10 commits into from
Oct 24, 2023
Merged

Conversation

nathanwn
Copy link
Member

@nathanwn nathanwn commented Oct 18, 2023

This pull request makes a number of improvements to our current run_macaron.sh script.

This is to prepare for another pull request, #512, which adds support for Podman as an alternative container engine to run the Macaron image.

Set bash "strict" flags

Commit: 95cb003

The following bash built-in flags are added to the script. These flags effectively help make the script less error-prone.

  • set -e: exit immediately if a command fails (with non-zero return code), or if a function returns non-zero.
  • set -u: treat unset variables and parameters as errors when performing parameter expansion.
    Note: In case a variable ${VAR} is unset but we still need to expand, we can use the syntax ${VAR:-} to expand it to an empty string (bash documentation).
  • set -o pipefail: set the return value of a pipeline to the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully.

Reference: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html.

Simplify passing environment variables into the container

Commit: b4d49f0

During docker run, we can pass environment variables into the container as follows:

$ docker run [...] -e "http_proxy=${http_proxy}" [...]

In cases where we want the container to "inherit" the environment variables on the host, we do not need to explicitly specify the value, i.e., doing this should be enough:

$ docker run [...] -e http_proxy [...]

Passing the environment variables into the container in this implicit manner is also very useful when we want to use the set -x flag of bash for debugging purposes but do not want secret values to be logged out as plain text.

Inherit the JAVA_OPTS environment variable into the container

Commit: d1f6341

Proxy settings for the Gradle wrapper can also be set through the JAVA_OPTS environment variable (besides GRADLE_OPTS). We should also pass it into the container.

Other changes

  • b7374c2 and dca163b mostly remove redundant logic from the script.
  • 1147ede changes how analyze and verify-policy are referred to, from "actions" to "commands".
  • fff08a9 refactors functions in the script that check for the existence of files or directories. With set -u, these functions can return 1 and immediately stop the script with exit code 1.
  • c2bda95 renames the functions in the script to make the intentions clearer.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 18, 2023
@nathanwn nathanwn force-pushed the improve-run-macaron-sh branch from 1bca05d to d1f6341 Compare October 18, 2023 11:16
@nathanwn nathanwn marked this pull request as ready for review October 18, 2023 12:37
@nathanwn nathanwn self-assigned this Oct 18, 2023
@@ -373,10 +349,11 @@ proxy_var_names=(
"NO_PROXY"
"MAVEN_OPTS"
"GRADLE_OPTS"
"JAVA_OPTS"
Copy link
Member

Choose a reason for hiding this comment

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

The main reason we pass MAVEN_OPTS and GRADLE_OPTS is to download mvnw and gradlew when proxy is set. With JAVA_OPTS we will pass a lot more options, potentially interfering with the JVM process. Have you encountered a case where JAVA_OPTS is absolutely necessary and the other environment variables cannot be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted in d47f254.

@behnazh-w
Copy link
Member

We use action commands in the CLI RST documentations, which needs to be adjust to be consistent.

@nathanwn
Copy link
Member Author

We use action commands in the CLI RST documentation, which needs to be adjusted to be consistent.

RST doc has been adjusted in 57e3c16.

@tromai
Copy link
Member

tromai commented Oct 23, 2023

The latest changes to the RST doc files look good to me. My approval still holds.

@nathanwn nathanwn merged commit a78120b into staging Oct 24, 2023
9 checks passed
@nathanwn nathanwn deleted the improve-run-macaron-sh branch October 24, 2023 00:26
art1f1c3R pushed a commit that referenced this pull request Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants