Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle signing key and event key #48

Merged
merged 39 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
417e801
move Inngest into client module
darwin67 Oct 2, 2024
d6f0b30
set dev server url using INNGEST_DEVc
darwin67 Oct 2, 2024
1d3a9b7
add internal function to API_ORIGIN
darwin67 Oct 2, 2024
26ec18e
changing const name for dev api origin
darwin67 Oct 2, 2024
db45ef3
add builder for handlerc
darwin67 Oct 2, 2024
ca7b908
replace hardcoded urls with proper values
darwin67 Oct 2, 2024
563c67d
add headers
darwin67 Oct 2, 2024
f857105
replace header keys with constants
darwin67 Oct 2, 2024
02f7784
add header struct as hashmap wrapper
darwin67 Oct 2, 2024
10ae438
add skeleton for signature verification
darwin67 Oct 2, 2024
4dbab80
add tests samples
darwin67 Oct 5, 2024
15cf4c5
add regex
darwin67 Oct 5, 2024
65d121d
add signing key hashing
darwin67 Oct 5, 2024
79baf1b
implement signature checks
darwin67 Oct 5, 2024
c20eb42
format
darwin67 Oct 5, 2024
ab6d841
attempt docker image build
darwin67 Oct 8, 2024
d950d61
typo
darwin67 Oct 8, 2024
7044d4a
change to vars
darwin67 Oct 8, 2024
87b762c
add permissions
darwin67 Oct 8, 2024
e223337
fix image ref
darwin67 Oct 8, 2024
e8948c8
use proper reference
darwin67 Oct 8, 2024
765cf82
setup deploy
darwin67 Oct 8, 2024
861f804
change binary name
darwin67 Oct 8, 2024
649216c
add deployment step
darwin67 Oct 8, 2024
83203fc
consolidate
darwin67 Oct 8, 2024
81eaf79
change to ipv6 binding
darwin67 Oct 8, 2024
c00db27
change to parsed
darwin67 Oct 8, 2024
2f723bc
update args
darwin67 Oct 8, 2024
091534d
fix syntax error
darwin67 Oct 8, 2024
d22fbda
remove grace period
darwin67 Oct 8, 2024
00f07b5
change to single quotes
darwin67 Oct 8, 2024
a636abb
change separator to be used
darwin67 Oct 8, 2024
1f06d63
add signature to header on sync
darwin67 Oct 8, 2024
609e917
fmt
darwin67 Oct 8, 2024
2ba4033
test more error messages
darwin67 Oct 8, 2024
a7f1cac
debug
darwin67 Oct 8, 2024
b7e5f91
change validation of timestamp
darwin67 Oct 8, 2024
0ad750a
change to second based unix ts
darwin67 Oct 8, 2024
54bff0b
check body
darwin67 Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Deploy

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
build_and_deploy:
name: Build and Deploy
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GH_ACTION_ACCESS }}
aws-region: ${{ vars.AWS_REGION }}

- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/rust-sdk
tags: |
type=sha,prefix=

- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
provenance: false
file: inngest/examples/axum/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
platform: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Replace placeholders in kustomize
working-directory: deploy
run: |
# image name
sed -i "s/IMAGE_NAME/${{ steps.login-ecr.outputs.registry }}\/rust-sdk/g" kustomization.yaml

# image tag
sed -i "s/IMAGE_TAG/${{ env.DOCKER_METADATA_OUTPUT_VERSION }}/g" kustomization.yaml

# siging key
sed -i "s/REPLACE_SIGNING_KEY/${{ secrets.INNGEST_SIGNING_KEY }}/g" kustomization.yaml

# event key
sed -i "s/REPLACE_EVENT_KEY/${{ secrets.INNGEST_EVENT_KEY }}/g" kustomization.yaml

# TLS cert - use % as separator instead
sed -i 's%REPLACE_TLS_CERT_ARN%${{ secrets.TLS_CERT_ARN }}%g' service.yaml

- name: Deploy
uses: ianbelcher/eks-kubectl-action@master # ALERT: master...?
with:
cluster_name: ${{ secrets.EKS_CLUSTER_NAME }}
kubernetes_version: v1.28.4
eks_role_arn: ${{ secrets.EKS_ACCESS_ARN }}
args: apply -k ./deploy
53 changes: 53 additions & 0 deletions deploy/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: rust-sdk
spec:
replicas: 2
revisionHistoryLimit: 5
template:
spec:
topologySpreadConstraints:
- topologyKey: "topology.kubernetes.io/zone"
maxSkew: 1
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: rust-sdk
serviceAccountName: rust-sdk
containers:
- image: rust-sdk:TO_BE_REPLACED
imagePullPolicy: IfNotPresent
name: axum
ports:
- containerPort: 3000
resources:
limits:
memory: 100Mi
requests:
cpu: 0.5
envFrom:
- configMapRef:
name: common
livenessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 3
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 3
periodSeconds: 10
successThreshold: 3
failureThreshold: 3
lifecycle:
# required for LB to register and drain target
# ref: https://aws.github.io/aws-eks-best-practices/networking/loadbalancing/loadbalancing/#ensure-pods-are-deregistered-from-load-balancers-before-termination
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 180"]
29 changes: 29 additions & 0 deletions deploy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: rust-sdk

commonLabels:
app: rust-sdk
app.kubernetes.io/managed-by: kustomize

configMapGenerator:
- name: common
literals:
- INNGEST_SERVE_ORIGIN=https://rust-sdk.inngest.net
- INNGEST_EVENT_API_ORIGIN=https://stage.inn.gs
- INNGEST_API_ORIGIN=https://api.inngest.net

- INNGEST_SIGNING_KEY=REPLACE_SIGNING_KEY
- INNGEST_EVENT_KEY=REPLACE_EVENT_KEY

resources:
- namespace.yaml
- serviceaccount.yaml
- service.yaml
- deployment.yaml

images:
- name: rust-sdk
newName: "IMAGE_NAME"
newTag: "IMAGE_TAG"
7 changes: 7 additions & 0 deletions deploy/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: rust-sdk
labels:
# required to make sure pods are ready after LB has completed their health checks
elbv2.k8s.aws/pod-readiness-gate-inject: enabled
23 changes: 23 additions & 0 deletions deploy/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Service
metadata:
name: rust-sdk
annotations:
service.beta.kubernetes.io/aws-load-balancer-name: rust-sdk
service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
service.beta.kubernetes.io/aws-load-balancer-ip-address-type: dualstack
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
service.beta.kubernetes.io/aws-load-balancer-target-group-attributes: preserve_client_ip.enabled=true
service.beta.kubernetes.io/aws-load-balancer-ssl-negotiation-policy: ELBSecurityPolicy-TLS13-1-2-2021-06
service.beta.kubernetes.io/aws-load-balancer-attributes: load_balancing.cross_zone.enabled=true
service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags: env=staging,app=rust-sdk
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: REPLACE_TLS_CERT_ARN
# external DNS integration test
external-dns.alpha.kubernetes.io/hostname: rust-sdk.inngest.net
spec:
type: LoadBalancer
ports:
- name: tcp
port: 443
targetPort: 3000
protocol: TCP
6 changes: 6 additions & 0 deletions deploy/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: rust-sdk
labels:
service: rust-sdk
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

# LSP
rust-analyzer
nodePackages.yaml-language-server
];

RUST_SRC_PATH =
Expand Down
4 changes: 4 additions & 0 deletions inngest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ slug = "0.1.4"
typetag = "0.2.13"
inngest_macros = { path = "../macros" }
futures = "0.3.30"
regex = "1.11.0"

# used for step encoding in SDK
sha1 = "0.10.6"
base16 = "0.2.1"
url = "2.5.2"
sha2 = "0.10.8"
hmac = "0.12.1"
16 changes: 16 additions & 0 deletions inngest/examples/axum/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM rust:1.79-bookworm AS build

RUN apt-get update && apt-get install -y adduser ca-certificates tzdata curl dnsutils && update-ca-certificates

WORKDIR /app
COPY . .

RUN cargo build --example axum --release

FROM ubuntu:24.04 AS runner
RUN apt update && apt install -y adduser wget ca-certificates tzdata curl dnsutils && update-ca-certificates

COPY --from=build /app/target/release/examples/axum /bin/main

USER ubuntu
CMD ["main"]
14 changes: 8 additions & 6 deletions inngest/examples/axum/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use axum::{
routing::{get, put},
Json, Router,
Router,
};
use inngest::{
client::Inngest,
event::Event,
function::{create_function, FunctionOps, Input, ServableFn, Trigger},
handler::Handler,
into_dev_result,
result::{DevError, Error, InngestResult},
result::{DevError, Error},
serve,
step_tool::{InvokeFunctionOpts, Step as StepTool, WaitForEventOpts},
Inngest,
};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
Expand All @@ -29,15 +29,17 @@ async fn main() {
let inngest_state = Arc::new(inngest_handler);

let app = Router::new()
.route("/", get(|| async { "Hello, World!" }))
.route("/", get(|| async { "OK!\n" }))
.route(
"/api/inngest",
put(serve::axum::register).post(serve::axum::invoke),
)
.with_state(inngest_state);

let addr = "[::]:3000".parse::<std::net::SocketAddr>().unwrap();

// run it with hyper on localhost:3000
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
Expand Down Expand Up @@ -138,7 +140,7 @@ fn hello_fn() -> ServableFn<TestData, Error> {
let evt = &input.event;
println!("Event: {}", evt.name);

step.sleep_until("sleep", 1727245659000)?;
step.sleep("wait-5s", Duration::from_secs(5))?;

Ok(json!("test hello"))
},
Expand Down
2 changes: 1 addition & 1 deletion inngest/examples/send_events/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use inngest::{event::Event, Inngest};
use inngest::{client::Inngest, event::Event};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
Loading
Loading