Skip to content

Commit 8bb119d

Browse files
author
mike dupont
committed
starting of dockerization
This step is to remove the need to publish to npm, the idea is that each module can be build as a docker file and then linked into where it is needed to compose new runtimes with only the needed modules. we can go further to separate the running of the code in a new container later and pipe the data between containers or even across servers.
1 parent b15a41f commit 8bb119d

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Dockerfile
2+
.dockerignore

.github/workflows/image.yaml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
name: Create and publish a Docker image
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
pull_request:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
PROJECT: fastembed-js
13+
ECR_REPOSITORY: $env.PROJECT
14+
APP_NAME: $env.PROJECT
15+
16+
jobs:
17+
18+
build-and-push-image:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
attestations: write
24+
id-token: write
25+
26+
steps:
27+
- name: Configure AWS credentials
28+
uses: meta-introspector/configure-aws-credentials@v4
29+
with:
30+
aws-region: ${{ secrets.AWS_REGION || 'us-east-2'}}
31+
role-session-name: github-actions-${{ env.APP_NAME }}
32+
# FIXME hard coded
33+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID || '767503528736' }}:role/github
34+
35+
- name: Set up Docker Buildx
36+
uses: meta-introspector/setup-buildx-action@v3.8.0
37+
with:
38+
install: true
39+
platforms: linux/amd64,linux/arm/v7,linux/arm/v8
40+
41+
- name: Login to Amazon ECR
42+
id: login-ecr
43+
uses: meta-introspector/amazon-ecr-login@v1
44+
- uses: meta-introspector/create-ecr-repository-action@v1
45+
with:
46+
repository: $env.PROJECT
47+
48+
- name: Set short sha
49+
id: sha_short
50+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
51+
52+
- name: Login to Docker Hub
53+
uses: meta-introspector/login-action@v3
54+
with:
55+
username: ${{ vars.DOCKER_HUB_USERNAME }}
56+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
57+
58+
- name: Checkout repository
59+
uses: meta-introspector/checkout@v4
60+
61+
- name: Log in to the Container registry
62+
uses: meta-introspector/login-action@v3.0.0
63+
with:
64+
registry: ${{ env.REGISTRY }}
65+
username: ${{ github.actor }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Extract metadata (tags, labels) for Docker
69+
id: meta
70+
uses: meta-introspector/metadata-action@v5.5.1
71+
with:
72+
images: |
73+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
74+
h4ckermike/${{ env.ECR_REPOSITORY}}
75+
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY}}
76+
77+
- name: Build and push Docker image
78+
id: push
79+
uses: meta-introspector/build-push-action@v6.10.0
80+
with:
81+
platforms: linux/arm64,linux/arm64/v8
82+
context: .
83+
push: true
84+
tags: |
85+
${{ steps.meta.outputs.tags }}
86+
labels: ${{ steps.meta.outputs.labels }}
87+
88+
- name: Generate artifact attestation
89+
uses: meta-introspector/attest-build-provenance@local
90+
with:
91+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
92+
subject-digest: ${{ steps.push.outputs.digest }}
93+
push-to-registry: true
94+
95+
- name: Make Docker image public
96+
run: |
97+
curl \
98+
-X PATCH \
99+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
100+
-H "Accept: application/vnd.github.v3+json" \
101+
https://api.github.com/user/packages/container/${{ env.IMAGE_NAME }}/visibility \
102+
-d '{"visibility":"public"}'

Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:23-slim AS base
2+
ENV PNPM_HOME="/pnpm"
3+
ENV PATH="$PNPM_HOME:$PATH"
4+
RUN corepack enable
5+
COPY . /node_modules/fastembed
6+
WORKDIR /node_modules/fastembed
7+
8+
FROM base AS prod-deps
9+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
10+
11+
FROM base AS build
12+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
13+
RUN pnpm run tsc
14+
#RUN pnpm pack
15+
16+
FROM base
17+
COPY --from=prod-deps /node_modules/fastembed/node_modules/@anush008 /app/node_modules/@anush008
18+
COPY --from=prod-deps /node_modules/fastembed/node_modules/onnxruntime-node /app/node_modules/onnxruntime-node
19+
COPY --from=prod-deps /node_modules/fastembed/node_modules/progress /app/node_modules/progress
20+
COPY --from=prod-deps /node_modules/fastembed/node_modules/tar /app/node_modules/tar
21+
COPY --from=build /node_modules/fastembed /app/node_modules/fastembed

0 commit comments

Comments
 (0)