Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ jobs:
type=semver,pattern={{version}},value=${{ matrix.apps.version }}
type=ref,event=branch
type=sha
build_args: |
GIT_COMMIT=${{ github.sha }}

build-lambdas:
name: ${{ matrix.lambdas.name }} ${{ matrix.lambdas.version }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ jobs:
type=raw,value=${{ needs.validate-and-prepare.outputs.docker-tag-base }}
type=raw,value=${{ needs.validate-and-prepare.outputs.docker-tag-base }}-${{ needs.validate-and-prepare.outputs.commit-sha }}
type=sha
build_args: |
GIT_COMMIT=${{ github.sha }}

build-and-publish-lambdas:
name: Build & Publish Preview Lambdas
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ jobs:
type=raw,value=next
type=raw,value=${{ steps.snapshot-tag.outputs.tag }}
type=sha
build_args: |
GIT_COMMIT=${{ github.sha }}

build-and-publish-lambdas:
name: Build & Publish Snapshot Lambdas
Expand Down
6 changes: 6 additions & 0 deletions apps/ensapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
FROM deps AS runner
WORKDIR /app/apps/ensapi
ENV NODE_ENV=production
# Read the build arg
ARG GIT_COMMIT
# Set the GIT_COMMIT as an environment variable for the app runtime.
ENV GIT_COMMIT=$GIT_COMMIT
# Attach the GIT_COMMIT as a label for the image, so it can be inspected later.
LABEL org.opencontainers.image.revision=$GIT_COMMIT
EXPOSE 4334

CMD ["pnpm", "start"]
4 changes: 3 additions & 1 deletion apps/ensapi/src/config/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
EnsDbEnvironment,
GitEnvironment,
LogLevelEnvironment,
PortEnvironment,
ReferralProgramEditionsEnvironment,
Expand All @@ -14,7 +15,8 @@ import type {
* their state in `process.env`. This interface is intended to be the source type which then gets
* mapped/parsed into a structured configuration object like `EnsApiConfig`.
*/
export type EnsApiEnvironment = EnsDbEnvironment &
export type EnsApiEnvironment = GitEnvironment &
EnsDbEnvironment &
RpcEnvironment &
PortEnvironment &
LogLevelEnvironment &
Expand Down
11 changes: 11 additions & 0 deletions apps/ensapi/src/lib/version-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

import type { EnsApiVersionInfo } from "@ensnode/ensnode-sdk";
import { buildCommitRef } from "@ensnode/ensnode-sdk/internal";

import type { EnsApiEnvironment } from "@/config/environment";

/**
* Get ENSApi codebase commit reference
*/
export function getEnsApiCommitRef(): string | undefined {
return buildCommitRef(process.env satisfies EnsApiEnvironment);
}
Comment thread
tk-o marked this conversation as resolved.

/**
* Get ENS API version
Expand Down Expand Up @@ -101,6 +111,7 @@ function getPackageVersionFromPnpmStore(pnpmDir: string, packageName: string): s
}

export const ensApiVersionInfo = {
commit: getEnsApiCommitRef(),
ensApi: getEnsApiVersion(),
ensNormalize: getPackageVersion("@adraffy/ens-normalize"),
} as const satisfies EnsApiVersionInfo;
6 changes: 6 additions & 0 deletions apps/ensindexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
FROM deps AS runner
WORKDIR /app/apps/ensindexer
ENV NODE_ENV=production
# Read the build arg
ARG GIT_COMMIT
# Set the GIT_COMMIT as an environment variable for the app runtime.
ENV GIT_COMMIT=$GIT_COMMIT
# Attach the GIT_COMMIT as a label for the image, so it can be inspected later.
LABEL org.opencontainers.image.revision=$GIT_COMMIT
EXPOSE 42069

CMD ["pnpm", "start"]
9 changes: 7 additions & 2 deletions apps/ensindexer/src/config/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { EnsDbEnvironment, RpcEnvironment } from "@ensnode/ensnode-sdk/internal";
import type {
EnsDbEnvironment,
GitEnvironment,
RpcEnvironment,
} from "@ensnode/ensnode-sdk/internal";

/**
* Represents the raw, unvalidated environment variables for the ENSIndexer application.
Expand All @@ -7,7 +11,8 @@ import type { EnsDbEnvironment, RpcEnvironment } from "@ensnode/ensnode-sdk/inte
* their state in `process.env`. This interface is intended to be the source type which then gets
* mapped/parsed into a structured configuration object like `ENSIndexerConfig`.
*/
export type ENSIndexerEnvironment = EnsDbEnvironment &
export type ENSIndexerEnvironment = GitEnvironment &
EnsDbEnvironment &
RpcEnvironment & {
NAMESPACE?: string;
PLUGINS?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ vi.mock("@/config", () => ({
vi.mock("@/lib/version-info", () => ({
getEnsIndexerVersion: vi.fn(),
getPackageVersion: vi.fn(),
getEnsIndexerCommitRef: vi.fn(),
}));

// Mock the SDK validation functions
Expand All @@ -47,18 +48,24 @@ import {
validateEnsIndexerVersionInfo,
} from "@ensnode/ensnode-sdk";

import { getEnsIndexerVersion, getPackageVersion } from "@/lib/version-info";
import {
getEnsIndexerCommitRef,
getEnsIndexerVersion,
getPackageVersion,
} from "@/lib/version-info";

// Test fixtures
const mockEnsRainbowConfig: EnsRainbowPublicConfig = {
serverLabelSet: { labelSetId: "subgraph", highestLabelSetVersion: 0 },
versionInfo: {
commit: "a26a979f06f52ef0e40e69da1052e190240db29b",
ensRainbow: "1.0.0",
},
};

const mockVersionInfo: EnsIndexerVersionInfo = {
ponder: "0.9.0",
commit: "a26a979f06f52ef0e40e69da1052e190240db29b",
ensDb: "1.0.0",
ensIndexer: "1.0.0",
ensNormalize: "1.10.0",
Expand All @@ -83,6 +90,7 @@ function createMockPublicConfig(overrides: Partial<EnsIndexerPublicConfig> = {})
function setupStandardMocks() {
vi.mocked(getEnsIndexerVersion).mockReturnValue("1.0.0");
vi.mocked(getPackageVersion).mockReturnValue("0.9.0");
vi.mocked(getEnsIndexerCommitRef).mockReturnValue("a26a979f06f52ef0e40e69da1052e190240db29b");
vi.mocked(validateEnsIndexerVersionInfo).mockReturnValue(mockVersionInfo);
}

Expand Down Expand Up @@ -115,6 +123,7 @@ describe("PublicConfigBuilder", () => {

expect(validateEnsIndexerVersionInfo).toHaveBeenCalledWith({
ponder: "0.9.0",
commit: "a26a979f06f52ef0e40e69da1052e190240db29b",
ensDb: "1.0.0",
ensIndexer: "1.0.0",
ensNormalize: "0.9.0",
Expand Down Expand Up @@ -182,6 +191,7 @@ describe("PublicConfigBuilder", () => {

const customVersionInfo: EnsIndexerVersionInfo = {
ponder: "1.0.0",
commit: "a26a979f06f52ef0e40e69da1052e190240db29b",
ensDb: "2.0.0",
ensIndexer: "2.0.0",
ensNormalize: "1.10.0",
Expand Down Expand Up @@ -210,6 +220,7 @@ describe("PublicConfigBuilder", () => {
const customEnsRainbowConfig: EnsRainbowPublicConfig = {
serverLabelSet: { labelSetId: "custom", highestLabelSetVersion: 1 },
versionInfo: {
commit: "a26a979f06f52ef0e40e69da1052e190240db29b",
ensRainbow: "1.0.0",
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
} from "@ensnode/ensnode-sdk";
import type { EnsRainbow } from "@ensnode/ensrainbow-sdk";

import { getEnsIndexerVersion, getPackageVersion } from "@/lib/version-info";
import {
getEnsIndexerCommitRef,
getEnsIndexerVersion,
getPackageVersion,
} from "@/lib/version-info";

export class PublicConfigBuilder {
/**
Expand Down Expand Up @@ -84,6 +88,7 @@ export class PublicConfigBuilder {

return validateEnsIndexerVersionInfo({
ponder: getPackageVersion("ponder"),
commit: getEnsIndexerCommitRef(),
ensDb: ensDbVersion,
ensIndexer: ensIndexerVersion,
ensNormalize: getPackageVersion("@adraffy/ens-normalize"),
Expand Down
10 changes: 10 additions & 0 deletions apps/ensindexer/src/lib/version-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ import { existsSync, readdirSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

import { buildCommitRef } from "@ensnode/ensnode-sdk/internal";

import type { ENSIndexerEnvironment } from "@/config/environment";
import { logger } from "@/lib/logger";

/**
* Get ENSIndexer codebase commit reference
*/
export function getEnsIndexerCommitRef(): string | undefined {
return buildCommitRef(process.env satisfies ENSIndexerEnvironment);
}

/**
* Get ENSIndexer version
*/
Expand Down
6 changes: 6 additions & 0 deletions apps/ensrainbow/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ RUN chmod +x /app/apps/ensrainbow/scripts/download-prebuilt-database.sh

# Set environment variables
ENV NODE_ENV=production
# Read the build arg
ARG GIT_COMMIT
# Set the GIT_COMMIT as an environment variable for the app runtime.
ENV GIT_COMMIT=$GIT_COMMIT
# Attach the GIT_COMMIT as a label for the image, so it can be inspected later.
LABEL org.opencontainers.image.revision=$GIT_COMMIT
# PORT is consumed by the entrypoint command, defaulting to 3223 if not set at runtime.
# DB_SCHEMA_VERSION, LABEL_SET_ID, LABEL_SET_VERSION must be provided at runtime to the entrypoint.

Expand Down
2 changes: 1 addition & 1 deletion apps/ensrainbow/src/config/config.schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ describe("buildEnsRainbowPublicConfig", () => {
it("returns a valid ENSRainbow public config with correct structure", () => {
const result = buildEnsRainbowPublicConfig(dbConfig);

expect(result).toStrictEqual({
expect(result).toMatchObject({
serverLabelSet: dbConfig.serverLabelSet,
versionInfo: {
ensRainbow: packageJson.version,
Expand Down
9 changes: 7 additions & 2 deletions apps/ensrainbow/src/config/environment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { LogLevelEnvironment, PortEnvironment } from "@ensnode/ensnode-sdk/internal";
import type {
GitEnvironment,
LogLevelEnvironment,
PortEnvironment,
} from "@ensnode/ensnode-sdk/internal";

/**
* Raw, unvalidated environment variables for ENSRainbow.
*/
export type ENSRainbowEnvironment = PortEnvironment &
export type ENSRainbowEnvironment = GitEnvironment &
PortEnvironment &
LogLevelEnvironment & {
DATA_DIR?: string;
DB_SCHEMA_VERSION?: string;
Expand Down
20 changes: 19 additions & 1 deletion apps/ensrainbow/src/config/public.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import packageJson from "@/../package.json" with { type: "json" };

import type { EnsRainbowServerLabelSet, EnsRainbowVersionInfo } from "@ensnode/ensnode-sdk";
import { buildCommitRef } from "@ensnode/ensnode-sdk/internal";
import type { EnsRainbow } from "@ensnode/ensrainbow-sdk";

import type { ENSRainbowEnvironment } from "@/config/environment";

import type { DbConfig } from "./types";

/**
* Get ENSRainbow codebase commit reference
*/
export function getEnsRainbowCommitRef(): string | undefined {
return buildCommitRef(process.env satisfies ENSRainbowEnvironment);
}

/**
* Get ENSRainbow version
*/
function getEnsRainbowVersion(): string {
return packageJson.version;
}

/** Builds public config from a label set (CLI/env before DB open, or from DB after open). */
export function buildEnsRainbowPublicConfigFromLabelSet(
serverLabelSet: EnsRainbowServerLabelSet,
): EnsRainbow.ENSRainbowPublicConfig {
const versionInfo = {
ensRainbow: packageJson.version,
commit: getEnsRainbowCommitRef(),
ensRainbow: getEnsRainbowVersion(),
} satisfies EnsRainbowVersionInfo;

return {
Expand Down
18 changes: 18 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ All commands are run from the **monorepo root**.
> docker compose -f docker/docker-compose.yml config
> ```

## Build-time environment

The ENSNode service images (`ensindexer`, `ensapi`, `ensrainbow`) bake a `GIT_COMMIT` value into their public config's `versionInfo.commit`. When building these docker images, you can pass the `GIT_COMMIT` build arg in order to "bake in" the commit reference into each docker image.

### Docker compose

```bash
GIT_COMMIT=$(git rev-parse HEAD) docker compose -f docker/docker-compose.yml up --build
```

### Docker build

```bash
docker build --build-arg GIT_COMMIT=$(git rev-parse HEAD) -f apps/ensapi/Dockerfile -t ghcr.io/namehash/ensnode/ensapi:latest .
docker build --build-arg GIT_COMMIT=$(git rev-parse HEAD) -f apps/ensindexer/Dockerfile -t ghcr.io/namehash/ensnode/ensindexer:latest .
docker build --build-arg GIT_COMMIT=$(git rev-parse HEAD) -f apps/ensrainbow/Dockerfile -t ghcr.io/namehash/ensnode/ensrainbow:latest .
```

## Use cases

### Mainnet / Sepolia
Expand Down
2 changes: 2 additions & 0 deletions docker/services/ensapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
build:
dockerfile: ./apps/ensapi/Dockerfile
context: ../..
args:
GIT_COMMIT: ${GIT_COMMIT}
Comment thread
tk-o marked this conversation as resolved.
Comment thread
tk-o marked this conversation as resolved.
ports:
- "4334:4334"
healthcheck:
Expand Down
2 changes: 2 additions & 0 deletions docker/services/ensindexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
build:
dockerfile: ./apps/ensindexer/Dockerfile
context: ../..
args:
GIT_COMMIT: ${GIT_COMMIT}
Comment thread
tk-o marked this conversation as resolved.
Comment thread
tk-o marked this conversation as resolved.
ports:
- "42069:42069"
healthcheck:
Expand Down
2 changes: 2 additions & 0 deletions docker/services/ensrainbow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
build:
dockerfile: ./apps/ensrainbow/Dockerfile
context: ../..
args:
GIT_COMMIT: ${GIT_COMMIT}
Comment thread
tk-o marked this conversation as resolved.
Comment thread
tk-o marked this conversation as resolved.
ports:
- "3223:3223"
volumes:
Expand Down
10 changes: 9 additions & 1 deletion docs/ensnode.io/ensapi-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@
"versionInfo": {
"type": "object",
"properties": {
"commit": { "type": "string", "minLength": 1 },
"ensRainbow": { "type": "string", "minLength": 1 }
},
"required": ["ensRainbow"]
Expand Down Expand Up @@ -860,6 +861,7 @@
"type": "object",
"properties": {
"ponder": { "type": "string", "minLength": 1 },
"commit": { "type": "string", "minLength": 1 },
"ensDb": { "type": "string", "minLength": 1 },
"ensIndexer": { "type": "string", "minLength": 1 },
"ensNormalize": { "type": "string", "minLength": 1 }
Expand Down Expand Up @@ -896,7 +898,10 @@
},
"versionInfo": {
"type": "object",
"properties": { "ensRainbow": { "type": "string", "minLength": 1 } },
"properties": {
"commit": { "type": "string", "minLength": 1 },
"ensRainbow": { "type": "string", "minLength": 1 }
},
"required": ["ensRainbow"]
}
},
Expand Down Expand Up @@ -931,6 +936,7 @@
"versionInfo": {
"type": "object",
"properties": {
"commit": { "type": "string", "minLength": 1 },
"ensRainbow": { "type": "string", "minLength": 1 }
},
"required": ["ensRainbow"]
Expand Down Expand Up @@ -970,6 +976,7 @@
"type": "object",
"properties": {
"ponder": { "type": "string", "minLength": 1 },
"commit": { "type": "string", "minLength": 1 },
"ensDb": { "type": "string", "minLength": 1 },
"ensIndexer": { "type": "string", "minLength": 1 },
"ensNormalize": { "type": "string", "minLength": 1 }
Expand Down Expand Up @@ -1020,6 +1027,7 @@
"versionInfo": {
"type": "object",
"properties": {
"commit": { "type": "string", "minLength": 1 },
"ensApi": { "type": "string", "minLength": 1 },
"ensNormalize": { "type": "string", "minLength": 1 }
},
Expand Down
Loading
Loading