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 all commits
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
61 changes: 45 additions & 16 deletions apps/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
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
# install
FROM oven/bun@sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513 AS install
WORKDIR /app/
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

RUN \
--mount=type=bind,target=package.json,source=package.json \
--mount=type=bind,target=apps/server/package.json,source=apps/server/package.json \
--mount=type=bind,target=packages/analytics/package.json,source=packages/analytics/package.json \
--mount=type=bind,target=packages/db/package.json,source=packages/db/package.json \
--mount=type=bind,target=packages/emails/package.json,source=packages/emails/package.json \
--mount=type=bind,target=packages/error/package.json,source=packages/error/package.json \
--mount=type=bind,target=packages/notifications/discord/package.json,source=packages/notifications/discord/package.json \
--mount=type=bind,target=packages/notifications/email/package.json,source=packages/notifications/email/package.json \
--mount=type=bind,target=packages/notifications/pagerduty/package.json,source=packages/notifications/pagerduty/package.json \
--mount=type=bind,target=packages/notifications/slack/package.json,source=packages/notifications/slack/package.json \
--mount=type=bind,target=packages/notifications/twillio-sms/package.json,source=packages/notifications/twillio-sms/package.json \
--mount=type=bind,target=packages/tinybird/package.json,source=packages/tinybird/package.json \
--mount=type=bind,target=packages/tracker/package.json,source=packages/tracker/package.json \
--mount=type=bind,target=packages/upstash/package.json,source=packages/upstash/package.json \
--mount=type=bind,target=packages/utils/package.json,source=packages/utils/package.json \
--mount=type=bind,target=packages/tsconfig/package.json,source=packages/tsconfig/package.json \
--mount=type=bind,target=packages/assertions/package.json,source=packages/assertions/package.json \
--mount=type=cache,target=/root/.bun/install/cache,sharing=locked \
bun install --production --ignore-scripts --frozen-lockfile --verbose

# 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
# build
FROM oven/bun@sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513 AS build
WORKDIR /app/apps/server

# Compile the TypeScript application
COPY \
--link \
"." "/app/"
COPY \
--from=install \
--link \
"/app/node_modules" "/app/node_modules"
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"]
9 changes: 9 additions & 0 deletions apps/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ flyctl deploy --config apps/server/fly.toml --dockerfile apps/server/Dockerfile

## Docker

The Dockerfile is generated thanks to [Dofigen](https://github.com/lenra-io/dofigen). To generate the Dockerfile, run the following command from the `apps/server` directory:

```bash
# Update the dependent image versions
dofigen update
# Generate the Dockerfile
dofigen gen
```

Build the docker image locally

```bash
Expand Down
95 changes: 95 additions & 0 deletions apps/server/dofigen.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
effective: |
ignore:
- node_modules
- /apps/docs
- /apps/screenshot-service
- /apps/web
- /packages/api
- /packages/integrations/vercel
builders:
build:
fromImage:
path: oven/bun
digest: sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513
workdir: /app/apps/server
copy:
- paths:
- .
target: /app/
- fromBuilder: install
paths:
- /app/node_modules
target: /app/node_modules
run:
- bun build --compile --sourcemap src/index.ts --outfile=app
install:
fromImage:
path: oven/bun
digest: sha256:eb409bed239c3adff079a6b71283f151e802d66b99f643ba7a71e1be7d3da513
workdir: /app/
run:
- bun install --production --ignore-scripts --frozen-lockfile --verbose
cache:
- target: /root/.bun/install/cache
bind:
- target: package.json
source: package.json
- target: apps/server/package.json
source: apps/server/package.json
- target: packages/analytics/package.json
source: packages/analytics/package.json
- target: packages/db/package.json
source: packages/db/package.json
- target: packages/emails/package.json
source: packages/emails/package.json
- target: packages/error/package.json
source: packages/error/package.json
- target: packages/notifications/discord/package.json
source: packages/notifications/discord/package.json
- target: packages/notifications/email/package.json
source: packages/notifications/email/package.json
- target: packages/notifications/pagerduty/package.json
source: packages/notifications/pagerduty/package.json
- target: packages/notifications/slack/package.json
source: packages/notifications/slack/package.json
- target: packages/notifications/twillio-sms/package.json
source: packages/notifications/twillio-sms/package.json
- target: packages/tinybird/package.json
source: packages/tinybird/package.json
- target: packages/tracker/package.json
source: packages/tracker/package.json
- target: packages/upstash/package.json
source: packages/upstash/package.json
- target: packages/utils/package.json
source: packages/utils/package.json
- target: packages/tsconfig/package.json
source: packages/tsconfig/package.json
- target: packages/assertions/package.json
source: packages/assertions/package.json
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: adf3f9674023b48f97b9d48996067d36db5da23a2ee73685c1d85079e1328320
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/\n # Copy project\n bind:\n - package.json\n - apps/server/package.json\n - packages/analytics/package.json\n - packages/db/package.json\n - packages/emails/package.json\n - packages/error/package.json\n - packages/notifications/discord/package.json\n - packages/notifications/email/package.json\n - packages/notifications/pagerduty/package.json\n - packages/notifications/slack/package.json\n - packages/notifications/twillio-sms/package.json\n - packages/tinybird/package.json\n - packages/tracker/package.json\n - packages/upstash/package.json\n - packages/utils/package.json\n - packages/tsconfig/package.json\n - packages/assertions/package.json\n # Install dependencies\n run: bun install --production --ignore-scripts --frozen-lockfile --verbose\n cache:\n - /root/.bun/install/cache\n build:\n fromImage: oven/bun\n workdir: /app/apps/server\n copy: \n - . /app/\n - fromBuilder: install\n source: /app/node_modules\n target: /app/node_modules\n # Compile the TypeScript application\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"
52 changes: 52 additions & 0 deletions apps/server/dofigen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ignore:
- node_modules
- /apps/docs
- /apps/screenshot-service
- /apps/web
- /packages/api
- /packages/integrations/vercel
builders:
install:
fromImage: oven/bun
workdir: /app/
# Copy project
bind:
- package.json
Copy link
Member

Choose a reason for hiding this comment

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

I m ashamed by that part our monorepo is 😱

- apps/server/package.json
- packages/analytics/package.json
- packages/db/package.json
- packages/emails/package.json
- packages/error/package.json
- packages/notifications/discord/package.json
- packages/notifications/email/package.json
- packages/notifications/pagerduty/package.json
- packages/notifications/slack/package.json
- packages/notifications/twillio-sms/package.json
- packages/tinybird/package.json
- packages/tracker/package.json
- packages/upstash/package.json
- packages/utils/package.json
- packages/tsconfig/package.json
- packages/assertions/package.json
# Install dependencies
run: bun install --production --ignore-scripts --frozen-lockfile --verbose
cache:
- /root/.bun/install/cache
build:
fromImage: oven/bun
workdir: /app/apps/server
copy:
- . /app/
- fromBuilder: install
source: /app/node_modules
target: /app/node_modules
# Compile the TypeScript application
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
5 changes: 3 additions & 2 deletions packages/assertions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "",
"main": "src/index.ts",
"scripts": {},
"dependencies": {},
"dependencies": {
"jsonpath-plus": "7.2.0"
},
"devDependencies": {
"@openstatus/tsconfig": "workspace:*",
"jsonpath-plus": "7.2.0",
"typescript": "5.5.2",
"zod": "3.23.8"
},
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading