-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build ddev flat package for macOS (#15851)
- Loading branch information
Showing
10 changed files
with
338 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# ddev release assets | ||
|
||
----- | ||
|
||
This directory stores files related to building binaries and installers for each platform. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# (C) Datadog, Inc. 2023-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
""" | ||
This script must be run from within the `ddev` directory. | ||
At a high level, the goal is to have a directory that emulates the full path structure of the | ||
target machine which then gets packaged by tools that are only available on macOS. | ||
""" | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import shutil | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
|
||
REPO_DIR = Path.cwd().parent | ||
ASSETS_DIR = Path(__file__).parent / 'pkg' | ||
IDENTIFIER = 'com.datadoghq.ddev' | ||
COMPONENT_PACKAGE_NAME = f'{IDENTIFIER}.pkg' | ||
README = """\ | ||
<!DOCTYPE html> | ||
<html> | ||
<head></head> | ||
<body> | ||
<p>This will install ddev v{version} globally.</p> | ||
<p>For more information on installing and upgrading ddev, see our <a href="https://datadoghq.dev/integrations-core/setup/#ddev">Installation Guide</a>.</p> | ||
</body> | ||
</html> | ||
""" # noqa: E501 | ||
|
||
|
||
def run_command(command: list[str]) -> None: | ||
process = subprocess.run(command) | ||
if process.returncode: | ||
sys.exit(process.returncode) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('directory') | ||
parser.add_argument('--binary', required=True) | ||
parser.add_argument('--version', required=True) | ||
args = parser.parse_args() | ||
|
||
directory = Path(args.directory).absolute() | ||
staged_binary = Path(args.binary).absolute() | ||
binary_name = staged_binary.stem | ||
version = args.version | ||
|
||
with TemporaryDirectory() as d: | ||
temp_dir = Path(d) | ||
|
||
# This is where we assemble files required for builds | ||
resources_dir = temp_dir / 'resources' | ||
shutil.copytree(str(ASSETS_DIR / 'resources'), str(resources_dir)) | ||
|
||
resources_dir.joinpath('README.html').write_text(README.format(version=version), encoding='utf-8') | ||
shutil.copy2(REPO_DIR / 'LICENSE', resources_dir) | ||
|
||
# This is what gets shipped to users starting at / (the root directory) | ||
root_dir = temp_dir / 'root' | ||
root_dir.mkdir() | ||
|
||
# This is where we globally install ddev. We choose to not offer per-user installs because we can't | ||
# find out where the location is and therefore cannot add to PATH usually. For more information, see: | ||
# https://github.com/aws/aws-cli/commit/f3c3eb8262786142a1712b6da5a1515ad9dc66c5 | ||
relative_binary_dir = Path('usr', 'local', binary_name, 'bin') | ||
binary_dir = root_dir / relative_binary_dir | ||
binary_dir.mkdir(parents=True) | ||
shutil.copy2(staged_binary, binary_dir) | ||
|
||
# This is how we add the installation directory to PATH and is also what Go does, | ||
# although there are some caveats: https://apple.stackexchange.com/q/126725 | ||
path_file = root_dir / 'etc' / 'paths.d' / binary_name | ||
path_file.parent.mkdir(parents=True) | ||
path_file.write_text(f'/{relative_binary_dir}\n', encoding='utf-8') | ||
|
||
# This is where we build the intermediate components | ||
components_dir = temp_dir / 'components' | ||
components_dir.mkdir() | ||
|
||
run_command( | ||
[ | ||
'pkgbuild', | ||
'--root', | ||
str(root_dir), | ||
'--identifier', | ||
IDENTIFIER, | ||
'--version', | ||
version, | ||
'--install-location', | ||
'/', | ||
str(components_dir / COMPONENT_PACKAGE_NAME), | ||
] | ||
) | ||
|
||
# This is where we build the final artifact | ||
build_dir = temp_dir / 'build' | ||
build_dir.mkdir() | ||
product_archive = build_dir / f'{binary_name}-{version}.pkg' | ||
|
||
run_command( | ||
[ | ||
'productbuild', | ||
'--distribution', | ||
str(ASSETS_DIR / 'distribution.xml'), | ||
'--resources', | ||
str(resources_dir), | ||
'--package-path', | ||
str(components_dir), | ||
str(product_archive), | ||
] | ||
) | ||
|
||
# Copy the final artifact to the target directory | ||
directory.mkdir(parents=True, exist_ok=True) | ||
shutil.copy2(product_archive, directory) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
(C) Datadog, Inc. 2023-present | ||
All rights reserved | ||
Licensed under a 3-clause BSD style license (see LICENSE) | ||
--> | ||
|
||
<installer-gui-script minSpecVersion="1"> | ||
<!-- | ||
https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html | ||
--> | ||
<title>Datadog Agent integration developer tool</title> | ||
<license file="LICENSE" mime-type="text/plain"/> | ||
<readme file="README.html" mime-type="text/html"/> | ||
<background mime-type="image/png" file="icon.png" alignment="left" scaling="proportional"/> | ||
<background-darkAqua mime-type="image/png" file="icon.png" alignment="left" scaling="proportional"/> | ||
<options hostArchitectures="arm64,x86_64" customize="never" require-scripts="false"/> | ||
<domains enable_localSystem="true"/> | ||
|
||
<choices-outline> | ||
<line choice="com.datadoghq.ddev.choice"/> | ||
</choices-outline> | ||
<choice title="ddev (universal)" id="com.datadoghq.ddev.choice"> | ||
<pkg-ref id="com.datadoghq.ddev.pkg"/> | ||
</choice> | ||
|
||
<pkg-ref id="com.datadoghq.ddev.pkg">com.datadoghq.ddev.pkg</pkg-ref> | ||
</installer-gui-script> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import subprocess | ||
from functools import cache | ||
from pathlib import Path | ||
|
||
MARKER = '<docs-insert-ddev-version>' | ||
SEMVER_PARTS = 3 | ||
|
||
# Ignore the current documentation environment so that the version | ||
# command can execute as usual in the default build environment | ||
os.environ.pop('HATCH_ENV_ACTIVE', None) | ||
|
||
|
||
@cache | ||
def get_latest_version(): | ||
"""This returns the latest version of ddev.""" | ||
ddev_root = Path.cwd() / 'ddev' | ||
output = subprocess.check_output(['hatch', 'version'], cwd=str(ddev_root)).decode('utf-8').strip() | ||
|
||
version = output.replace('dev', '') | ||
parts = list(map(int, version.split('.'))) | ||
major, minor, patch = parts[:SEMVER_PARTS] | ||
if len(parts) > SEMVER_PARTS: | ||
patch -= 1 | ||
|
||
return f'{major}.{minor}.{patch}' | ||
|
||
|
||
def on_page_read_source(page, config): | ||
"""This inserts the latest version of ddev.""" | ||
with open(page.file.abs_src_path, encoding='utf-8') as f: | ||
return f.read().replace(MARKER, get_latest_version()) |
Oops, something went wrong.