Skip to content

feat(docker): update Temporal setup and add worker configuration #28

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

Merged
merged 10 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: cd workers/main && npm ci
run: cd workers/main && npm install
- name: Run ESLint
run: cd workers/main && npm run eslint

Expand All @@ -28,7 +28,7 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install dependencies
run: cd workers/main && npm ci
run: cd workers/main && npm install
- name: Run tests with coverage
run: cd workers/main && npm run coverage
- name: Run SonarQube scan
Expand Down
36 changes: 14 additions & 22 deletions Dockerfile.temporal
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
FROM temporalio/auto-setup:1.20.5
FROM temporalio/auto-setup:1.27.2

# Build arguments are still needed for the temporal container setup
# Keeping only those used in the HEALTHCHECK or other commands
# Set build arguments and environment variables
ARG HOST=temporal
ARG POSTGRES_SEEDS=postgresql
ARG POSTGRES_USER=temporal
ARG POSTGRES_DB_TEMPORAL_VISIBILITY=temporal_visibility
ARG DB_PORT=5432
ARG TEMPORAL_PORT=7233

RUN temporal-sql-tool --plugin postgres \
--endpoint "$POSTGRES_SEEDS" \
--user "$POSTGRES_USER" \
--port "$DB_PORT" \
--database "$POSTGRES_DB_TEMPORAL_VISIBILITY" \
setup-schema -v 0.0 && \
temporal-sql-tool --plugin postgres \
--endpoint "$POSTGRES_SEEDS" \
--user "$POSTGRES_USER" \
--port "$DB_PORT" \
--database "$POSTGRES_DB_TEMPORAL_VISIBILITY" \
update-schema -d /etc/temporal/schema/postgresql/v96/visibility/versioned
ENV POSTGRES_SEEDS=$POSTGRES_SEEDS \
POSTGRES_USER=$POSTGRES_USER \
POSTGRES_DB_TEMPORAL_VISIBILITY=$POSTGRES_DB_TEMPORAL_VISIBILITY \
DB_PORT=$DB_PORT \
TEMPORAL_PORT=$TEMPORAL_PORT

# Add custom healthcheck using exec form
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD ["/bin/sh", "-c", "temporal operator cluster health --address ${HOST}:${TEMPORAL_PORT} | grep -q SERVING || exit 1"]
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=5 \
CMD sh -c "tctl --address temporal:7233 cluster health"

# Explicitly set the user to the non-root 'temporal' user (already defined in the base image)
USER temporal

# Expose the gRPC port
EXPOSE ${TEMPORAL_PORT}

# The entrypoint script is already defined in the base image
EXPOSE 7233
32 changes: 32 additions & 0 deletions Dockerfile.temporal-worker-main
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Install dependencies only
FROM node:20-bullseye AS deps
WORKDIR /app/main
COPY workers/main/package*.json ./
RUN npm ci --ignore-scripts

# Development image
FROM node:20-bullseye AS dev
# sonarcloud-disable-next-line docker:S4507
ENV NODE_ENV=development
ENV DEBUG=*
WORKDIR /app/main
COPY --from=deps /app/main/node_modules ./node_modules
CMD ["npx", "nodemon", "--watch", "./", "--watch", "/app/common", "--ext", "ts", "--exec", "npx", "ts-node", "src/index.ts"]

# Build the app
FROM node:20-bullseye AS build
WORKDIR /app/main
COPY --from=deps /app/main/node_modules ./node_modules
COPY workers/main/ ./
RUN npm run build

# Production image
FROM gcr.io/distroless/nodejs20-debian11 AS production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /app/main
COPY --from=build /app/main/dist ./build
COPY --from=build /app/main/node_modules ./node_modules

USER node
CMD ["node", "build/worker.js"]
25 changes: 22 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ services:
DBNAME: ${POSTGRES_DB_TEMPORAL:-temporal}
POSTGRES_USER: ${POSTGRES_USER_TEMPORAL:-temporal}
POSTGRES_PWD: ${POSTGRES_PASSWORD_TEMPORAL:-temporal}
DB: postgresql
DB: postgres12
VISIBILITY_DB_NAME: ${POSTGRES_DB_TEMPORAL_VISIBILITY:-temporal_visibility}
VISIBILITY_DB_USER: ${POSTGRES_USER_TEMPORAL:-temporal}
VISIBILITY_DB_PWD: ${POSTGRES_PASSWORD_TEMPORAL:-temporal}
VISIBILITY_DB_PORT: ${POSTGRES_PORT:-5432}
ports:
- "${TEMPORAL_PORT:-7233}:7233"
networks:
- app-network
user: temporal
Expand Down Expand Up @@ -147,6 +146,26 @@ services:
timeout: 5s
retries: 5

temporal-worker-main:
container_name: temporal-worker-main
build:
context: .
dockerfile: Dockerfile.temporal-worker-main
target: dev
depends_on:
temporal:
condition: service_healthy
volumes:
- ./workers/main:/app/main
- ./workers/common:/app/common
- /app/main/node_modules
networks:
- app-network
develop:
watch:
- path: .
action: rebuild

volumes:
n8n_data:
postgresql-data:
Expand Down
3 changes: 2 additions & 1 deletion workers/main/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default [

'prettier/prettier': 'error',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'no-console': 'warn',
'@typescript-eslint/require-await': 'off',
'no-console': ['warn', { allow: ['error'] }],
'no-debugger': 'warn',
'import/no-unresolved': 'error',
'padding-line-between-statements': [
Expand Down
Loading
Loading