Skip to content

Commit

Permalink
Typescript Support & KS Workflow (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushisource authored Dec 18, 2023
1 parent a3d5eef commit 403d0cc
Show file tree
Hide file tree
Showing 30 changed files with 14,980 additions and 16,136 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/all-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
java-version:
description: Java SDK version to build. Skipped if not specified. Must start with v.
type: string
ts-ver:
description: TypeScript SDK ver to build. Skipped if not specified. Must start with v.
type: string
do-push:
description: If set, push the built images to Docker Hub.
type: boolean
Expand All @@ -29,6 +32,9 @@ on:
java-version:
description: Java SDK version to build. Skipped if not specified. Must start with v.
type: string
ts-ver:
description: TypeScript SDK ver to build. Skipped if not specified. Must start with v.
type: string
do-push:
description: If set, push the built images to Docker Hub.
type: boolean
Expand Down Expand Up @@ -62,3 +68,12 @@ jobs:
lang: java
sdk-version: ${{ inputs.java-version }}
do-push: ${{ inputs.do-push }}

build-typescript-docker-images:
if: inputs.ts-ver
uses: ./.github/workflows/docker-images.yml
secrets: inherit
with:
lang: typescript
sdk-version: ${{ inputs.ts-ver }}
do-push: ${{ inputs.do-push }}
34 changes: 32 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
- name: Run local scenario with worker
run: ./temporal-omes run-scenario-with-worker --scenario workflow_with_single_noop_activity --log-level debug --language go --embedded-server --iterations 5
- name: Build worker image
run: ./temporal-omes build-worker-image --language go --version v1.24.0 --tag-as-latest
run: ./temporal-omes build-worker-image --language go --version v1.25.2-0.20231129171107-288a04f72145 --tag-as-latest
- name: Run worker image
run: docker run --rm --detach -i -p 10233:10233 omes:go-1.24.0 --scenario workflow_with_single_noop_activity --log-level debug --language go --run-id {{ github.run_id }} --embedded-server-address 0.0.0.0:10233
run: docker run --rm --detach -i -p 10233:10233 omes:go-1.25.2-0.20231129171107-288a04f72145 --scenario workflow_with_single_noop_activity --log-level debug --language go --run-id {{ github.run_id }} --embedded-server-address 0.0.0.0:10233
- name: Run scenario against image
run: ./temporal-omes run-scenario --scenario workflow_with_single_noop_activity --log-level debug --server-address 127.0.0.1:10233 --run-id {{ github.run_id }} --connect-timeout 1m --iterations 5

Expand Down Expand Up @@ -94,6 +94,36 @@ jobs:
- name: Run scenario against image
run: ./temporal-omes run-scenario --scenario workflow_with_single_noop_activity --log-level debug --server-address 127.0.0.1:10233 --run-id {{ github.run_id }} --connect-timeout 1m --iterations 5

build-lint-test-typescript:
runs-on: ubuntu-latest
steps:
- name: Print build information
run: "echo head_ref: ${{ github.head_ref }}, ref: ${{ github.ref }}"
- name: Checkout repo
uses: actions/checkout@v2
with:
submodules: 'true'
- name: Setup TypeScript
uses: actions/setup-node@v4
- name: Initialize TypeScript worker
run: cd workers/typescript && npm ci && npm run build
- name: Lint TypeScript worker
run: cd workers/typescript && npm run lint-ci
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "^1.20"
- name: Build exe
run: go build -o temporal-omes ./cmd
- name: Run local scenario with worker
run: ./temporal-omes run-scenario-with-worker --scenario workflow_with_single_noop_activity --log-level debug --language ts --embedded-server --iterations 5
- name: Build worker image
run: ./temporal-omes build-worker-image --language ts --version 1.9.0-rc.0 --tag-as-latest
- name: Run worker image
run: docker run --rm --detach -i -p 10233:10233 omes:typescript-1.9.0-rc.0 --scenario workflow_with_single_noop_activity --log-level debug --language ts --run-id {{ github.run_id }} --embedded-server-address 0.0.0.0:10233
- name: Run scenario against image
run: ./temporal-omes run-scenario --scenario workflow_with_single_noop_activity --log-level debug --server-address 127.0.0.1:10233 --run-id {{ github.run_id }} --connect-timeout 1m --iterations 5

build-ks-gen-and-ensure-protos-up-to-date:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ workflow that waits for a signal for a configurable amount of time.
## Fuzzer trophy case

* Python upsert SA with no initial attributes: [PR](https://github.com/temporalio/sdk-python/pull/440)
* Core cancel-before-start on abandon activities: [PR](https://github.com/temporalio/sdk-core/pull/652)
* Core cancel-before-start on abandon activities: [PR](https://github.com/temporalio/sdk-core/pull/652)
* Core panic on evicting run with buffered tasks: [PR](https://github.com/temporalio/sdk-core/pull/660)
42 changes: 40 additions & 2 deletions cmd/prepare_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (b *workerBuilder) build(ctx context.Context) (sdkbuild.Program, error) {
return b.buildPython(ctx, baseDir)
case "java":
return b.buildJava(ctx, baseDir)
case "typescript":
return b.buildTypeScript(ctx, baseDir)
default:
return nil, fmt.Errorf("unrecognized language %v", lang)
}
Expand Down Expand Up @@ -119,7 +121,7 @@ func (b *workerBuilder) buildPython(ctx context.Context, baseDir string) (sdkbui
if version == "" {
b, err := os.ReadFile(filepath.Join(baseDir, "pyproject.toml"))
if err != nil {
return nil, fmt.Errorf("failed reading package.json: %w", err)
return nil, fmt.Errorf("failed reading pyproject.toml: %w", err)
}
for _, line := range strings.Split(string(b), "\n") {
line = strings.TrimSpace(line)
Expand Down Expand Up @@ -161,16 +163,52 @@ func (b *workerBuilder) buildJava(ctx context.Context, baseDir string) (sdkbuild
return prog, nil
}

func (b *workerBuilder) buildTypeScript(ctx context.Context, baseDir string) (sdkbuild.Program, error) {
// If version not provided, try to read it from package.json
version := b.version
if version == "" {
b, err := os.ReadFile(filepath.Join(baseDir, "package.json"))
if err != nil {
return nil, fmt.Errorf("failed reading package.json: %w", err)
}
for _, line := range strings.Split(string(b), "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "\"temporalio\":") {
split := strings.Split(line, "\"")
version = split[len(split)-2]
break
}
}
if version == "" {
return nil, fmt.Errorf("version not found in package.json")
}
}
prog, err := sdkbuild.BuildTypeScriptProgram(ctx, sdkbuild.BuildTypeScriptProgramOptions{
BaseDir: baseDir,
Version: version,
TSConfigPaths: map[string][]string{"@temporalio/omes": {"src/omes.ts"}},
DirName: b.dirName,
ApplyToCommand: nil,
Includes: []string{"../src/**/*.ts", "../src/protos/json-module.js", "../src/protos/root.js"},
})
if err != nil {
return nil, fmt.Errorf("failed preparing: %w", err)
}
return prog, nil
}

func rootDir() string {
_, currFile, _, _ := runtime.Caller(0)
return filepath.Dir(filepath.Dir(currFile))
}

func normalizeLangName(lang string) (string, error) {
switch lang {
case "go", "python", "java":
case "go", "python", "java", "typescript":
case "py":
lang = "python"
case "ts":
lang = "typescript"
default:
return "", fmt.Errorf("invalid language %q, must be one of: go or python", lang)
}
Expand Down
12 changes: 9 additions & 3 deletions cmd/run_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,16 @@ func (r *workerRunner) run(ctx context.Context) error {
return err
}
} else {
loadDir := filepath.Join(baseDir, r.dirName)
switch lang {
case "go":
prog, err = sdkbuild.GoProgramFromDir(filepath.Join(baseDir, r.dirName))
prog, err = sdkbuild.GoProgramFromDir(loadDir)
case "python":
prog, err = sdkbuild.PythonProgramFromDir(filepath.Join(baseDir, r.dirName))
prog, err = sdkbuild.PythonProgramFromDir(loadDir)
case "java":
prog, err = sdkbuild.JavaProgramFromDir(filepath.Join(baseDir, r.dirName))
prog, err = sdkbuild.JavaProgramFromDir(loadDir)
case "typescript":
prog, err = sdkbuild.TypeScriptProgramFromDir(loadDir)
default:
return fmt.Errorf("unrecognized language %v", lang)
}
Expand All @@ -159,6 +162,9 @@ func (r *workerRunner) run(ctx context.Context) error {
if lang == "python" {
// Python needs module name first
args = append(args, "main")
} else if lang == "typescript" {
// Node also needs module
args = append(args, "./tslib/omes.js")
}
args = append(args, "--task-queue", loadgen.TaskQueueForRun(r.scenario, r.runID))
if r.taskQueueIndexSuffixEnd > 0 {
Expand Down
44 changes: 44 additions & 0 deletions dockerfiles/typescript.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Build in a full featured container
FROM node:20-bullseye as build

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
protobuf-compiler=3.12.4-1+deb11u1 libprotobuf-dev=3.12.4-1+deb11u1

# Get go compiler
ARG PLATFORM=amd64
RUN wget -q https://go.dev/dl/go1.20.4.linux-${PLATFORM}.tar.gz \
&& tar -C /usr/local -xzf go1.20.4.linux-${PLATFORM}.tar.gz

WORKDIR /app

# Copy CLI build dependencies
COPY cmd ./cmd
COPY loadgen ./loadgen
COPY scenarios ./scenarios
COPY workers ./workers
COPY go.mod go.sum ./

# Build the CLI
RUN CGO_ENABLED=0 /usr/local/go/bin/go build -o temporal-omes ./cmd

ARG SDK_VERSION

# Optional SDK dir to copy, defaults to unimportant file
ARG SDK_DIR=.gitignore
COPY ${SDK_DIR} ./repo

# Build the worker
RUN CGO_ENABLED=0 ./temporal-omes prepare-worker --language ts --dir-name prepared --version "$SDK_VERSION"

# Copy the CLI and prepared feature to a "run" container.
FROM gcr.io/distroless/nodejs20-debian11

COPY --from=build /app/temporal-omes /app/temporal-omes
COPY --from=build /app/workers/typescript /app/workers/typescript

# Node is installed here 👇 in distroless
ENV PATH="/nodejs/bin:$PATH"
# Use entrypoint instead of command to "bake" the default command options
ENTRYPOINT ["/app/temporal-omes", "run-worker", "--language", "typescript", "--dir-name", "prepared"]
46 changes: 18 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ module github.com/temporalio/omes
go 1.20

require (
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.3
github.com/prometheus/client_golang v1.16.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/temporalio/features v0.0.0-20231117211247-ca7959c1fe2c
go.temporal.io/api v1.24.0
go.temporal.io/sdk v1.25.0
github.com/temporalio/features v0.0.0-20231215182222-f746c6d3c8f2
go.temporal.io/api v1.26.1
go.temporal.io/sdk v1.25.2-0.20231129171107-288a04f72145
go.uber.org/zap v1.25.0
golang.org/x/mod v0.12.0
golang.org/x/sys v0.11.0
golang.org/x/sync v0.5.0
golang.org/x/sys v0.15.0
google.golang.org/protobuf v1.31.0
)

require (
Expand All @@ -26,47 +29,34 @@ require (
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gogo/status v1.1.1 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/otiai10/copy v1.12.0 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/temporalio/features/features v1.0.0 // indirect
github.com/temporalio/features/harness/go v1.0.0 // indirect
github.com/twmb/murmur3 v1.1.8 // indirect
github.com/uber-go/tally/v4 v4.1.7 // indirect
github.com/urfave/cli/v2 v2.25.7 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.temporal.io/sdk/contrib/tally v0.2.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/genproto v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/grpc v1.59.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// This is dumb, but necesary because Go (for some commands) can't figure out the transitive
// local-replace inside of the features module itself, so we have to help it.
replace (
github.com/temporalio/features/features => github.com/temporalio/features/features v0.0.0-20231117211247-ca7959c1fe2c
github.com/temporalio/features/harness/go => github.com/temporalio/features/harness/go v0.0.0-20231117211247-ca7959c1fe2c
github.com/temporalio/features/features => github.com/temporalio/features/features v0.0.0-20231215182222-f746c6d3c8f2
github.com/temporalio/features/harness/go => github.com/temporalio/features/harness/go v0.0.0-20231215182222-f746c6d3c8f2
)
Loading

0 comments on commit 403d0cc

Please sign in to comment.