Skip to content

Commit

Permalink
Merge pull request #14 from tminaorg/bun-rewrite
Browse files Browse the repository at this point in the history
feat: Bun rewrite
  • Loading branch information
aleksasiriski authored Nov 2, 2023
2 parents 9258c8d + e6fe12d commit 0b97935
Show file tree
Hide file tree
Showing 13 changed files with 3,224 additions and 3,350 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/testingci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- run: npm ci
- run: npm run build

- uses: oven-sh/setup-bun@v1
- run: bun run build
85 changes: 40 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.9.0
ARG PORT=8080
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="NodeJS"

# NodeJS app lives here
WORKDIR /app

# Set production environment
# use dumb-init to add graceful shutdown
FROM building5/dumb-init:1.2.1 as init

# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base
WORKDIR /usr/src/app

# use the official Node image until Bun fixes bug for static assets
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM node:20.9.0-slim AS install
WORKDIR /usr/src/app
RUN mkdir -p /temp
COPY package.json package-lock.json /temp/
RUN cd /temp && npm ci

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/node_modules node_modules
COPY . .

# build
ENV NODE_ENV=production
ENV PORT="${PORT}"

# Throw-away build stage to reduce size of final image
FROM base as build

# Install node modules
COPY --link package.json package-lock.json ./
RUN npm ci --include=dev

# Copy application code
COPY --link . .

# Build application
RUN npm run build

# Remove development dependencies
RUN npm prune --production


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Expose port
EXPOSE ${PORT}

# Start the server by default, this can be overwritten at runtime
CMD [ "npm", "run", "start" ]

LABEL org.opencontainers.image.source="https://github.com/tminaorg/prednjica"
RUN bun run build

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=init /dumb-init /usr/local/bin/
COPY --from=prerelease /usr/src/app/node_modules node_modules
COPY --from=prerelease /usr/src/app/build ./
COPY --from=prerelease /usr/src/app/package.json ./

# switch to nonroot user
USER bun
EXPOSE 3000

# run the app
ENTRYPOINT [ "/usr/local/bin/dumb-init", "--" ]
CMD [ "bun", "run", "start" ]
3 changes: 1 addition & 2 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ primary_region = "cdg"
image = "ghcr.io/tminaorg/prednjica:latest"

[env]
PORT = "8080"
PRIVATE_API_URL = "http://zadnjica.internal:3030"
PUBLIC_API_URL = "https://api.brzaguza.rs"

[http_service]
internal_port = 8080
internal_port = 3000
force_https = true
auto_stop_machines = true
auto_start_machines = true
Expand Down
Loading

0 comments on commit 0b97935

Please sign in to comment.