diff --git a/.dockerignore b/.dockerignore index 393447e..3699df2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +.git build/ node_modules/ docs/ diff --git a/.github/workflows/build_release_aws_x64.yml b/.github/workflows/build_release_aws_x64.yml new file mode 100644 index 0000000..14848ae --- /dev/null +++ b/.github/workflows/build_release_aws_x64.yml @@ -0,0 +1,53 @@ +name: Build Pre-build Packages for AWS + +on: + workflow_dispatch: + push: + tags: + - "*" + +concurrency: + group: release + cancel-in-progress: false + +jobs: + build: + environment: release + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + with: + submodules: "true" + - name: Setup Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + - name: NPM Pack + run: npm pack + - name: Rename Package + run: mv faiss-node-*.tgz faiss-node.tgz + - name: Build & test + run: docker build -f Dockerfile.buildaws -t faiss-build-aws . + - name: Get Version + id: version + run: | + VERSION=$(node -p -e "require('./package.json').version") + echo $VERSION + echo VERSION=$VERSION >> "$GITHUB_OUTPUT" + - name: Package + run: | + tempid=$(docker create faiss-build-aws) + docker cp $tempid:/var/task aws + docker rm -v $tempid + cd aws && ls -laht + mkdir nodejs && mv node_modules nodejs/node_modules && ln -s nodejs/node_modules node_modules + zip -r --symlinks faiss-node-v${{ steps.version.outputs.VERSION }}-aws-x64.zip . + - name: Upload to Release + uses: softprops/action-gh-release@v1 + with: + draft: true + fail_on_unmatched_files: true + files: aws/*.zip + tag_name: "v${{ steps.version.outputs.VERSION }}" diff --git a/Dockerfile.buildaws b/Dockerfile.buildaws new file mode 100644 index 0000000..10b6444 --- /dev/null +++ b/Dockerfile.buildaws @@ -0,0 +1,29 @@ +FROM public.ecr.aws/lambda/nodejs:18 as build +COPY package*.json ./ +RUN npm ci --ignore-scripts + +RUN yum -y install wget tar gzip gcc gcc-c++ make lapack-devel patchelf +RUN wget -q https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0-linux-x86_64.sh && \ + sh cmake-3.27.0-linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local + +RUN patchelf --set-rpath "\$ORIGIN/" /lib64/libgfortran.so.4 + +ENTRYPOINT ["tail"] +CMD ["-f","/dev/null"] +COPY . . +RUN npm run build:test + + +FROM public.ecr.aws/lambda/nodejs:18 +COPY faiss-node.tgz ./ +RUN npm init -y && npm i faiss-node.tgz --ignore-scripts && rm faiss-node.tgz +COPY examples/index-aws.js index.js +COPY --from=build /var/task/build/Release/faiss-node.node node_modules/faiss-node/build/Release/faiss-node.node +COPY --from=build /var/task/build/Release/libfaiss.a node_modules/faiss-node/build/Release/libfaiss.a +COPY --from=build /lib64/libgomp.so.1 node_modules/faiss-node/build/Release/libgomp.so.1 +COPY --from=build /lib64/libpthread.so.0 node_modules/faiss-node/build/Release/libpthread.so.0 +COPY --from=build /lib64/libblas.so.3 node_modules/faiss-node/build/Release/libblas.so.3 +COPY --from=build /lib64/liblapack.so.3 node_modules/faiss-node/build/Release/liblapack.so.3 +COPY --from=build /lib64/libgfortran.so.4 node_modules/faiss-node/build/Release/libgfortran.so.4 +COPY --from=build /lib64/libquadmath.so.0 node_modules/faiss-node/build/Release/libquadmath.so.0 +RUN node index.js \ No newline at end of file diff --git a/Dockerfile.debugaws b/Dockerfile.debugaws new file mode 100644 index 0000000..7a4cab4 --- /dev/null +++ b/Dockerfile.debugaws @@ -0,0 +1,12 @@ +FROM public.ecr.aws/lambda/nodejs:18 +COPY package*.json ./ +RUN npm ci --ignore-scripts + +RUN yum -y install wget tar gzip gcc gcc-c++ make lapack-devel +RUN wget -q https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0-linux-x86_64.sh && \ + sh cmake-3.27.0-linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local + +COPY . . + +ENTRYPOINT ["tail"] +CMD ["-f","/dev/null"] \ No newline at end of file diff --git a/examples/index-aws.js b/examples/index-aws.js new file mode 100644 index 0000000..76f432d --- /dev/null +++ b/examples/index-aws.js @@ -0,0 +1,22 @@ +const { IndexFlatL2 } = require('faiss-node'); + +exports.handler = async function(event, context) { + const dimension = 2; + const index = new IndexFlatL2(dimension); + + console.log(index.getDimension()); + console.log(index.isTrained()); + console.log(index.ntotal()); + index.add([1, 0]); + index.add([1, 2]); + index.add([1, 3]); + index.add([1, 1]); + console.log(index.ntotal()); + + const k = 4; + const results = index.search([1, 0], k); + console.log(results.labels); + console.log(results.distances); + + return results; +}; diff --git a/examples/index.js b/examples/index.js index 86c796f..1c85f3e 100644 --- a/examples/index.js +++ b/examples/index.js @@ -1,4 +1,4 @@ -const { IndexFlatL2 } = require('../lib/index'); +const { IndexFlatL2 } = require('faiss-node'); const dimension = 2; const index = new IndexFlatL2(dimension);