Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Manage Dockerfile with Dofigen #1014

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file is generated by Dofigen v2.0.0
# See https://github.com/lenra-io/dofigen

node_modules
/apps/docs
/apps/screenshot-service
/apps/web
/packages/api
/packages/integrations/vercel
41 changes: 25 additions & 16 deletions apps/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
FROM oven/bun
# syntax=docker/dockerfile:1.7
# This file is generated by Dofigen v2.0.0
# See https://github.com/lenra-io/dofigen

WORKDIR /app

# Copy project
COPY . .

# To keep the image small ;)
RUN rm -rf /app/apps/docs
RUN rm -rf /app/apps/screenshot-service
RUN rm -rf /app/apps/web
RUN rm -rf /app/packages/api
RUN rm -rf /app/packages/integrations/vercel
# Temp solution for bun
RUN bun install --ignore-scripts
# install
FROM oven/bun@sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513 AS install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taorepoara do we really need the hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hash gives you the control on the FROM images. Dofigen does it by default, but I'll add a flag to avoid that: lenra-io/dofigen#278

WORKDIR /app/apps/server
COPY \
--link \
"." "/app/"
USER 0:0
RUN \
--mount=type=cache,target=/root/.bun/install/cache,uid=0,gid=0,sharing=locked \
bun install --ignore-scripts --frozen-lockfile

# Compile the TypeScript application
# build
FROM install AS build
USER 0:0
RUN bun build --compile --sourcemap src/index.ts --outfile=app

# runtime
FROM debian@sha256:00558f781b91e90469812bad32002f311ab26ef241b4a1996f6600680ec82f5c AS runtime
COPY \
--from=build \
--chown=1000:1000 \
--chmod=555 \
--link \
"/app/apps/server/app" "/bin/"
USER 1000:1000
EXPOSE 3000
CMD ["./app"]
ENTRYPOINT ["/bin/app"]
55 changes: 55 additions & 0 deletions apps/server/dofigen.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
effective: |
ignore:
- node_modules
- /apps/docs
- /apps/screenshot-service
- /apps/web
- /packages/api
- /packages/integrations/vercel
builders:
install:
fromImage:
path: oven/bun
digest: sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513
workdir: /app/apps/server
copy:
- paths:
- .
target: /app/
root:
run:
- bun install --ignore-scripts --frozen-lockfile
cache:
- target: /root/.bun/install/cache
build:
fromBuilder: install
root:
run:
- bun build --compile --sourcemap src/index.ts --outfile=app
fromImage:
path: debian
digest: sha256:00558f781b91e90469812bad32002f311ab26ef241b4a1996f6600680ec82f5c
copy:
- fromBuilder: build
paths:
- /app/apps/server/app
target: /bin/
chmod: '555'
entrypoint:
- /bin/app
expose:
- port: 3000
images:
registry.hub.docker.com:443:
oven:
bun:
latest:
digest: sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513
library:
debian:
bullseye-slim:
digest: sha256:00558f781b91e90469812bad32002f311ab26ef241b4a1996f6600680ec82f5c
resources:
dofigen.yml:
hash: de7b73f37730fb3b9b2b7904c05d04cce840149ad25c0d7354c233b3b2782a10
content: "ignore:\n - node_modules\n - /apps/docs\n - /apps/screenshot-service\n - /apps/web\n - /packages/api\n - /packages/integrations/vercel\nbuilders:\n install:\n fromImage: oven/bun\n workdir: /app/apps/server\n # Copy project\n copy: . /app/\n # Install dependencies\n root:\n run: \n - bun install --ignore-scripts --frozen-lockfile\n cache:\n - /root/.bun/install/cache\n build:\n fromBuilder: install\n # Compile the TypeScript application\n root:\n run: bun build --compile --sourcemap src/index.ts --outfile=app\nfromImage: debian:bullseye-slim\ncopy:\n - fromBuilder: build\n source: /app/apps/server/app\n target: /bin/\n chmod: \"555\"\nexpose: 3000\nentrypoint: /bin/app\n"
32 changes: 32 additions & 0 deletions apps/server/dofigen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ignore:
- node_modules
- /apps/docs
- /apps/screenshot-service
- /apps/web
- /packages/api
- /packages/integrations/vercel
builders:
install:
fromImage: oven/bun
workdir: /app/apps/server
# Copy project
copy: . /app/
# Install dependencies
root:
run:
- bun install --ignore-scripts --frozen-lockfile
cache:
- /root/.bun/install/cache
build:
fromBuilder: install
# Compile the TypeScript application
root:
run: bun build --compile --sourcemap src/index.ts --outfile=app
fromImage: debian:bullseye-slim
copy:
- fromBuilder: build
source: /app/apps/server/app
target: /bin/
chmod: "555"
expose: 3000
entrypoint: /bin/app