From 615f28bf370a6dbc897d886c3d86442baad3f32d Mon Sep 17 00:00:00 2001 From: raczu Date: Wed, 3 Apr 2024 00:25:51 +0200 Subject: [PATCH] ci: contenerized web and mobile Mobile contenerization requires to specify your computer IP address to make it possible to use expo go. --- .env.sample | 8 ++++++++ Client/.dockerignore | 34 +++++++++++++++++++++++++++++++++ Client/mobile.Dockerfile | 22 +++++++++++++++++++++ Client/web.Dockerfile | 22 +++++++++++++++++++++ compose.override.yml | 41 ++++++++++++++++++++++++++++++++++++++-- compose.yml | 23 ++++++++++++++++++++-- 6 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 Client/.dockerignore create mode 100644 Client/mobile.Dockerfile create mode 100644 Client/web.Dockerfile diff --git a/.env.sample b/.env.sample index 065303c6..798cef0d 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,11 @@ +# MOBILE +MOBILE_LISTEN_PORT=5274 +RCT_METRO_PORT=5274 +REACT_NATIVE_PACKAGER_HOSTNAME=YOUR_IP_ADDRESS + +# WEB +WEB_LISTEN_PORT=5273 + # SERVER ASPNETCORE_ENVIRONMENT=Development diff --git a/Client/.dockerignore b/Client/.dockerignore new file mode 100644 index 00000000..fd00eaa9 --- /dev/null +++ b/Client/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/build +**/dist +LICENSE +README.md diff --git a/Client/mobile.Dockerfile b/Client/mobile.Dockerfile new file mode 100644 index 00000000..4870b5db --- /dev/null +++ b/Client/mobile.Dockerfile @@ -0,0 +1,22 @@ +FROM node:21.7.1-alpine as base + +FROM base as prunner +RUN apk add --no-cache libc6-compat +copy reasn-client /source +WORKDIR /source +RUN yarn set version 4.1.0 \ + && yarn dlx turbo prune native --docker + +FROM base AS installer +RUN apk add --no-cache libc6-compat +WORKDIR /source +COPY --from=prunner /source/out/json/ . +COPY --from=prunner /source/out/yarn.lock ./yarn.lock +RUN --mount=type=cache,target=.yarn/cache \ + yarn install --immutable +COPY --from=prunner /source/out/full . + +FROM installer AS development +ARG NODE_ENV=development +ENV NODE_ENV=${NODE_ENV} +CMD ["yarn", "run", "dev:mobile"] diff --git a/Client/web.Dockerfile b/Client/web.Dockerfile new file mode 100644 index 00000000..f8177659 --- /dev/null +++ b/Client/web.Dockerfile @@ -0,0 +1,22 @@ +FROM node:21.7.1-alpine as base + +FROM base as prunner +RUN apk add --no-cache libc6-compat +copy reasn-client /source +WORKDIR /source +RUN yarn set version 4.1.0 \ + && yarn dlx turbo prune web --docker + +FROM base AS installer +RUN apk add --no-cache libc6-compat +WORKDIR /source +COPY --from=prunner /source/out/json/ . +COPY --from=prunner /source/out/yarn.lock ./yarn.lock +RUN --mount=type=cache,target=.yarn/cache \ + yarn install --immutable +COPY --from=prunner /source/out/full . + +FROM installer AS development +ARG NODE_ENV=development +ENV NODE_ENV=${NODE_ENV} +CMD ["yarn", "run", "dev:web"] diff --git a/compose.override.yml b/compose.override.yml index 17989357..78ce04ea 100644 --- a/compose.override.yml +++ b/compose.override.yml @@ -1,4 +1,43 @@ services: + mobile: + build: + context: Client + dockerfile: mobile.Dockerfile + target: development + restart: unless-stopped + networks: + - reasn-network + ports: + - "${MOBILE_LISTEN_PORT:-8081}:${MOBILE_LISTEN_PORT:-8081}" + env_file: + - .env + depends_on: + - server + develop: + watch: + - action: rebuild + path: ./Client/reasn-client/yarn.lock + - action: sync + path: ./Client/reasn-client/apps/native + target: /source/apps/native + - action: sync + path: ./Client/reasn-client/packages + target: /source/packages + + web: + build: + target: development + develop: + watch: + - action: rebuild + path: ./Client/reasn-client/yarn.lock + - action: sync + path: ./Client/reasn-client/apps/web + target: /source/apps/web + - action: sync + path: ./Client/reasn-client/packages + target: /source/packages + server: build: target: development @@ -8,8 +47,6 @@ services: path: ./Server/ReasnAPI/ReasnAPI postgres: - expose: - - 5432 volumes: - ./Database/init-dev-data.sql:/docker-entrypoint-initdb.d/03-init-dev-data.sql \ No newline at end of file diff --git a/compose.yml b/compose.yml index c8eb3e17..eddc114c 100644 --- a/compose.yml +++ b/compose.yml @@ -1,10 +1,26 @@ services: + web: + build: + context: Client + dockerfile: web.Dockerfile + restart: unless-stopped + networks: + - reasn-network + ports: + - "${WEB_LISTEN_PORT:-5273}:3000" + env_file: + - .env + depends_on: + - server + server: build: context: Server dockerfile: server.Dockerfile target: production + restart: unless-stopped networks: + - reasn-isolated-network - reasn-network ports: - "${SERVER_LISTEN_PORT:-5272}:8080" @@ -18,7 +34,7 @@ services: image: postgres:16 restart: unless-stopped networks: - - reasn-network + - reasn-isolated-network volumes: - postgres-data:/var/lib/postgresql/data - ./Database/init-db.sql:/docker-entrypoint-initdb.d/01-init-db.sql @@ -34,8 +50,9 @@ services: pgadmin: image: dpage/pgadmin4:8.0 + restart: unless-stopped networks: - - reasn-network + - reasn-isolated-network ports: - "${PGADMIN_LISTEN_PORT:-5050}:${PGADMIN_LISTEN_PORT:-80}" volumes: @@ -47,6 +64,8 @@ services: condition: service_healthy networks: + reasn-isolated-network: + driver: bridge reasn-network: driver: bridge