-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
142 lines (114 loc) · 4.92 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
set dotenv-load
# Display help information.
help:
@ just --list
# Open project workspace in VS Code.
code:
@ code .
# Install tooling for working with The Stack.
[linux]
install-tooling:
# Install QEMU packages.
sudo apt-get update
sudo apt-get install -y qemu-user-static binfmt-support
sudo update-binfmts --enable qemu-arm
sudo update-binfmts --display qemu-arm
# This step will execute the registering scripts.
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# Testing the emulation environment.
docker run --rm -t arm64v8/ubuntu uname -m
@ just _install-tooling-all-platforms
# Install tooling for working with The Stack.
[macos]
install-tooling:
@ just _install-tooling-all-platforms
_install-tooling-all-platforms:
# Install bun.
command -v bun >/dev/null 2>&1 || curl -fsSL https://bun.sh/install | bash
# Install the zig compiler for cross-compilation.
command -v zig >/dev/null 2>&1 || bun install --global zig
# Install cargo-binstall for installing binaries from crates.io.
command -v cargo-binstall >/dev/null 2>&1 || curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
# Install the rover CLI tool to manage Apollo supergraphs.
command -v rover >/dev/null 2>&1 || curl -sSL https://rover.apollo.dev/nix/latest | sh
# Install cargo-watch for watching Rust files.
cargo binstall --no-confirm cargo-watch
# Install cargo-edit for managing dependencies.
cargo binstall --no-confirm cargo-edit
# Install cargo-lambda for building Rust Lambda functions.
cargo binstall --no-confirm cargo-lambda
# Set up all projects.
setup-all:
@ just setup lambda-directly
@ just setup lambda-directly-optimized
@ just setup lambda-with-server
# Setup dependencies and tooling for <project>, e.g. `just setup lambda-directly`.
setup project:
just _setup-{{project}}
_setup-lambda-directly: (_setup-rust "lambda-directly")
_setup-lambda-directly-optimized: (_setup-rust "lambda-directly-optimized")
_setup-lambda-with-server: (_setup-rust "lambda-with-server")
_setup-rust project:
#!/usr/bin/env bash
set -euxo pipefail
cd {{project}}
rustup toolchain install stable
rustup default stable
# Run <project> development server, e.g. `just dev ui-app`.
dev project:
just _dev-{{project}}
# Alternative: cargo watch -x run
_dev-lambda-directly:
cd lambda-directly && cargo lambda watch --invoke-port 4010
_dev-lambda-directly-optimized:
cd lambda-directly-optimized && cargo lambda watch --invoke-port 4020
_dev-lambda-with-server:
cd lambda-directly && cargo lambda watch --invoke-port 4030
_dev-lambda-cosmo:
cd lambda-cosmo && cargo lambda watch --invoke-port 4040
# Invoke the local lambda function for <project>, e.g. `just invoke lambda-directly`.
invoke project:
just _invoke-{{project}}
_invoke-lambda-directly:
cargo lambda invoke --invoke-port 4010 --data-ascii '{ "body": "{\"query\":\"{me { name } }\"}" }'
_invoke-lambda-directly-optimized:
cargo lambda invoke --invoke-port 4020 --data-ascii '{ "body": "{\"query\":\"{me { name } }\"}" }'
_invoke-lambda-with-server:
cargo lambda invoke --invoke-port 4030 --data-ascii '{ "body": "{\"query\":\"{me { name } }\"}" }'
_invoke-lambda-cosmo:
cargo lambda invoke --invoke-port 4040 --data-ascii '{ "body": "{\"query\":\"{me { name } }\"}" }'
# Build the bootstrap file in docker for <project>, e.g. `just build lambda-directly-optimized-arm`.
build project:
@ just _build-{{project}}
_build-lambda-directly:
_build_generic "lambda-directly"
_build-lambda-with-server:
_build_generic "lambda-with-server"
_build-lambda-cosmo:
cd lambda-cosmo && cargo lambda build --arm64 --release
_build_generic project:
#!/usr/bin/env bash
set -euxo pipefail
cd {{project}}
docker build -t {{project}}:lambda .
export TMP_IMAGE_ID=$(docker create {{project}}:lambda)
docker cp $TMP_IMAGE_ID:/dist/apollo-router-lambda/target/lambda/apollo-router-lambda/bootstrap bootstrap
docker rm -v $TMP_IMAGE_ID
_build-lambda-directly-optimized-arm:
#!/usr/bin/env bash
set -euxo pipefail
cd lambda-directly-optimized
mkdir -p arm
docker buildx build -f Dockerfile-arm --platform linux/arm64 -t lambda-directly-optimized:lambda-arm .
export TMP_IMAGE_ID=$(docker create --platform linux/arm64 lambda-directly-optimized:lambda-arm)
docker cp $TMP_IMAGE_ID:/dist/apollo-router-lambda/target/lambda/apollo-router-lambda/bootstrap arm/bootstrap
docker rm -v $TMP_IMAGE_ID
_build-lambda-directly-optimized-x86:
#!/usr/bin/env bash
set -euxo pipefail
cd lambda-directly-optimized
mkdir -p x86
docker buildx build -f Dockerfile-x86 --platform linux/amd64 -t lambda-directly-optimized:lambda-x86 .
export TMP_IMAGE_ID=$(docker create --platform linux/amd64 lambda-directly-optimized:lambda-x86)
docker cp $TMP_IMAGE_ID:/dist/apollo-router-lambda/target/lambda/apollo-router-lambda/bootstrap x86/bootstrap
docker rm -v $TMP_IMAGE_ID