Skip to content

Commit 4c6a5a5

Browse files
authored
fix: resolve issues with docker deployment process (#56)
* refractor: update dockerfile * chore(deps): add trusted dependencies * refractor: remove unused target * refractor: optimize dockerfile syntax * fix: replace copy command to prerelease * refractor: switch start argument positions * refractor: remove explicit generate command * fix: downgrade prisma to version 5.12.1 * refractor: bump prisma back to 5.13.0 * fix: revert changes in #53 * fix: revert previous commit
1 parent 1877620 commit 4c6a5a5

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

Dockerfile

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# use the official Bun image
2-
# see all versions at https://hub.docker.com/r/oven/bun/tags
1+
# use the official bun image
32
FROM oven/bun:latest as base
43
WORKDIR /usr/src/app
54

6-
# Set environment variables
5+
# set environment variables
76
ENV RATE_LIMIT="200"
87
ENV DATABASE_URL="file:./database/data.db"
98
ENV HISTORY_API_URL="https://helldivers-b.omnedia.com/api"
@@ -20,8 +19,6 @@ RUN cd /temp/dev && bun install --frozen-lockfile
2019
# install with --production (exclude devDependencies)
2120
RUN mkdir -p /temp/prod
2221
COPY package.json bun.lockb /temp/prod/
23-
24-
# install production dependencies
2522
RUN cd /temp/prod && bun install --frozen-lockfile --production
2623

2724
# copy node_modules from temp directory
@@ -30,36 +27,31 @@ FROM base AS prerelease
3027
COPY --from=install /temp/dev/node_modules node_modules
3128
COPY . .
3229

33-
# copy production dependencies and source code into final image
34-
FROM base AS release
35-
COPY --from=install /temp/prod/node_modules node_modules
36-
COPY --from=prerelease /usr/src/app/package.json .
37-
COPY --from=prerelease /usr/src/app .
38-
39-
# set the environment to production
40-
ENV NODE_ENV=production
41-
42-
# create the database
30+
# synchronize the database schema & generate client
4331
RUN bunx prisma migrate deploy
44-
RUN bunx prisma db push --skip-generate
32+
RUN bunx prisma db push
4533

46-
# create primsa client
47-
RUN bunx prisma generate
34+
# generate source data for the api
35+
RUN bun run generate
4836

49-
# build the app
50-
RUN bun run output
37+
# test generated source data
38+
RUN bun test
5139

52-
# upload source maps to sentry
53-
ARG SOURCE_MAP_TOKEN
54-
ENV SENTRY_AUTH_TOKEN=${SOURCE_MAP_TOKEN}
55-
# install ca-certificates if not running in GitHub action runner
56-
RUN if [ -z "${SOURCE_MAP_TOKEN}" ]; then echo "CA certificate install not required"; else apt-get -y update && apt-get -y install ca-certificates; fi
57-
RUN if [ -z "${SOURCE_MAP_TOKEN}" ]; then echo "Sourcemap upload not executed. GitHub action runner detected."; else bun run sentry:sourcemaps; fi
40+
# copy production dependencies and source code into final image
41+
FROM base AS release
42+
COPY --from=prerelease /usr/src/app/src src
43+
COPY --from=prerelease /usr/src/app/prisma prisma
44+
COPY --from=prerelease /usr/src/app/node_modules node_modules
45+
COPY --from=prerelease /usr/src/app/package.json package.json
46+
COPY --from=prerelease /usr/src/app/tsconfig.json tsconfig.json
5847

59-
# create a non-root use
60-
RUN chmod a+rw prisma/database prisma/database/*
48+
# src directory permissions
49+
RUN chown -R bun:bun /usr/src/app
50+
51+
# set production environment
52+
ENV NODE_ENV=production
6153

6254
# run the app
6355
USER bun
6456
EXPOSE 3000/tcp
65-
ENTRYPOINT ["bun", "--smol", "run", "build/index.js"]
57+
ENTRYPOINT ["bun", "run", "--smol", "src/index.ts"]

bun.lockb

2.45 KB
Binary file not shown.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"build"
1919
],
2020
"scripts": {
21-
"postinstall": "bunx prisma generate --schema=./prisma/schema.prisma",
2221
"lint": "eslint . --ext .ts",
2322
"format": "prettier --write .",
2423
"output": "bun run scripts/build.ts",
@@ -47,13 +46,20 @@
4746
},
4847
"dependencies": {
4948
"@hono/sentry": "^1.0.1",
50-
"@prisma/client": "^5.12.1",
49+
"@prisma/client": "^5.13.0",
5150
"@sentry/bun": "^7.110.1",
5251
"@sentry/cli": "^2.31.0",
5352
"chalk": "^5.3.0",
5453
"croner": "^8.0.2",
5554
"hono": "^4.1.0",
5655
"node-cache": "^5.1.2",
56+
"prisma": "^5.13.0",
5757
"qs": "^6.12.0"
58-
}
58+
},
59+
"trustedDependencies": [
60+
"@prisma/client",
61+
"@prisma/engines",
62+
"@sentry/cli",
63+
"prisma"
64+
]
5965
}

prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
generator client {
55
provider = "prisma-client-js"
6-
binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x"]
6+
binaryTargets = ["native", "debian-openssl-3.0.x"]
77
}
88

99
datasource db {

0 commit comments

Comments
 (0)