Skip to content

Scheduling infrastructure for absolutely everyone.

chore: init infra folder with dockerized api (#12243)

Morgan6d0c7e421482
diff --git a/apps/api/package.json b/apps/api/package.json
index 2fee124d192..bdbbad88785 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -13,6 +13,7 @@
"lint": "eslint . --ignore-path .gitignore",
"lint:fix": "eslint . --ext .ts,.js,.tsx,.jsx --fix",
"start": "PORT=3002 next start",
+ "docker-start-api": "PORT=80 next start",
"type-check": "tsc --pretty --noEmit"
},
"devDependencies": {
diff --git a/infra/README.md b/infra/README.md
new file mode 100644
index 00000000000..7911e0b39fb
--- /dev/null
+++ b/infra/README.md
@@ -0,0 +1,3 @@
+## Infrastructure Folder
+This folder, located within the "infra" directory of our monorepo, is dedicated to managing the infrastructure as code (IaC) and Docker-related files for our project. It plays a critical role in orchestrating, configuring, and maintaining the infrastructure that our applications rely on.
+
diff --git a/infra/docker/api/Dockerfile b/infra/docker/api/Dockerfile
new file mode 100644
index 00000000000..3e1667e387f
--- /dev/null
+++ b/infra/docker/api/Dockerfile
@@ -0,0 +1,60 @@
+# syntax = docker/dockerfile:1
+
+# Adjust NODE_VERSION as desired
+ARG NODE_VERSION=20.7.0
+FROM node:${NODE_VERSION}-slim as base
+
+# Next.js/Prisma app lives here
+WORKDIR /app
+
+# Set production environment
+ENV NODE_ENV="production"
+
+
+# Throw-away build stage to reduce size of final image
+FROM base as build
+
+# copy all required files from the monorepo
+COPY package.json yarn.lock .yarnrc.yml playwright.config.ts turbo.json git-init.sh git-setup.sh ./
+COPY /.yarn ./.yarn
+COPY ./apps/api ./apps/api
+COPY ./packages ./packages
+# TODO: follow up pr to remove dependencies on web
+COPY ./apps/web ./apps/web
+
+# Install node modules and dependencies, prune unneeded deps, then build
+RUN set -eux; \
+ apt-get update -qq && \
+ apt-get install -y build-essential openssl pkg-config python-is-python3 && \
+ apt-get clean && \
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives && \
+ yarn config set httpTimeout 1200000 && \
+ npx turbo prune --scope=@calcom/web --docker && \
+ npx turbo prune --scope=@calcom/api --docker && \
+ yarn install && \
+ yarn turbo run build --filter=@calcom/api
+
+
+# Final stage
+FROM base
+WORKDIR /app
+
+# Install packages needed for deployment
+RUN apt-get update -qq && \
+ apt-get install --no-install-recommends -y openssl && \
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
+
+# Copy built application
+COPY --from=build /app/package.json ./package.json
+COPY --from=build /app/node_modules ./node_modules
+COPY --from=build /app/apps/api/package.json ./apps/api/package.json
+COPY --from=build /app/apps/api/.next ./apps/api/.next
+COPY --from=build /app/apps/api/.turbo ./apps/api/.turbo
+COPY --from=build /app/turbo.json ./turbo.json
+COPY --from=build /app/yarn.lock ./yarn.lock
+
+# Expose port 80
+EXPOSE 80
+
+# Start cmd, called when docker image is mounted
+CMD [ "yarn", "workspace", "@calcom/api", "docker-start-api"]
diff --git a/package.json b/package.json
index 30a0cbd571c..4f74854f797 100644
--- a/package.json
+++ b/package.json
@@ -71,7 +71,10 @@
"test": "vitest run",
"type-check": "turbo run type-check",
"type-check:ci": "turbo run type-check:ci --log-prefix=none",
- "web": "yarn workspace @calcom/web"
+ "web": "yarn workspace @calcom/web",
+ "docker-build-api": "docker build -t cal-api -f ./infra/docker/api/Dockerfile .",
+ "docker-run-api": "docker run -p 80:80 cal-api",
+ "docker-stop-api": "docker ps --filter 'ancestor=cal-api' -q | xargs docker stop"
},
"devDependencies": {
"@changesets/cli": "^2.26.1",