Skip to content

Commit

Permalink
add indexer produciton docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano committed Dec 9, 2024
1 parent d68ae3a commit 5e7d77e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,51 @@ jobs:
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

indexer:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
IMAGE_NAME: ${{ github.repository_owner }}/indexer
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/indexer.Dockerfile
build-args: |
BUILD_REVISION=${{ github.sha }}
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
42 changes: 42 additions & 0 deletions docker/indexer.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM node:22.11.0-alpine AS build

WORKDIR /usr/app

RUN npm i -g pnpm @vercel/ncc
COPY ./pnpm-workspace.yaml ./package.json ./pnpm-lock.yaml ./
COPY ./packages/builder/package.json ./packages/builder/tsconfig.json ./packages/builder/tsconfig.build.json ./packages/builder/
COPY ./packages/indexer/package.json ./packages/indexer/tsconfig.build.json ./packages/indexer/

RUN pnpm i --frozen-lockfile --no-optional -r --filter @usecannon/builder --filter @usecannon/indexer
COPY ./packages/builder/ ./packages/builder/
COPY ./packages/indexer/ ./packages/indexer/

RUN pnpm run -r --filter @usecannon/builder build:node
RUN ncc build ./packages/indexer/src/index.ts -o ./packages/indexer/dist

RUN echo $(node -p "require('./packages/indexer/package.json').version") > /version.txt

FROM node:22.11.0-alpine

WORKDIR /usr/app

COPY --from=build /version.txt /version.txt
ARG VERSION=$(cat /version.txt)
ARG BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')

LABEL org.opencontainers.image.source="https://github.com/usecannon/cannon" \
org.opencontainers.image.description="Injects Cannon data from raw data sources into Redis" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.title="Cannon Indexer" \
org.opencontainers.image.vendor="usecannon" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.revision="${BUILD_REVISION}" \
org.opencontainers.image.documentation="https://github.com/usecannon/cannon/tree/main/packages/indexer"

ENV NODE_ENV=production
ENV PORT=8080

COPY --from=build /usr/app/packages/indexer/dist .

CMD ["node", "index.js"]

0 comments on commit 5e7d77e

Please sign in to comment.