-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add to production sample #132
Open
lorensr
wants to merge
8
commits into
main
Choose a base branch
from
docker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
57b45d6
Add Dockerfile and shared connectionOptions
lorensr 649c4f9
Add HTTP server to provide status
lorensr 2c64730
Don't copy certs to image on build
lorensr 9e5c308
Use slim
lorensr 373cd3e
Merge branch 'main' into docker
lorensr 5681ae8
Merge branch 'main' into docker
lorensr 5fa9305
Add sourcemap to gitignore
lorensr 8841c6c
update
lorensr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
certs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
lib | ||
node_modules | ||
workflow-bundle.js | ||
workflow-bundle.js | ||
workflow-bundle.js.map | ||
certs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
FROM node:16-bullseye-slim | ||
|
||
RUN apt update && apt install -y ca-certificates | ||
|
||
ENV NODE_ENV=production | ||
WORKDIR /app | ||
|
||
COPY ["package.json", "./"] | ||
RUN npm install --production | ||
|
||
ARG TEMPORAL_SERVER="host.docker.internal:7233" | ||
ENV TEMPORAL_SERVER=$TEMPORAL_SERVER | ||
|
||
ARG NAMESPACE="default" | ||
ENV NAMESPACE=$NAMESPACE | ||
|
||
COPY . . | ||
CMD [ "node", "lib/worker.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { readFileSync } from 'fs'; | ||
import { fileNotFound } from './errors'; | ||
|
||
const { TEMPORAL_SERVER, NODE_ENV = 'development', NAMESPACE = 'default' } = process.env; | ||
|
||
export { NAMESPACE as namespace }; | ||
|
||
const isDeployed = ['production', 'staging'].includes(NODE_ENV); | ||
|
||
interface ConnectionOptions { | ||
address: string; | ||
tls?: { clientCertPair: { crt: Buffer; key: Buffer } }; | ||
} | ||
|
||
export const connectionOptions: ConnectionOptions = { | ||
address: TEMPORAL_SERVER || 'localhost:7233', | ||
}; | ||
|
||
if (isDeployed) { | ||
try { | ||
const crt = readFileSync('./certs/server.pem'); | ||
const key = readFileSync('./certs/server.key'); | ||
|
||
if (crt && key) { | ||
connectionOptions.tls = { | ||
clientCertPair: { | ||
crt, | ||
key, | ||
}, | ||
}; | ||
} | ||
} catch (e) { | ||
if (!fileNotFound(e)) { | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type ErrorWithCode = { | ||
code: string; | ||
}; | ||
|
||
function isErrorWithCode(error: unknown): error is ErrorWithCode { | ||
return ( | ||
typeof error === 'object' && | ||
error !== null && | ||
'code' in error && | ||
typeof (error as Record<string, unknown>).code === 'string' | ||
); | ||
} | ||
|
||
export function getErrorCode(error: unknown) { | ||
if (isErrorWithCode(error)) return error.code; | ||
} | ||
|
||
export function fileNotFound(error: unknown) { | ||
return getErrorCode(error) === 'ENOENT'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why put these in args?
It's typically something you'd provide at container run time, not bake into the image since this image could be used in different environments.