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:
|
volumes:
|
||||||
# if you need to share files with nginx, you do it here.
|
# if you need to share files with nginx, you do it here.
|
||||||
- images-volume:/volumes/icons
|
- images-volume:/volumes/icons
|
||||||
|
# - static-volume:/volumes/static
|
||||||
environment:
|
environment:
|
||||||
# this can stay the same for developpement. This is an alias to `localhost`
|
# this can stay the same for developpement. This is an alias to `localhost`
|
||||||
- NGINX_DOMAIN=local.maix.me
|
- NGINX_DOMAIN=local.maix.me
|
||||||
|
|
||||||
# an example of an micro service. this one basically only does this:
|
###############
|
||||||
# - handle uploading of icons
|
# 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/
|
context: ./src/
|
||||||
args:
|
args:
|
||||||
- SERVICE=icons
|
- SERVICE=icons
|
||||||
|
#- EXTRA_FILES=icons/extra
|
||||||
container_name: icons
|
container_name: icons
|
||||||
restart: always
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
|
|
@ -42,6 +43,9 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- USER_ICONS_STORE=/store
|
- USER_ICONS_STORE=/store
|
||||||
- DATABASE_DIR=/database
|
- DATABASE_DIR=/database
|
||||||
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
images-volume:
|
images-volume:
|
||||||
sqlite-volume:
|
sqlite-volume:
|
||||||
|
static-volume:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
**/node_modules
|
**/node_modules
|
||||||
**/dist
|
**/dist
|
||||||
@shared/src/database/init.sql.ts
|
|
||||||
**/Dockerfile
|
**/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
|
ARG SERVICE
|
||||||
|
|
||||||
|
|
@ -6,6 +9,7 @@ WORKDIR /build
|
||||||
COPY @shared/package.json /build/@shared/
|
COPY @shared/package.json /build/@shared/
|
||||||
COPY ${SERVICE}/package.json /build/service/
|
COPY ${SERVICE}/package.json /build/service/
|
||||||
COPY tsconfig.base.json pnpm-workspace.yaml package.json /build/
|
COPY tsconfig.base.json pnpm-workspace.yaml package.json /build/
|
||||||
|
COPY ${SERVICE}/entrypoint.sh /build/
|
||||||
|
|
||||||
RUN pnpm install;
|
RUN pnpm install;
|
||||||
|
|
||||||
|
|
@ -19,15 +23,21 @@ RUN cd /build/service && \
|
||||||
cp /build/@shared/package.json /dist/@shared/ && \
|
cp /build/@shared/package.json /dist/@shared/ && \
|
||||||
cp /build/service/package.json /dist/service/ && \
|
cp /build/service/package.json /dist/service/ && \
|
||||||
cp /build/package.json /dist/ && \
|
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
|
WORKDIR /src
|
||||||
|
|
||||||
|
ARG EXTRA_FILES=empty
|
||||||
COPY --from=builder /dist /src
|
COPY --from=builder /dist /src
|
||||||
|
|
||||||
RUN pnpm install --prod --frozen-lockfile;
|
RUN pnpm install --prod --frozen-lockfile;
|
||||||
|
COPY ${EXTRA_FILES} /extra
|
||||||
|
RUN echo "${EXTRA_FILES}";
|
||||||
|
ENTRYPOINT [ "/src/entrypoint.sh" ]
|
||||||
|
|
||||||
CMD ["node", "/src/run.cjs"]
|
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