Skip to content

Commit f48ccc7

Browse files
abernixGeoffroy Couprie
andauthored
Future-proof installer script and re-introduce target triplets (#1433)
Co-authored-by: Geoffroy Couprie <[email protected]>
1 parent cb345d3 commit f48ccc7

File tree

5 files changed

+150
-70
lines changed

5 files changed

+150
-70
lines changed

NEXT_CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ These items have been removed from the public API of `apollo_router::services::e
7878

7979
By [@SimonSapin](https://github.com/SimonSapin) in https://github.com/apollographql/router/pull/1568
8080

81+
### Insert the full target triplet in the package name, and prefix with `v` ([Issue #1385](https://github.com/apollographql/router/issues/1385))
82+
83+
The release tarballs now contain the full target triplet in their name along with a `v` prefix to be consistent with our other packaging techniques (e.g., Rover):
84+
85+
* `router-0.16.0-x86_64-linux.tar.gz` -> `router-v0.16.0-x86_64-unknown-linux-gnu.tar.gz`
86+
* `router-0.16.0-x86_64-macos.tar.gz` -> `router-v0.16.0-x86_64-apple-darwin.tar.gz`
87+
* `router-0.16.0-x86_64-windows.tar.gz` -> `router-v0.16.0-x86_64-pc-windows-msvc.tar.gz`
88+
89+
By [@abernix](https://github.com/abernix) and [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/1433 (which re-lands work done in https://github.com/apollographql/router/pull/1393)
90+
8191
### Many structs and enums are now `#[non_exhaustive]` ([Issue #1550](https://github.com/apollographql/router/issues/1550))
8292

8393
This means we may add struct fields or enum variants in the future.

RELEASE_CHECKLIST.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,24 @@ in lieu of an official changelog.
3333
(release) or "#.#.#-rc.#" (release candidate)
3434
3. Update the `version` in `*/Cargo.toml` (do not forget the ones in scaffold templates).
3535
- Be certain to also update the ones in the `scaffold` templates
36-
4. Update `docker.mdx` and `kubernetes.mdx` with the release version.
37-
5. Update `helm/chart/router/Chart.yaml` and in `helm/chart/router/README.md` as follows:
36+
4. Update the `PACKAGE_VERSION` value in `scripts/install.sh` (it should be prefixed with `v`!)
37+
5. Update `docker.mdx` and `kubernetes.mdx` with the release version.
38+
6. Update `helm/chart/router/Chart.yaml` and in `helm/chart/router/README.md` as follows:
3839
- increment the version. e.g. `version: 0.1.2` becomes `version: 0.1.3`
3940
- update the appVersion to the release version. e.g.: `appVersion: "v0.9.0"`
40-
6. cd helm/chart && helm-docs router; cd - (if required, install [helm-docs](https://github.com/norwoodj/helm-docs))
41-
7. Update `federation-version-support.mdx` with the latest version info. Use https://github.com/apollographql/version_matrix to generate the version matrix.
42-
8. Update the `version` in `docker-compose*` files in the `dockerfiles` directory.
43-
9. Update the license list with `cargo about generate --workspace -o licenses.html about.hbs`.
41+
7. cd helm/chart && helm-docs router; cd - (if required, install [helm-docs](https://github.com/norwoodj/helm-docs))
42+
8. Update `federation-version-support.mdx` with the latest version info. Use https://github.com/apollographql/version_matrix to generate the version matrix.
43+
9. Update the `version` in `docker-compose*` files in the `dockerfiles` directory.
44+
10. Update the license list with `cargo about generate --workspace -o licenses.html about.hbs`.
4445
You can install `cargo-about` by running `cargo install cargo-about`.
45-
10. Add a new section in `CHANGELOG.md` with the contents of `NEXT_CHANGELOG.md`
46-
11. Put a Release date and the version number on the new `CHANGELOG.md` section
47-
12. Update the version in `NEXT_CHANGELOG.md`.
48-
13. Clear `NEXT_CHANGELOG.md` leaving only the template.
49-
14. Run `cargo check` so the lock file gets updated.
50-
15. Run `cargo xtask check-compliance`.
51-
16. Push up a commit with all the changes. The commit message should be "release: v#.#.#" or "release: v#.#.#-rc.#"
52-
17. Request review from the Router team.
46+
11. Add a new section in `CHANGELOG.md` with the contents of `NEXT_CHANGELOG.md`
47+
12. Put a Release date and the version number on the new `CHANGELOG.md` section
48+
13. Update the version in `NEXT_CHANGELOG.md`.
49+
14. Clear `NEXT_CHANGELOG.md` leaving only the template.
50+
15. Run `cargo check` so the lock file gets updated.
51+
16. Run `cargo xtask check-compliance`.
52+
17. Push up a commit with all the changes. The commit message should be "release: v#.#.#" or "release: v#.#.#-rc.#"
53+
18. Request review from the Router team.
5354

5455
### Review
5556

dockerfiles/Dockerfile.router

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM --platform=linux/amd64 alpine:latest AS build
55
ARG ROUTER_RELEASE
66

77
# Pull release from GH
8-
ADD https://github.com/apollographql/router/releases/download/v${ROUTER_RELEASE}/router-${ROUTER_RELEASE}-x86_64-linux.tar.gz /tmp/router.tar.gz
8+
ADD https://github.com/apollographql/router/releases/download/v${ROUTER_RELEASE}/router-${ROUTER_RELEASE}-x86_64-unknown-linux-gnu.tar.gz /tmp/router.tar.gz
99

1010
WORKDIR /tmp
1111

scripts/install.sh

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77

88
set -u
99

10+
BINARY_DOWNLOAD_PREFIX="https://github.com/apollographql/router/releases/download"
11+
12+
# Router version defined in apollo-router's Cargo.toml
13+
# Note: Change this line manually during the release steps.
14+
PACKAGE_VERSION="v0.16.0"
15+
1016
download_binary() {
11-
need_cmd curl
17+
downloader --check
18+
need_cmd mktemp
1219
need_cmd chmod
1320
need_cmd mkdir
1421
need_cmd rm
@@ -19,17 +26,18 @@ download_binary() {
1926
need_cmd awk
2027
need_cmd cut
2128

22-
ARG_VERSION=${1:-"latest"}
23-
29+
# if $VERSION isn't provided or has 0 length, use version apollo-router's cargo.toml
2430
# ${VERSION:-} checks if version exists, and if doesn't uses the default
31+
# which is after the :-, which in this case is empty. -z checks for empty str
2532
if [ -z "${VERSION:-}" ]; then
2633
# VERSION is either not set or empty
27-
DOWNLOAD_VERSION=$ARG_VERSION
34+
DOWNLOAD_VERSION=$PACKAGE_VERSION
2835
else
2936
# VERSION set and not empty
3037
DOWNLOAD_VERSION=$VERSION
3138
fi
3239

40+
3341
get_architecture || return 1
3442
_arch="$RETVAL"
3543
assert_nz "$_arch" "arch"
@@ -41,44 +49,16 @@ download_binary() {
4149
;;
4250
esac
4351

44-
ARG_ARCH=${2:-"$_arch"}
45-
46-
ARG_OUT_FILE=${3:-"./router"}
47-
48-
GITHUB_REPO="https://github.com/apollographql/router"
49-
50-
# Validate token.
51-
curl -o /dev/null -s $GITHUB_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }
52-
53-
#_tardir="router-$DOWNLOAD_VERSION-${_arch}"
54-
#_url="$BINARY_DOWNLOAD_PREFIX/$DOWNLOAD_VERSION/${_tardir}.tar.gz"
52+
_tardir="router-$DOWNLOAD_VERSION-${_arch}"
53+
_url="$BINARY_DOWNLOAD_PREFIX/$DOWNLOAD_VERSION/${_tardir}.tar.gz"
5554
_dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t router)"
5655
_file="$_dir/input.tar.gz"
5756
_router="$_dir/router$_ext"
5857

59-
_release_download_url="$GITHUB_REPO/releases"
60-
_router_version=$DOWNLOAD_VERSION
61-
if [ "$DOWNLOAD_VERSION" = "latest" ]; then
62-
_response=$(curl -Ls -o /dev/null -w '%{url_effective}' $GITHUB_REPO/releases/latest)
63-
_router_version=$(echo "$_response" | cut -d'/' -f 8)
64-
[ "$_router_version" ] || { echo "Error: Failed to get asset version for '$ARG_ARCH', response: $_response" | awk 'length($0)<100' >&2; exit 1; }
65-
fi;
66-
67-
say "Downloading release info for '$_release_download_url'"
68-
69-
# Cut the 'v' prefix
70-
_name="router-$(echo "$_router_version" | cut -c2-)-$ARG_ARCH.tar.gz"
71-
72-
_url="$GITHUB_REPO/releases/download/$_router_version/$_name"
73-
74-
say "Found $_name" 1>&2
58+
say "Downloading router from $_url ..." 1>&2
7559

7660
ensure mkdir -p "$_dir"
77-
78-
# Download asset file.
79-
say "Downloading router from $_url"
80-
81-
curl -sSfL -H 'Accept: application/octet-stream' "$_url" -o "$_file"
61+
downloader "$_url" "$_file"
8262
if [ $? != 0 ]; then
8363
say "Failed to download $_url"
8464
say "This may be a standard network error, but it may also indicate"
@@ -87,20 +67,19 @@ download_binary() {
8767
say "https://github.com/apollographql/router/issues/new/choose"
8868
exit 1
8969
fi
70+
9071
ensure tar xf "$_file" --strip-components 1 -C "$_dir"
9172

92-
say "Moving $_router to $ARG_OUT_FILE"
93-
mv "$_router" "$ARG_OUT_FILE"
73+
outfile="./router"
9474

95-
_version="$($ARG_OUT_FILE --version)"
75+
say "Moving $_router to $outfile ..."
76+
mv "$_router" "$outfile"
77+
78+
_version="$($outfile --version)"
9679
_retval=$?
9780

98-
say "Moved router version: $_version to $ARG_OUT_FILE"
9981
say ""
100-
say "You can now run the Apollo Router using '$ARG_OUT_FILE'"
101-
102-
103-
chmod +x "$ARG_OUT_FILE"
82+
say "You can now run the Apollo Router using '$outfile'"
10483

10584
ignore rm -rf "$_dir"
10685

@@ -137,15 +116,15 @@ get_architecture() {
137116

138117
case "$_ostype" in
139118
Linux)
140-
_ostype=linux
119+
_ostype=unknown-linux-gnu
141120
;;
142121

143122
Darwin)
144-
_ostype=macos
123+
_ostype=apple-darwin
145124
;;
146125

147126
MINGW* | MSYS* | CYGWIN*)
148-
_ostype=windows
127+
_ostype=pc-windows-msvc
149128
;;
150129

151130
*)
@@ -169,7 +148,7 @@ get_architecture() {
169148
say() {
170149
green=$(tput setaf 2 2>/dev/null || echo '')
171150
reset=$(tput sgr0 2>/dev/null || echo '')
172-
echo "$1" 1>&2
151+
echo "$1"
173152
}
174153

175154
err() {
@@ -213,5 +192,25 @@ ignore() {
213192
"$@"
214193
}
215194

195+
# This wraps curl or wget. Try curl first, if not installed,
196+
# use wget instead.
197+
downloader() {
198+
if check_cmd curl
199+
then _dld=curl
200+
elif check_cmd wget
201+
then _dld=wget
202+
else _dld='curl or wget' # to be used in error message of need_cmd
203+
fi
204+
205+
if [ "$1" = --check ]
206+
then need_cmd "$_dld"
207+
elif [ "$_dld" = curl ]
208+
then curl -sSfL "$1" -o "$2"
209+
elif [ "$_dld" = wget ]
210+
then wget "$1" -O "$2"
211+
else err "Unknown downloader" # should not reach here
212+
fi
213+
}
214+
216215
download_binary "$@" || exit 1
217216

xtask/src/commands/package/mod.rs

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#[cfg(target_os = "macos")]
22
mod macos;
33

4+
use std::fmt;
45
use std::path::Path;
6+
use std::str::FromStr;
57

68
use anyhow::ensure;
79
use anyhow::Context;
@@ -11,6 +13,16 @@ use structopt::StructOpt;
1113
use xtask::*;
1214

1315
const INCLUDE: &[&str] = &["README.md", "LICENSE", "licenses.html"];
16+
pub(crate) const TARGET_X86_64_MUSL_LINUX: &str = "x86_64-unknown-linux-musl";
17+
pub(crate) const TARGET_X86_64_GNU_LINUX: &str = "x86_64-unknown-linux-gnu";
18+
pub(crate) const TARGET_X86_64_WINDOWS: &str = "x86_64-pc-windows-msvc";
19+
pub(crate) const TARGET_X86_64_MACOS: &str = "x86_64-apple-darwin";
20+
pub(crate) const POSSIBLE_TARGETS: [&str; 4] = [
21+
TARGET_X86_64_MUSL_LINUX,
22+
TARGET_X86_64_GNU_LINUX,
23+
TARGET_X86_64_WINDOWS,
24+
TARGET_X86_64_MACOS,
25+
];
1426

1527
#[derive(Debug, StructOpt)]
1628
pub struct Package {
@@ -21,6 +33,9 @@ pub struct Package {
2133
#[cfg(target_os = "macos")]
2234
#[structopt(flatten)]
2335
macos: macos::PackageMacos,
36+
37+
#[structopt(long, default_value, possible_values = &POSSIBLE_TARGETS)]
38+
target: Target,
2439
}
2540

2641
impl Package {
@@ -42,13 +57,8 @@ impl Package {
4257
}
4358
self.output.to_owned()
4459
} else if self.output.is_dir() {
45-
self.output.join(format!(
46-
"router-{}-{}-{}.tar.gz",
47-
*PKG_VERSION,
48-
// NOTE: same as xtask
49-
std::env::consts::ARCH,
50-
std::env::consts::OS,
51-
))
60+
self.output
61+
.join(format!("router-v{}-{}.tar.gz", *PKG_VERSION, self.target))
5262
} else {
5363
self.output.to_owned()
5464
};
@@ -82,3 +92,63 @@ impl Package {
8292
Ok(())
8393
}
8494
}
95+
96+
#[derive(Debug, PartialEq, Clone)]
97+
pub(crate) enum Target {
98+
MuslLinux,
99+
GnuLinux,
100+
Windows,
101+
MacOS,
102+
Other,
103+
}
104+
105+
impl Default for Target {
106+
fn default() -> Self {
107+
if cfg!(target_arch = "x86_64") {
108+
if cfg!(target_os = "windows") {
109+
Target::Windows
110+
} else if cfg!(target_os = "linux") {
111+
if cfg!(target_env = "gnu") {
112+
Target::GnuLinux
113+
} else if cfg!(target_env = "musl") {
114+
Target::MuslLinux
115+
} else {
116+
Target::Other
117+
}
118+
} else if cfg!(target_os = "macos") {
119+
Target::MacOS
120+
} else {
121+
Target::Other
122+
}
123+
} else {
124+
Target::Other
125+
}
126+
}
127+
}
128+
129+
impl FromStr for Target {
130+
type Err = anyhow::Error;
131+
132+
fn from_str(input: &str) -> Result<Self, Self::Err> {
133+
match input {
134+
TARGET_X86_64_MUSL_LINUX => Ok(Self::MuslLinux),
135+
TARGET_X86_64_GNU_LINUX => Ok(Self::GnuLinux),
136+
TARGET_X86_64_WINDOWS => Ok(Self::Windows),
137+
TARGET_X86_64_MACOS => Ok(Self::MacOS),
138+
_ => Ok(Self::Other),
139+
}
140+
}
141+
}
142+
143+
impl fmt::Display for Target {
144+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
145+
let msg = match &self {
146+
Target::MuslLinux => TARGET_X86_64_MUSL_LINUX,
147+
Target::GnuLinux => TARGET_X86_64_GNU_LINUX,
148+
Target::Windows => TARGET_X86_64_WINDOWS,
149+
Target::MacOS => TARGET_X86_64_MACOS,
150+
Target::Other => "unknown-target",
151+
};
152+
write!(f, "{}", msg)
153+
}
154+
}

0 commit comments

Comments
 (0)