feat(infra): Added way to run custom commands for different services
- new `EXTRA_FILES` docker build args to specify directory to be copied at
/extra
- run `${SERVICE}/entrypoint.sh` as docker entry point
- added src/empty folder to so if EXTRA_FILES isn't set => use empty
folder (since no conditional COPY)
This commit is contained in:
parent
1ebe0868f5
commit
a2b896916e
6 changed files with 35 additions and 10 deletions
|
|
@ -19,19 +19,20 @@ services:
|
|||
volumes:
|
||||
# if you need to share files with nginx, you do it here.
|
||||
- images-volume:/volumes/icons
|
||||
# - static-volume:/volumes/static
|
||||
environment:
|
||||
# this can stay the same for developpement. This is an alias to `localhost`
|
||||
- NGINX_DOMAIN=local.maix.me
|
||||
|
||||
# an example of an micro service. this one basically only does this:
|
||||
# - handle uploading of icons
|
||||
# - write icons to shared volume allowing nginx to serve them (does it better than if we did it in the service)
|
||||
###############
|
||||
# ICONS #
|
||||
###############
|
||||
icons:
|
||||
# build is a bit strange: it has two parts
|
||||
build:
|
||||
build:
|
||||
context: ./src/
|
||||
args:
|
||||
- SERVICE=icons
|
||||
#- EXTRA_FILES=icons/extra
|
||||
container_name: icons
|
||||
restart: always
|
||||
networks:
|
||||
|
|
@ -42,6 +43,9 @@ services:
|
|||
environment:
|
||||
- USER_ICONS_STORE=/store
|
||||
- DATABASE_DIR=/database
|
||||
|
||||
|
||||
volumes:
|
||||
images-volume:
|
||||
sqlite-volume:
|
||||
static-volume:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
**/node_modules
|
||||
**/dist
|
||||
@shared/src/database/init.sql.ts
|
||||
**/Dockerfile
|
||||
.gitkeep
|
||||
.dockerignore
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
FROM guergeiro/pnpm:22-10-alpine as builder
|
||||
FROM node:22-alpine as pnpm_base
|
||||
RUN npm install --global pnpm@10.14.0;
|
||||
|
||||
FROM pnpm_base as builder
|
||||
|
||||
ARG SERVICE
|
||||
|
||||
|
|
@ -6,6 +9,7 @@ WORKDIR /build
|
|||
COPY @shared/package.json /build/@shared/
|
||||
COPY ${SERVICE}/package.json /build/service/
|
||||
COPY tsconfig.base.json pnpm-workspace.yaml package.json /build/
|
||||
COPY ${SERVICE}/entrypoint.sh /build/
|
||||
|
||||
RUN pnpm install;
|
||||
|
||||
|
|
@ -19,15 +23,21 @@ RUN cd /build/service && \
|
|||
cp /build/@shared/package.json /dist/@shared/ && \
|
||||
cp /build/service/package.json /dist/service/ && \
|
||||
cp /build/package.json /dist/ && \
|
||||
cp /build/pnpm-lock.yaml /dist/;
|
||||
cp /build/pnpm-lock.yaml /dist/ && \
|
||||
cp /build/entrypoint.sh /dist/ && \
|
||||
chmod +x /dist/entrypoint.sh;
|
||||
|
||||
|
||||
FROM guergeiro/pnpm:22-10-alpine
|
||||
FROM pnpm_base
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
ARG EXTRA_FILES=empty
|
||||
COPY --from=builder /dist /src
|
||||
|
||||
RUN pnpm install --prod --frozen-lockfile;
|
||||
COPY ${EXTRA_FILES} /extra
|
||||
RUN echo "${EXTRA_FILES}";
|
||||
ENTRYPOINT [ "/src/entrypoint.sh" ]
|
||||
|
||||
CMD ["node", "/src/run.cjs"]
|
||||
|
||||
|
|
|
|||
0
src/empty/.gitkeep
Normal file
0
src/empty/.gitkeep
Normal file
10
src/icons/entrypoint.sh
Normal file
10
src/icons/entrypoint.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
# do anything here
|
||||
|
||||
cp -r /extra /files
|
||||
|
||||
# run the CMD [ ... ] from the dockerfile
|
||||
exec "$@"
|
||||
0
src/icons/extra/.gitkeep
Normal file
0
src/icons/extra/.gitkeep
Normal file
Loading…
Add table
Add a link
Reference in a new issue