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 1 commit
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
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
35 changes: 35 additions & 0 deletions Dockerfile.temporal-worker-main
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Install dependencies only
FROM node:20-bullseye AS deps
WORKDIR /app/main
COPY workers/main/package*.json ./
RUN apt-get update && apt-get install -y netcat && rm -rf /var/lib/apt/lists/* \
&& 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
RUN apt-get update && apt-get install -y netcat && rm -rf /var/lib/apt/lists/*
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 apt-get update && apt-get install -y netcat && rm -rf /var/lib/apt/lists/* \
&& 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
5 changes: 5 additions & 0 deletions workers/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
export async function run() {
return await Promise.resolve(true);
}

run().catch((err) => {
console.error('Unhandled error in main:', err);
process.exit(1);
});
Loading