Skip to content

Commit

Permalink
feat: add dockerize for node (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeherysh authored Apr 30, 2024
1 parent 44c519d commit d384781
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,62 @@ jobs:
readme-filepath: ./DOCKERHUB.md
short-description: ${{ github.event.repository.description }}
enable-url-completion: true

publish-docker-node:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install --production

- name: Build package
run: bun run compile:node

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

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository }}
flavor: |
suffix=-node,onlatest=true
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-node-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-node-
- name: Publish to DockerHub
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.node
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
28 changes: 28 additions & 0 deletions Dockerfile.node
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:lts-slim
WORKDIR /usr/src/app

# setup labels
LABEL repository="https://github.com/kitabisa/smockr"
LABEL maintainer="adeherysh"

# setup arg
ARG SECRET_KEY
ARG ALLOWED_ORIGIN
ARG ALLOWED_METHODS
ARG ALLOWED_HEADERS

# setup env
ENV NODE_ENV=production
ENV PORT=8080
ENV SECRET_KEY=$SECRET_KEY
ENV ALLOWED_ORIGIN=$ALLOWED_ORIGIN
ENV ALLOWED_METHODS=$ALLOWED_METHODS
ENV ALLOWED_HEADERS=$ALLOWED_HEADERS

# copy binary
COPY ./bin /usr/src/app/

# run the app
USER node
EXPOSE 8080/tcp
ENTRYPOINT [ "node", "--max-http-header-size=100000", "server.mjs" ]
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"prepare": "husky || true",
"precompile": "rimraf ./bin ./dist",
"compile": "bun build ./server.ts --outdir ./bin --target bun --format esm --minify",
"precompile:node": "rimraf ./bin ./dist",
"compile:node": "bun build ./server.ts --outdir ./bin --target node --entry-naming [dir]/[name].mjs --format esm --minify",
"predev": "bun run compile",
"dev": "cd commands && opaline dev",
"prebuild": "NODE_ENV=production bun run compile",
Expand Down
1 change: 1 addition & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ app.all('*', (req: Request, res: Response) => {

app.listen(port, () => {
console.log(` \x1b[33m▲ ${pkg.name} ${pkg.version}\x1b[0m`)
console.log(` - Runtime: ${process.versions.bun ? 'bun' : 'node'}`)
console.log(` - Network: http://localhost:${port}`)
console.log(` - Local: http://0.0.0.0:${port}`)
console.log(` - Params: --port ${port}`)
Expand Down

0 comments on commit d384781

Please sign in to comment.