From 7454aa6569574409ca44b7a5fa50b48b7d103fd2 Mon Sep 17 00:00:00 2001 From: "Ricardo (XenGi) Band" Date: Wed, 18 Oct 2023 15:39:37 +0200 Subject: [PATCH] add docker build --- .dockerignore | 11 +++++++++++ Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ bun.lockb | Bin 1677 -> 2743 bytes package.json | 7 ++++++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c5fb1ef --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules +Dockerfile +.dockerignore +.git +.gitignore +README.md +LICENSE +.editorconfig +.idea +coverage* + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7693d73 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# use the official Bun image +# see all versions at https://hub.docker.com/r/oven/bun/tags +FROM docker.io/oven/bun:1 as base +WORKDIR /usr/src/app + +# install dependencies into temp directory +# this will cache them and speed up future builds +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lockb /temp/dev/ +RUN cd /temp/dev && bun install --frozen-lockfile + +# install with --production (exclude devDependencies) +RUN mkdir -p /temp/prod +COPY package.json bun.lockb /temp/prod/ +RUN cd /temp/prod && bun install --frozen-lockfile --production + +# copy node_modules from temp directory +# then copy all (non-ignored) project files into the image +FROM install AS prerelease +COPY --from=install /temp/dev/node_modules node_modules +COPY . . + +# [optional] tests & build +ENV NODE_ENV=production +RUN bun test +RUN bun run build + +# copy production dependencies and source code into final image +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY --from=prerelease /usr/src/app/index.ts . +COPY --from=prerelease /usr/src/app/package.json . + +# run the app +USER bun +EXPOSE 8000/tcp +EXPOSE 8080/tcp +ENTRYPOINT [ "bun", "run", "index.ts" ] + diff --git a/bun.lockb b/bun.lockb index 866b4804cd0a78d684ee3a6d2da87ab388b62ad2..0b96ba4ffbeabf03d5d2803c8bf63807d2fbe605 100755 GIT binary patch delta 968 zcmeC>-7Y#oPcv>$%n2q1sTnNZC(l+df9LsK$^VV@D}(6M$LEG7c6YR?b1{Gc+r)7B zs5~|Zhk>CuF)uS2$SF!qOfCV^Za~b#z|gP=NOJ;dkS-7nq!@tg2Cm7nY<<_1B_=$- zaZhr>kts~q3mc|88fm{+(Zzr58e74{1u>k)Ky^Yu^-L2tYES&Y!5ai*I{?KPfiw$5 zjB_=RZ3Pqq^7Vmg7@to3Y0sq1IN6HPDwG*02f|?WP?{A;g8(`W5+h3e73z_fg_09)xT)ApqnqP-uUEO0%#}zQ?R3#sm}sIhzHD4cLJM5V(M(l;l9F zLBgPTgDIu!&t%hZwFMFJlA9^)({o2 z8}xPc!L+WSg`Sa~fnG^^RZf0>ajI@=URh>Z<>Z~L(ssxKK=sI6T|+$+h^{zeAZ?&f oQ=UEx$y!WSlNA_Q6q%sPU^IveV#D}MlXo(e zOg3flo?OAqJGqx7d$I}Za;^hV)2}d3u3)oKgqrd1KLo(cU|@kraIj21$EL+)0p&V? zxN1Tm8yJDO04ltMWwIZ;*5n#?1FjEHAp_RQEF4agJva>1eSs=@7#JE_EKJWZR`C5x dfO_^Tl;*N2wXjn#oSeWeIe7<%-sBye{{a`dN8kVe diff --git a/package.json b/package.json index 8d9ff67..e42eb85 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,17 @@ "scripts": { "start": "bun run server.ts", "init": "mkdir -p /tmp/sanic/{music,playlists}; touch /tmp/sanic/mpd_db", - "mpd": "mpd --no-daemon ./mpd.conf" + "mpd": "mpd --no-daemon ./mpd.conf", + "docker-build": "docker build --pull -t sanic .", + "docker-run": "docker run -it --rm -p 8000:8000 -p 8080:8080 sanic" }, "devDependencies": { "bun-types": "latest" }, "peerDependencies": { "typescript": "^5.0.0" + }, + "dependencies": { + "react": "^18.2.0" } }