graalvm 23.1.0 独立nodejs docker 镜像&简单试用

graaljs docker 镜像

很简单就是下载官方包,集成下,然后进行一些简单的配置

  • Dockerfile
FROM debian:bullseye-backports
LABEL author="rongfengliang"
LABEL email="1141591465@qq.com"
WORKDIR /opt/
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo 'Asia/Shanghai' >/etc/timezone
COPY graalnodejs-23.1.0-linux-amd64/ /opt/nodejs/
ENV PATH=/opt/nodejs/bin:$PATH

参考项目

  • package.json
{
  "name": "graaljs-learning",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "ncc build index.js -o dist"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "fastify": "^4.23.2",
    "hashids": "^2.3.0"
  },
  "devDependencies": {
    "@vercel/ncc": "^0.38.0"
  }
}
  • index.js
const hashids = require('hashids')
 
const myid = new hashids('this is my salt', 10, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
 
const Fastify = require('fastify')
 
const fastify = Fastify()
 
fastify.get('/', async (request, reply) => {
    console.log(myid.encode(1, 2, 3))
    reply.send({ hello: myid.encode(1, 2, 3) })
})
 
fastify.listen({
    port: 3000,
    host: "0.0.0.0",
    backlog: 511
}, (err, address) => {
    if (err) {
        console.error(err)
        process.exit(1)
    }
    console.log(`Server listening at ${address}`)
})
  • 构建
yarn build
  • docker-compose 文件
version: '3'
services:
   app:
     image: dalongrong/graaljs:23.1.0
     command: node --jvm --polyglot  /app/index.js
     ports:
       - "3000:3000"
     volumes:
     - ./dist:/app/
  • 效果

 

说明

docker 镜像我已经push dockerhub了 dalongrong/graaljs:23.1.0 目前来说独立的graaljs 的确会简化node 与jvm 项目的集成,当然从实际测试来说graaljs 暂时还是不如nodejs 项目启动快速,但是对于业务有node 与java 互调用的场景是一个特别好的选择,比基于node-addon 的模式很很多

参考资料

https://github.com/oracle/graaljs/releases/

posted on   荣锋亮  阅读(190)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-09-20 qperf 网络测试工具
2020-09-20 tcprstat 很不错的服务器时延统计工具
2020-09-20 记一次linux 内存异常的处理
2019-09-20 speedscope + node inspect 分析node应用调用
2017-09-20 k8s api server ha 连接配置问题

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示