Skip to content

Commit

Permalink
Add s3 actor storage (#6)
Browse files Browse the repository at this point in the history
* Add s3 actor storage

* fix issues with hmac key

* update bucket name env var
  • Loading branch information
viktormarinho authored Oct 3, 2024
1 parent 455132f commit 1e9fe2a
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write
contents: read
id-token: write

steps:
- uses: actions/checkout@v4
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:
- main

permissions:
contents: write # Necessary for accessing and modifying repository content
pull-requests: write # Necessary for interacting with pull requests
actions: write # Necessary for triggering other workflows
contents: write # Necessary for accessing and modifying repository content
pull-requests: write # Necessary for interacting with pull requests
actions: write # Necessary for triggering other workflows

jobs:
tag-discussion:
Expand All @@ -21,8 +21,8 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }} # Checkout the base branch (target repository)
repository: ${{ github.event.pull_request.base.repo.full_name }} # Checkout from the target repo
ref: ${{ github.event.pull_request.base.ref }} # Checkout the base branch (target repository)
repository: ${{ github.event.pull_request.base.repo.full_name }} # Checkout from the target repo

- name: Calculate new versions
id: calculate_versions
Expand Down Expand Up @@ -165,15 +165,15 @@ jobs:
git push origin ${{ steps.determine_version.outputs.new_version }}
- name: Trigger Release Workflow
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yaml/dispatches \
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yaml/dispatches \
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'
- name: Trigger Publish Workflow
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/publish.yaml/dispatches \
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/publish.yaml/dispatches \
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"tasks": {
"check": "deno fmt && deno lint --fix && deno check ./src/actors/mod.ts ./src/actors/hono/middleware.ts",
"test": "rm kv;deno test -A --unstable-kv .",
"test": "rm kv;deno test -A --unstable-kv --env .",
"release": "deno run -A jsr:@deco/scripts/release"
},
"lock": false,
Expand Down
23 changes: 19 additions & 4 deletions src/actors/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ActorState } from "./state.ts";
import { DenoKvActorStorage } from "./storage/denoKv.ts";
import { EVENT_STREAM_RESPONSE_HEADER } from "./stream.ts";
import { isUpgrade, makeWebSocket } from "./util/channels/channel.ts";
import { S3ActorStorage } from "./storage/s3.ts";
import type { ActorStorage } from "./storage.ts";

/**
* Represents an actor.
Expand Down Expand Up @@ -81,6 +83,22 @@ export class ActorRuntime {
) {
}

getActorStorage(actorId: string, actorName: string): ActorStorage {
const storage = Deno.env.get("DECO_ACTORS_STORAGE");

if (storage === "s3") {
return new S3ActorStorage({
actorId,
actorName,
});
}

return new DenoKvActorStorage({
actorId,
actorName,
});
}

/**
* Ensures that the actors are initialized for the given actor ID.
* @param actorId - The ID of the actor.
Expand All @@ -91,10 +109,7 @@ export class ActorRuntime {
}
this.actorsConstructors.forEach((Actor) => {
const initialization = Promise.withResolvers<void>();
const storage = new DenoKvActorStorage({
actorId,
actorName: Actor.name,
});
const storage = this.getActorStorage(actorId, Actor.name);
const state = new ActorState({
initialization,
storage,
Expand Down
Loading

0 comments on commit 1e9fe2a

Please sign in to comment.