Setting the file. One moment.
Toolchain · Graphos Factory · apollographql/skills · Skills Docs
ContentsBack to the top of the page 10.20
Release
graphos-factory-core/scripts/ toolchain.sh
Shell · 147 lines · 7 KB
14
# variable unset as a note (exit 0: the tools are installed).
15 #
16 # One source of truth for the pins and their install paths; the SessionStart
17 # hook and CI both call this instead of carrying their own copy:
18 # rover $ROVER_VERSION + supergraph-v$FEDERATION_VERSION -> $HOME/.rover/bin (compose.sh, unit.sh, e2e.sh, live.sh)
19 # router-$ROUTER_VERSION -> $GRAPHOS_FACTORY_CORE_CACHE (e2e.sh, live.sh)
20 # wiremock-standalone-$WIREMOCK_VERSION.jar -> $GRAPHOS_FACTORY_CORE_CACHE (e2e.sh)
21 # FEDERATION_VERSION must match pilots/*/*/.factory/workspace.yaml; ROUTER_VERSION
22 # and WIREMOCK_VERSION must match the defaults in e2e.sh and live.sh.
23 #
24 # Java is not installed here: e2e.sh and live.sh need it, but every host this
25 # runs on (the web container, CI's setup-java) already provides it. The
26 # product binary is bootstrap.sh's job. $GRAPHOS_FACTORY_CORE_CACHE defaults as cache.sh
27 # says.
28 #
29 # Idempotent: every step is skipped when its version is already in place.
30 # Exit codes: 0 installed · 1 a download failed · 127 no router build for this platform.
31 set -euo pipefail
32
33 ROVER_VERSION = "${ ROVER_VERSION :- 0 . 41 . 0 }"
34 FEDERATION_VERSION = "${ FEDERATION_VERSION :- 2 . 15 . 2 }"
35 ROUTER_VERSION = "${ ROUTER_VERSION :- 2 . 17 . 0 }"
36 WIREMOCK_VERSION = "${ WIREMOCK_VERSION :- 3 . 13 . 2 }"
37 # shellcheck source=SCRIPTDIR/cache.sh
38 . "$( dirname " $0 ")/cache.sh"
39 CACHE = " $GRAPHOS_FACTORY_CORE_CACHE_DIR "
40 ROVER_BIN = " $HOME /.rover/bin"
41 ROUTER = " $CACHE /router- $ROUTER_VERSION "
42 WIREMOCK_JAR = " $CACHE /wiremock-standalone- $WIREMOCK_VERSION .jar"
43 export PATH = " $ROVER_BIN : $PATH "
44 # shellcheck source=SCRIPTDIR/elv2.sh
45 . "$( dirname " $0 ")/elv2.sh"
46
47 MODE = "install"
48 for arg in " $@ " ; do
49 case " $arg " in
50 --check ) MODE = "check" ;;
51 -h | --help ) sed -n '2,30p' " $0 " | sed 's/^# \{0,1\}//' ; exit 0 ;;
52 *) echo "toolchain: unknown argument $arg " >&2 ; exit 1 ;;
53 esac
54 done
55
56 have_rover () { [ "$( " $ROVER_BIN /rover" --version 2> /dev/null || true )" = "Rover $ROVER_VERSION " ]; }
57 have_plugin () { [ -x " $ROVER_BIN /supergraph-v $FEDERATION_VERSION " ]; }
58 have_router () { [ -x " $ROUTER " ]; }
59 have_wiremock () { [ -f " $WIREMOCK_JAR " ]; }
60
61 router_platform () {
62 case "$( uname -s )-$( uname -m )" in
63 Linux-x86_64 ) echo "x86_64-unknown-linux-gnu" ;;
64 Linux-aarch64 ) echo "aarch64-unknown-linux-gnu" ;;
65 Darwin-x86_64 ) echo "x86_64-apple-darwin" ;;
66 Darwin-arm64 ) echo "aarch64-apple-darwin" ;;
67 *) echo "" ;;
68 esac
69 }
70
71 if [ " $MODE " = "check" ]; then
72 missing = 0
73 have_rover || { echo "toolchain: rover $ROVER_VERSION is not at $ROVER_BIN " >&2 ; missing = 1 ; }
74 # The two ELv2-licensed pieces: a missing one fails, and the instruction
75 # is printed once when the user has not accepted.
76 elv2_missing = 0
77 have_plugin || { echo "toolchain: supergraph plugin v $FEDERATION_VERSION is not at $ROVER_BIN " >&2 ; missing = 1 ; elv2_missing = 1 ; }
78 have_router || { echo "toolchain: Apollo Router $ROUTER_VERSION is not at $ROUTER " >&2 ; missing = 1 ; elv2_missing = 1 ; }
79 have_wiremock || { echo "toolchain: WireMock $WIREMOCK_VERSION is not at $WIREMOCK_JAR " >&2 ; missing = 1 ; }
80 if ! elv2_accepted ; then
81 [ " $elv2_missing " -eq 1 ] \
82 || echo "toolchain: note — the supergraph plugin and the Apollo Router are installed, but APOLLO_ELV2_LICENSE is not set to accept" >&2
83 elv2_explain toolchain
84 fi
85 [ " $missing " -eq 0 ] && echo "toolchain: rover $ROVER_VERSION , supergraph v $FEDERATION_VERSION , router $ROUTER_VERSION , wiremock $WIREMOCK_VERSION present"
86 exit " $missing "
87 fi
88
89 # ── rover + composition plugin ───────────────────────────────────────────────
90 if have_rover ; then
91 echo "rover $ROVER_VERSION already installed"
92 else
93 echo "installing rover $ROVER_VERSION "
94 curl -fsSL "https://rover.apollo.dev/nix/v${ ROVER_VERSION }" | sh -s -- --force
95 fi
96
97 # What the user's missing ELv2 acceptance held back, explained once at the end.
98 held = ""
99 plugin = "supergraph v $FEDERATION_VERSION "
100 if have_plugin ; then
101 echo "supergraph plugin v $FEDERATION_VERSION already installed"
102 elif elv2_accepted ; then
103 # rover reads the user's own APOLLO_ELV2_LICENSE=accept; no flag here.
104 echo "installing supergraph plugin v $FEDERATION_VERSION "
105 " $ROVER_BIN /rover" install --plugin "supergraph@= $FEDERATION_VERSION "
106 else
107 held = "supergraph plugin v $FEDERATION_VERSION "
108 plugin = "no supergraph plugin"
109 fi
110
111 # ── router + WireMock for the e2e and live layers ────────────────────────────
112 mkdir -p " $CACHE "
113 router = "router $ROUTER_VERSION "
114 if have_router ; then
115 echo "router $ROUTER_VERSION already cached"
116 elif ! elv2_accepted ; then
117 held = "${ held : + $held and the }Apollo Router $ROUTER_VERSION "
118 router = "no router"
119 else
120 platform = "$( router_platform )"
121 if [ -z " $platform " ]; then
122 echo "toolchain: no Apollo Router build for $( uname -s )-$( uname -m ); e2e.sh and live.sh will report it as skipped" >&2
123 exit 127
124 fi
125 echo "caching Apollo Router $ROUTER_VERSION ( $platform )"
126 tmp = "$( mktemp -d )"
127 trap 'rm -rf "$tmp"' EXIT
128 curl -fsSL "https://github.com/apollographql/router/releases/download/v${ ROUTER_VERSION }/router-v${ ROUTER_VERSION }-${ platform }.tar.gz" \
129 | tar xzf - -C " $tmp " --strip-components=1 dist/router
130 mv " $tmp /router" " $ROUTER " && chmod +x " $ROUTER "
131 fi
132
133 if have_wiremock ; then
134 echo "WireMock $WIREMOCK_VERSION already cached"
135 else
136 echo "caching WireMock $WIREMOCK_VERSION "
137 curl -fsSL "https://repo1.maven.org/maven2/org/wiremock/wiremock-standalone/${ WIREMOCK_VERSION }/wiremock-standalone-${ WIREMOCK_VERSION }.jar" \
138 -o " $WIREMOCK_JAR "
139 fi
140
141 note = ""
142 if [ -n " $held " ]; then
143 echo "toolchain: not downloading the $held " >&2
144 elv2_explain toolchain
145 note = " (APOLLO_ELV2_LICENSE not set to accept)"
146 fi
147 echo "toolchain: rover $ROVER_VERSION , $plugin , $router , wiremock $WIREMOCK_VERSION ready $note "