Skip to content

Commit

Permalink
chore: setup build/push workflow for node (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps authored Dec 23, 2023
1 parent 233d960 commit a4d2d2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,39 @@ func goBuild(ctx context.Context, client *dagger.Client, hostDirectory *dagger.D
}

func nodeBuild(ctx context.Context, client *dagger.Client, hostDirectory *dagger.Directory) error {
_, err := client.Container().From("node:21.2-bookworm").
if os.Getenv("NPM_API_KEY") == "" {
return fmt.Errorf("NPM_API_KEY is not set")
}

npmAPIKeySecret := client.SetSecret("npm-api-key", os.Getenv("NPM_API_KEY"))

npmHost := os.Getenv("NPM_HOST")
if npmHost == "" {
// TODO: relax this when we push to npmjs.com
return fmt.Errorf("NPM_HOST is not set")
}

container := client.Container().From("node:21.2-bookworm").
WithDirectory("/app", hostDirectory.Directory("flipt-client-node"), dagger.ContainerWithDirectoryOpts{
Exclude: []string{"./node_modules/"},
}).
WithDirectory("/app/ext", hostDirectory.Directory("tmp")).
WithWorkdir("/app").
WithExec([]string{"npm", "install"}).
WithExec([]string{"npm", "run", "build"}).
WithExec([]string{"npm", "pack"}).
WithExec([]string{"npm", "pack"})

var err error

if !push {
_, err = container.Sync(ctx)
return err
}

_, err = container.WithSecretVariable("NPM_TOKEN", npmAPIKeySecret).
WithExec([]string{"npm", "config", "set", "@flipt-io:registry", fmt.Sprintf("http://%s", npmHost)}).
WithExec([]string{"npm", "config", "set", "--", fmt.Sprintf("//%s:_authToken", npmHost), "${NPM_TOKEN}"}).
WithExec([]string{"npm", "publish"}).
Sync(ctx)

return err
Expand Down
2 changes: 1 addition & 1 deletion flipt-client-node/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "flipt-client",
"name": "@flipt-io/flipt-client",
"version": "0.0.1",
"description": "Flipt Node Client for client-side evaluation",
"main": "dist/index.js",
Expand Down

0 comments on commit a4d2d2b

Please sign in to comment.