From 0dd89fbc95a04192bc13f699ca14e4b4e7688944 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 02:54:14 +0000 Subject: [PATCH 1/9] tools, github: Add current source version writer This adds a script to produce SOURCE_VERSION which is useful to build envoy in a non-git (from an extracted release tarball) directory. Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tools/github/write_current_source_version.py diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py new file mode 100644 index 000000000000..b22f617817e1 --- /dev/null +++ b/tools/github/write_current_source_version.py @@ -0,0 +1,55 @@ +# Copyright 2020 Envoyproxy Authors + +# Produces SOURCE_VERSION file with content from current version commit hash. As a reminder, +# SOURCE_VERSION is required when building Envoy from an extracted release tarball (non-git). +# See: bazel/get_workspace_status for more information. +# +# The SOURCE_VERSION is produced by reading the VERSION.txt file then fetch the corresponding commit +# hass from GitHub. Note: This script can only be executed from project root directory of an +# extracted "release" tarball. + +import os +import sys +import json + +from urllib import request +from pathlib import Path + +if __name__ == "__main__": + # Simple check if a .git directory exists. We should only rely on information from "git". + if Path(".git").exists(): + print( + "Failed to create SOURCE_VERSION. " + "Run this script from an extracted release tarball directory." + ) + sys.exit(1) + + # Check if we have VERSION.txt available + current_version_file = Path("VERSION.txt") + if not current_version_file.exists(): + print( + "Failed to read VERSION.txt. " + "Run this script from project root of an extracted release tarball directory." + ) + sys.exit(1) + + current_version = current_version_file.read_text().rstrip() + + # Exit when we are in a "main" copy. + if current_version.endswith("-dev"): + print( + "Failed to create SOURCE_VERSION. " + "The current VERSION.txt contains version with '-dev' suffix. " + "Run this script from an extracted release tarball directory." + ) + sys.exit(1) + + # Fetch the current version commit information from GitHub. + with request.urlopen( + "https://api.github.com/repos/envoyproxy/envoy/commits/v" + current_version + ) as response: + commit_info = json.loads(response.read()) + source_version_file = Path("SOURCE_VERSION") + with source_version_file.open("w", encoding="utf-8") as source_version: + # Write the extracted current version commit hash "sha" to SOURCE_VERSION. + source_version.write(commit_info["sha"]) From 5a96c89a8bf9cf97bd72cac23798390e2270c2c0 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 02:56:17 +0000 Subject: [PATCH 2/9] Fix comment Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index b22f617817e1..3c77f5b814ad 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -1,5 +1,3 @@ -# Copyright 2020 Envoyproxy Authors - # Produces SOURCE_VERSION file with content from current version commit hash. As a reminder, # SOURCE_VERSION is required when building Envoy from an extracted release tarball (non-git). # See: bazel/get_workspace_status for more information. From 950ba6458f7bd5d7a18bbd4300e9ff2c1a576dae Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 03:03:14 +0000 Subject: [PATCH 3/9] Fix comment Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index 3c77f5b814ad..fe4e6f820d6b 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -14,7 +14,7 @@ from pathlib import Path if __name__ == "__main__": - # Simple check if a .git directory exists. We should only rely on information from "git". + # Simple check if a .git directory exists. When we are in a Git repo, we should rely on git. if Path(".git").exists(): print( "Failed to create SOURCE_VERSION. " From db4e64f2fa09f96d04c0deb42212935201ce3d72 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 03:04:29 +0000 Subject: [PATCH 4/9] No main Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 67 ++++++++++---------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index fe4e6f820d6b..96a4f2888070 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -13,41 +13,40 @@ from urllib import request from pathlib import Path -if __name__ == "__main__": - # Simple check if a .git directory exists. When we are in a Git repo, we should rely on git. - if Path(".git").exists(): - print( - "Failed to create SOURCE_VERSION. " - "Run this script from an extracted release tarball directory." - ) - sys.exit(1) +# Simple check if a .git directory exists. When we are in a Git repo, we should rely on git. +if Path(".git").exists(): + print( + "Failed to create SOURCE_VERSION. " + "Run this script from an extracted release tarball directory." + ) + sys.exit(1) - # Check if we have VERSION.txt available - current_version_file = Path("VERSION.txt") - if not current_version_file.exists(): - print( - "Failed to read VERSION.txt. " - "Run this script from project root of an extracted release tarball directory." - ) - sys.exit(1) +# Check if we have VERSION.txt available +current_version_file = Path("VERSION.txt") +if not current_version_file.exists(): + print( + "Failed to read VERSION.txt. " + "Run this script from project root of an extracted release tarball directory." + ) + sys.exit(1) - current_version = current_version_file.read_text().rstrip() +current_version = current_version_file.read_text().rstrip() - # Exit when we are in a "main" copy. - if current_version.endswith("-dev"): - print( - "Failed to create SOURCE_VERSION. " - "The current VERSION.txt contains version with '-dev' suffix. " - "Run this script from an extracted release tarball directory." - ) - sys.exit(1) +# Exit when we are in a "main" copy. +if current_version.endswith("-dev"): + print( + "Failed to create SOURCE_VERSION. " + "The current VERSION.txt contains version with '-dev' suffix. " + "Run this script from an extracted release tarball directory." + ) + sys.exit(1) - # Fetch the current version commit information from GitHub. - with request.urlopen( - "https://api.github.com/repos/envoyproxy/envoy/commits/v" + current_version - ) as response: - commit_info = json.loads(response.read()) - source_version_file = Path("SOURCE_VERSION") - with source_version_file.open("w", encoding="utf-8") as source_version: - # Write the extracted current version commit hash "sha" to SOURCE_VERSION. - source_version.write(commit_info["sha"]) +# Fetch the current version commit information from GitHub. +with request.urlopen( + "https://api.github.com/repos/envoyproxy/envoy/commits/v" + current_version +) as response: + commit_info = json.loads(response.read()) + source_version_file = Path("SOURCE_VERSION") + with source_version_file.open("w", encoding="utf-8") as source_version: + # Write the extracted current version commit hash "sha" to SOURCE_VERSION. + source_version.write(commit_info["sha"]) From 06f42a8d2227951ab36c625ab7e57f84e8767e5b Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 03:25:26 +0000 Subject: [PATCH 5/9] Fix format Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index 96a4f2888070..591175e7e001 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -6,7 +6,6 @@ # hass from GitHub. Note: This script can only be executed from project root directory of an # extracted "release" tarball. -import os import sys import json @@ -17,8 +16,7 @@ if Path(".git").exists(): print( "Failed to create SOURCE_VERSION. " - "Run this script from an extracted release tarball directory." - ) + "Run this script from an extracted release tarball directory.") sys.exit(1) # Check if we have VERSION.txt available @@ -26,8 +24,7 @@ if not current_version_file.exists(): print( "Failed to read VERSION.txt. " - "Run this script from project root of an extracted release tarball directory." - ) + "Run this script from project root of an extracted release tarball directory.") sys.exit(1) current_version = current_version_file.read_text().rstrip() @@ -37,14 +34,12 @@ print( "Failed to create SOURCE_VERSION. " "The current VERSION.txt contains version with '-dev' suffix. " - "Run this script from an extracted release tarball directory." - ) + "Run this script from an extracted release tarball directory.") sys.exit(1) # Fetch the current version commit information from GitHub. -with request.urlopen( - "https://api.github.com/repos/envoyproxy/envoy/commits/v" + current_version -) as response: +with request.urlopen("https://api.github.com/repos/envoyproxy/envoy/commits/v" + + current_version) as response: commit_info = json.loads(response.read()) source_version_file = Path("SOURCE_VERSION") with source_version_file.open("w", encoding="utf-8") as source_version: From d179328913224176bf330410678c63fdbdf2eba1 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 03:38:49 +0000 Subject: [PATCH 6/9] Fix comment again Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index 591175e7e001..e92ffb5df4a8 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -1,10 +1,12 @@ -# Produces SOURCE_VERSION file with content from current version commit hash. As a reminder, -# SOURCE_VERSION is required when building Envoy from an extracted release tarball (non-git). -# See: bazel/get_workspace_status for more information. +# This script produces SOURCE_VERSION file with content from current version commit hash. As a +# reminder,SOURCE_VERSION is required when building Envoy from an extracted release tarball +# (non-git). See: bazel/get_workspace_status for more information. # -# The SOURCE_VERSION is produced by reading the VERSION.txt file then fetch the corresponding commit -# hass from GitHub. Note: This script can only be executed from project root directory of an -# extracted "release" tarball. +# The SOURCE_VERSION file is produced by reading current version tag from VERSION.txt file then +# fetch the corresponding commit hash from GitHub. +# +# Note: This script can only be executed from project root directory of an extracted "release" +# tarball. import sys import json From 395077d0feaa8f1c832f2544d0fb7358102c0770 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 11:47:10 +0000 Subject: [PATCH 7/9] Review comments Signed-off-by: Dhi Aurrahman --- bazel/README.md | 12 ++++ tools/github/write_current_source_version.py | 66 ++++++++++---------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/bazel/README.md b/bazel/README.md index 5b7a0a84dfe8..97ee7308b365 100644 --- a/bazel/README.md +++ b/bazel/README.md @@ -32,6 +32,18 @@ independently sourced, the following steps should be followed: 1. Configure, build and/or install the [Envoy dependencies](https://www.envoyproxy.io/docs/envoy/latest/start/building#requirements). 1. `bazel build -c opt envoy` from the repository root. +### Building from a release tarball + +To build Envoy from a release tarball, you can download a release tarball from Assets section in each release in project [Releases page](https://github.com/envoyproxy/envoy/releases). +Given all required [Envoy dependencies](https://www.envoyproxy.io/docs/envoy/latest/start/building#requirements) are installed, the following steps should be followed: + +1. Download and extract source code of a release tarball from the Releases page. For example: https://github.com/envoyproxy/envoy/releases/tag/v1.24.0. +1. `python3 tools/github/tools/github/write_current_source_version.py` from the repository root. +1. `bazel build -c opt envoy` from the repository root. + +> Note: If the the `write_current_source_version.py` script is missing from the extracted source code directory, you can download it from [here](https://raw.githubusercontent.com/envoyproxy/envoy/tree/main/tools/github/write_current_source_version.py). +> This script is used to generate SOURCE_VERSION that is required by [`bazel/get_workspace_status`](./get_workspace_status) to "stamp" the binary in a non-git directory. + ## Quick start Bazel build for developers This section describes how to and what dependencies to install to get started building Envoy with Bazel. diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index e92ffb5df4a8..2be77af49483 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -8,42 +8,42 @@ # Note: This script can only be executed from project root directory of an extracted "release" # tarball. -import sys import json +import pathlib +import sys +import urllib.request -from urllib import request -from pathlib import Path - -# Simple check if a .git directory exists. When we are in a Git repo, we should rely on git. -if Path(".git").exists(): - print( - "Failed to create SOURCE_VERSION. " - "Run this script from an extracted release tarball directory.") - sys.exit(1) +if __name__ == '__main__': + # Simple check if a .git directory exists. When we are in a Git repo, we should rely on git. + if pathlib.Path(".git").exists(): + print( + "Failed to create SOURCE_VERSION. " + "Run this script from an extracted release tarball directory.") + sys.exit(1) -# Check if we have VERSION.txt available -current_version_file = Path("VERSION.txt") -if not current_version_file.exists(): - print( - "Failed to read VERSION.txt. " - "Run this script from project root of an extracted release tarball directory.") - sys.exit(1) + # Check if we have VERSION.txt available + current_version_file = pathlib.Path("VERSION.txt") + if not current_version_file.exists(): + print( + "Failed to read VERSION.txt. " + "Run this script from project root of an extracted release tarball directory.") + sys.exit(1) -current_version = current_version_file.read_text().rstrip() + current_version = current_version_file.read_text().rstrip() -# Exit when we are in a "main" copy. -if current_version.endswith("-dev"): - print( - "Failed to create SOURCE_VERSION. " - "The current VERSION.txt contains version with '-dev' suffix. " - "Run this script from an extracted release tarball directory.") - sys.exit(1) + # Exit when we are in a "main" copy. + if current_version.endswith("-dev"): + print( + "Failed to create SOURCE_VERSION. " + "The current VERSION.txt contains version with '-dev' suffix. " + "Run this script from an extracted release tarball directory.") + sys.exit(1) -# Fetch the current version commit information from GitHub. -with request.urlopen("https://api.github.com/repos/envoyproxy/envoy/commits/v" - + current_version) as response: - commit_info = json.loads(response.read()) - source_version_file = Path("SOURCE_VERSION") - with source_version_file.open("w", encoding="utf-8") as source_version: - # Write the extracted current version commit hash "sha" to SOURCE_VERSION. - source_version.write(commit_info["sha"]) + # Fetch the current version commit information from GitHub. + with urllib.request.urlopen("https://api.github.com/repos/envoyproxy/envoy/commits/v" + + current_version) as response: + commit_info = json.loads(response.read()) + source_version_file = pathlib.Path("SOURCE_VERSION") + with source_version_file.open("w", encoding="utf-8") as source_version: + # Write the extracted current version commit hash "sha" to SOURCE_VERSION. + source_version.write(commit_info["sha"]) From 0516792bea7a75a6dc68e28eb35ee730c4687153 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 12:49:02 +0000 Subject: [PATCH 8/9] Fix format Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index 2be77af49483..2aa659f73afd 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -41,7 +41,7 @@ # Fetch the current version commit information from GitHub. with urllib.request.urlopen("https://api.github.com/repos/envoyproxy/envoy/commits/v" - + current_version) as response: + + current_version) as response: commit_info = json.loads(response.read()) source_version_file = pathlib.Path("SOURCE_VERSION") with source_version_file.open("w", encoding="utf-8") as source_version: From 46e0420e7ba4d30cd17b89190286e98cda3dfde1 Mon Sep 17 00:00:00 2001 From: Dhi Aurrahman Date: Thu, 20 Oct 2022 21:54:14 +0000 Subject: [PATCH 9/9] Review comments Signed-off-by: Dhi Aurrahman --- tools/github/write_current_source_version.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/github/write_current_source_version.py b/tools/github/write_current_source_version.py index 2aa659f73afd..393348efe973 100644 --- a/tools/github/write_current_source_version.py +++ b/tools/github/write_current_source_version.py @@ -44,6 +44,5 @@ + current_version) as response: commit_info = json.loads(response.read()) source_version_file = pathlib.Path("SOURCE_VERSION") - with source_version_file.open("w", encoding="utf-8") as source_version: - # Write the extracted current version commit hash "sha" to SOURCE_VERSION. - source_version.write(commit_info["sha"]) + # Write the extracted current version commit hash "sha" to SOURCE_VERSION. + source_version_file.write_text(commit_info["sha"])