diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 259f95e806..36c4744640 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -66,6 +66,16 @@ These items have been removed from the public API of `apollo_router::services::e By [@SimonSapin](https://github.com/SimonSapin) in https://github.com/apollographql/router/pull/1568 +### Insert the full target triplet in the package name, and prefix with `v` ([Issue #1385](https://github.com/apollographql/router/issues/1385)) + +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): + +* `router-0.16.0-x86_64-linux.tar.gz` -> `router-v0.16.0-x86_64-unknown-linux-gnu.tar.gz` +* `router-0.16.0-x86_64-macos.tar.gz` -> `router-v0.16.0-x86_64-apple-darwin.tar.gz` +* `router-0.16.0-x86_64-windows.tar.gz` -> `router-v0.16.0-x86_64-pc-windows-msvc.tar.gz` + +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) + ### Many structs and enums are now `#[non_exhaustive]` ([Issue #1550](https://github.com/apollographql/router/issues/1550)) This means we may add struct fields or enum variants in the future. diff --git a/RELEASE_CHECKLIST.md b/RELEASE_CHECKLIST.md index 9bdaa80daf..58f7f54b8c 100644 --- a/RELEASE_CHECKLIST.md +++ b/RELEASE_CHECKLIST.md @@ -33,23 +33,24 @@ in lieu of an official changelog. (release) or "#.#.#-rc.#" (release candidate) 3. Update the `version` in `*/Cargo.toml` (do not forget the ones in scaffold templates). - Be certain to also update the ones in the `scaffold` templates -4. Update `docker.mdx` and `kubernetes.mdx` with the release version. -5. Update `helm/chart/router/Chart.yaml` and in `helm/chart/router/README.md` as follows: +4. Update the `PACKAGE_VERSION` value in `scripts/install.sh` (it should be prefixed with `v`!) +5. Update `docker.mdx` and `kubernetes.mdx` with the release version. +6. Update `helm/chart/router/Chart.yaml` and in `helm/chart/router/README.md` as follows: - increment the version. e.g. `version: 0.1.2` becomes `version: 0.1.3` - update the appVersion to the release version. e.g.: `appVersion: "v0.9.0"` -6. cd helm/chart && helm-docs router; cd - (if required, install [helm-docs](https://github.com/norwoodj/helm-docs)) -7. Update `federation-version-support.mdx` with the latest version info. Use https://github.com/apollographql/version_matrix to generate the version matrix. -8. Update the `version` in `docker-compose*` files in the `dockerfiles` directory. -9. Update the license list with `cargo about generate --workspace -o licenses.html about.hbs`. +7. cd helm/chart && helm-docs router; cd - (if required, install [helm-docs](https://github.com/norwoodj/helm-docs)) +8. Update `federation-version-support.mdx` with the latest version info. Use https://github.com/apollographql/version_matrix to generate the version matrix. +9. Update the `version` in `docker-compose*` files in the `dockerfiles` directory. +10. Update the license list with `cargo about generate --workspace -o licenses.html about.hbs`. You can install `cargo-about` by running `cargo install cargo-about`. -10. Add a new section in `CHANGELOG.md` with the contents of `NEXT_CHANGELOG.md` -11. Put a Release date and the version number on the new `CHANGELOG.md` section -12. Update the version in `NEXT_CHANGELOG.md`. -13. Clear `NEXT_CHANGELOG.md` leaving only the template. -14. Run `cargo check` so the lock file gets updated. -15. Run `cargo xtask check-compliance`. -16. Push up a commit with all the changes. The commit message should be "release: v#.#.#" or "release: v#.#.#-rc.#" -17. Request review from the Router team. +11. Add a new section in `CHANGELOG.md` with the contents of `NEXT_CHANGELOG.md` +12. Put a Release date and the version number on the new `CHANGELOG.md` section +13. Update the version in `NEXT_CHANGELOG.md`. +14. Clear `NEXT_CHANGELOG.md` leaving only the template. +15. Run `cargo check` so the lock file gets updated. +16. Run `cargo xtask check-compliance`. +17. Push up a commit with all the changes. The commit message should be "release: v#.#.#" or "release: v#.#.#-rc.#" +18. Request review from the Router team. ### Review diff --git a/dockerfiles/Dockerfile.router b/dockerfiles/Dockerfile.router index cb58b3f086..dc82501d5f 100644 --- a/dockerfiles/Dockerfile.router +++ b/dockerfiles/Dockerfile.router @@ -5,7 +5,7 @@ FROM --platform=linux/amd64 alpine:latest AS build ARG ROUTER_RELEASE # Pull release from GH -ADD https://github.com/apollographql/router/releases/download/v${ROUTER_RELEASE}/router-${ROUTER_RELEASE}-x86_64-linux.tar.gz /tmp/router.tar.gz +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 WORKDIR /tmp diff --git a/scripts/install.sh b/scripts/install.sh index 28d6564afa..db3b9144e4 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -7,8 +7,15 @@ set -u +BINARY_DOWNLOAD_PREFIX="https://github.com/apollographql/router/releases/download" + +# Router version defined in apollo-router's Cargo.toml +# Note: Change this line manually during the release steps. +PACKAGE_VERSION="v0.16.0" + download_binary() { - need_cmd curl + downloader --check + need_cmd mktemp need_cmd chmod need_cmd mkdir need_cmd rm @@ -19,17 +26,18 @@ download_binary() { need_cmd awk need_cmd cut - ARG_VERSION=${1:-"latest"} - + # if $VERSION isn't provided or has 0 length, use version apollo-router's cargo.toml # ${VERSION:-} checks if version exists, and if doesn't uses the default + # which is after the :-, which in this case is empty. -z checks for empty str if [ -z "${VERSION:-}" ]; then # VERSION is either not set or empty - DOWNLOAD_VERSION=$ARG_VERSION + DOWNLOAD_VERSION=$PACKAGE_VERSION else # VERSION set and not empty DOWNLOAD_VERSION=$VERSION fi + get_architecture || return 1 _arch="$RETVAL" assert_nz "$_arch" "arch" @@ -41,44 +49,16 @@ download_binary() { ;; esac - ARG_ARCH=${2:-"$_arch"} - - ARG_OUT_FILE=${3:-"./router"} - - GITHUB_REPO="https://github.com/apollographql/router" - - # Validate token. - curl -o /dev/null -s $GITHUB_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; } - - #_tardir="router-$DOWNLOAD_VERSION-${_arch}" - #_url="$BINARY_DOWNLOAD_PREFIX/$DOWNLOAD_VERSION/${_tardir}.tar.gz" + _tardir="router-$DOWNLOAD_VERSION-${_arch}" + _url="$BINARY_DOWNLOAD_PREFIX/$DOWNLOAD_VERSION/${_tardir}.tar.gz" _dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t router)" _file="$_dir/input.tar.gz" _router="$_dir/router$_ext" - _release_download_url="$GITHUB_REPO/releases" - _router_version=$DOWNLOAD_VERSION - if [ "$DOWNLOAD_VERSION" = "latest" ]; then - _response=$(curl -Ls -o /dev/null -w '%{url_effective}' $GITHUB_REPO/releases/latest) - _router_version=$(echo "$_response" | cut -d'/' -f 8) - [ "$_router_version" ] || { echo "Error: Failed to get asset version for '$ARG_ARCH', response: $_response" | awk 'length($0)<100' >&2; exit 1; } - fi; - - say "Downloading release info for '$_release_download_url'" - - # Cut the 'v' prefix - _name="router-$(echo "$_router_version" | cut -c2-)-$ARG_ARCH.tar.gz" - - _url="$GITHUB_REPO/releases/download/$_router_version/$_name" - - say "Found $_name" 1>&2 + say "Downloading router from $_url ..." 1>&2 ensure mkdir -p "$_dir" - - # Download asset file. - say "Downloading router from $_url" - - curl -sSfL -H 'Accept: application/octet-stream' "$_url" -o "$_file" + downloader "$_url" "$_file" if [ $? != 0 ]; then say "Failed to download $_url" say "This may be a standard network error, but it may also indicate" @@ -87,20 +67,19 @@ download_binary() { say "https://github.com/apollographql/router/issues/new/choose" exit 1 fi + ensure tar xf "$_file" --strip-components 1 -C "$_dir" - say "Moving $_router to $ARG_OUT_FILE" - mv "$_router" "$ARG_OUT_FILE" + outfile="./router" - _version="$($ARG_OUT_FILE --version)" + say "Moving $_router to $outfile ..." + mv "$_router" "$outfile" + + _version="$($outfile --version)" _retval=$? - say "Moved router version: $_version to $ARG_OUT_FILE" say "" - say "You can now run the Apollo Router using '$ARG_OUT_FILE'" - - - chmod +x "$ARG_OUT_FILE" + say "You can now run the Apollo Router using '$outfile'" ignore rm -rf "$_dir" @@ -137,15 +116,15 @@ get_architecture() { case "$_ostype" in Linux) - _ostype=linux + _ostype=unknown-linux-gnu ;; Darwin) - _ostype=macos + _ostype=apple-darwin ;; MINGW* | MSYS* | CYGWIN*) - _ostype=windows + _ostype=pc-windows-msvc ;; *) @@ -169,7 +148,7 @@ get_architecture() { say() { green=$(tput setaf 2 2>/dev/null || echo '') reset=$(tput sgr0 2>/dev/null || echo '') - echo "$1" 1>&2 + echo "$1" } err() { @@ -213,5 +192,25 @@ ignore() { "$@" } +# This wraps curl or wget. Try curl first, if not installed, +# use wget instead. +downloader() { + if check_cmd curl + then _dld=curl + elif check_cmd wget + then _dld=wget + else _dld='curl or wget' # to be used in error message of need_cmd + fi + + if [ "$1" = --check ] + then need_cmd "$_dld" + elif [ "$_dld" = curl ] + then curl -sSfL "$1" -o "$2" + elif [ "$_dld" = wget ] + then wget "$1" -O "$2" + else err "Unknown downloader" # should not reach here + fi +} + download_binary "$@" || exit 1 diff --git a/xtask/src/commands/package/mod.rs b/xtask/src/commands/package/mod.rs index e5eb7ec94a..2523af7284 100644 --- a/xtask/src/commands/package/mod.rs +++ b/xtask/src/commands/package/mod.rs @@ -1,7 +1,9 @@ #[cfg(target_os = "macos")] mod macos; +use std::fmt; use std::path::Path; +use std::str::FromStr; use anyhow::ensure; use anyhow::Context; @@ -11,6 +13,16 @@ use structopt::StructOpt; use xtask::*; const INCLUDE: &[&str] = &["README.md", "LICENSE", "licenses.html"]; +pub(crate) const TARGET_X86_64_MUSL_LINUX: &str = "x86_64-unknown-linux-musl"; +pub(crate) const TARGET_X86_64_GNU_LINUX: &str = "x86_64-unknown-linux-gnu"; +pub(crate) const TARGET_X86_64_WINDOWS: &str = "x86_64-pc-windows-msvc"; +pub(crate) const TARGET_X86_64_MACOS: &str = "x86_64-apple-darwin"; +pub(crate) const POSSIBLE_TARGETS: [&str; 4] = [ + TARGET_X86_64_MUSL_LINUX, + TARGET_X86_64_GNU_LINUX, + TARGET_X86_64_WINDOWS, + TARGET_X86_64_MACOS, +]; #[derive(Debug, StructOpt)] pub struct Package { @@ -21,6 +33,9 @@ pub struct Package { #[cfg(target_os = "macos")] #[structopt(flatten)] macos: macos::PackageMacos, + + #[structopt(long, default_value, possible_values = &POSSIBLE_TARGETS)] + target: Target, } impl Package { @@ -42,13 +57,8 @@ impl Package { } self.output.to_owned() } else if self.output.is_dir() { - self.output.join(format!( - "router-{}-{}-{}.tar.gz", - *PKG_VERSION, - // NOTE: same as xtask - std::env::consts::ARCH, - std::env::consts::OS, - )) + self.output + .join(format!("router-v{}-{}.tar.gz", *PKG_VERSION, self.target)) } else { self.output.to_owned() }; @@ -82,3 +92,63 @@ impl Package { Ok(()) } } + +#[derive(Debug, PartialEq, Clone)] +pub(crate) enum Target { + MuslLinux, + GnuLinux, + Windows, + MacOS, + Other, +} + +impl Default for Target { + fn default() -> Self { + if cfg!(target_arch = "x86_64") { + if cfg!(target_os = "windows") { + Target::Windows + } else if cfg!(target_os = "linux") { + if cfg!(target_env = "gnu") { + Target::GnuLinux + } else if cfg!(target_env = "musl") { + Target::MuslLinux + } else { + Target::Other + } + } else if cfg!(target_os = "macos") { + Target::MacOS + } else { + Target::Other + } + } else { + Target::Other + } + } +} + +impl FromStr for Target { + type Err = anyhow::Error; + + fn from_str(input: &str) -> Result { + match input { + TARGET_X86_64_MUSL_LINUX => Ok(Self::MuslLinux), + TARGET_X86_64_GNU_LINUX => Ok(Self::GnuLinux), + TARGET_X86_64_WINDOWS => Ok(Self::Windows), + TARGET_X86_64_MACOS => Ok(Self::MacOS), + _ => Ok(Self::Other), + } + } +} + +impl fmt::Display for Target { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let msg = match &self { + Target::MuslLinux => TARGET_X86_64_MUSL_LINUX, + Target::GnuLinux => TARGET_X86_64_GNU_LINUX, + Target::Windows => TARGET_X86_64_WINDOWS, + Target::MacOS => TARGET_X86_64_MACOS, + Target::Other => "unknown-target", + }; + write!(f, "{}", msg) + } +}