Best approach to setup mono repo using Docker

MayoMayn

BestDev
Oct 18, 2016
1,423
683
So currently I have a mono repository that consists of the structure:
Code:
+-- project
|   +-- client
|       +-- assets
|       +-- src
|           +-- ...
|       +-- package.json
|       +-- angular.json
|       +-- tsconfig.json
|       +-- Dockerfile
|       +-- ...
|   +-- server
|       +-- database
|           +-- ...
|       +-- src
|           +-- ...
|       +-- package.json
|       +-- .graphqlconfig.yml
|       +-- tsconfig.json
|       +-- tsconfig.build.json
|       +-- Dockerfile
|       +-- ...
+-- yarn.lock
+-- package.json
+-- lerna.json
+-- tsconfig.json
+-- tsconfig.base.json
+-- docker-compose.yml

And the problem is, that the docker-compose services commands can't figure out the workdirs of the images, so it tries to run the script commands in the root directory of the project.
Tried to do switch out the bash command with ls and it was still in the root directory of the project.

project/server/Dockerfile
Code:
FROM node:alpine

ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/app/server

COPY ./package.json .
# COPY ../../yarn.lock .
RUN yarn

COPY . .

EXPOSE 4242

project/client/Dockerfile
Code:
FROM node:alpine

ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/app/client

COPY ./package.json .
# COPY ../../yarn.lock .
RUN yarn

COPY . .

EXPOSE 8080


docker-compose.yml
Code:
version: '3'
volumes:
  postgres:
services:
  prisma:
    image: prismagraphql/prisma:1.16
    restart: always
    ports:
      - '4466:4466'
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: postgres
            host: postgres
            port: 5432
            user: prisma
            password: prisma
            migrations: true
  postgres:
    image: postgres:10.5
    restart: always
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
  client:
    container_name: emerald-client
    command: yarn start
    restart: unless-stopped
    image: client
    build:
      context: ./project/client
      dockerfile: Dockerfile
      args:
        - NODE_ENV=development
    ports:
      - '3030:3030'
    volumes:
      - .:/usr/app/client
  server:
    container_name: emerald-server
    command: [sh, -c, 'yarn run prisma deploy && yarn start:dev']
    restart: unless-stopped
    image: server
    depends_on:
      - prisma
      - postgres
    build:
      context: ./project/server
      dockerfile: Dockerfile
      args:
        - NODE_ENV=development
    ports:
      - '4242:4242'
    volumes:
      - .:/usr/app/server

Error log
Code:
marcus-sa@DESKTOP-FUHH564:/e/Git/nest-prisma-angular-docker$ docker-compose up --build --remove-orphans
Building client
Step 1/9 : FROM node:alpine
 ---> 5ffbcf1d9932
Step 2/9 : ARG NODE_ENV=development
 ---> Running in 0fa11a29b762
Removing intermediate container 0fa11a29b762
 ---> a943a9eaa495
Step 3/9 : ENV NODE_ENV=${NODE_ENV}
 ---> Running in 95e18bc28566
Removing intermediate container 95e18bc28566
 ---> 349ada5022a1
Step 4/9 : WORKDIR /usr/app/client
 ---> Running in be4b60c56e33
Removing intermediate container be4b60c56e33
 ---> ad0c66dbfb9d
Step 5/9 : COPY ./package.json .
 ---> 4db7715d4607
Step 6/9 : RUN yarn
 ---> Running in 5c04efc3e1ad
yarn install v1.9.4
warning package.json: No license field
info No lockfile found.
warning @npa/[email protected]: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
(node:1) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@angular-devkit/build-angular > @ngtools/[email protected]" has unmet peer dependency "typescript@~2.4.0 || ~2.5.0 || ~2.6.0 || ~2.7.0 || ~2.8.0 || ~2.9.0".
warning " > @angular/[email protected]" has unmet peer dependency "typescript@>=2.7.2 <2.10".
warning "@angular/compiler-cli > [email protected]" has unmet peer dependency "typescript@>=2.4.2 <2.10".
warning " > [email protected]" has unmet peer dependency "apollo-link@^1.0.0".
warning " > [email protected]" has unmet peer dependency "apollo-link@^1.0.0".
warning " > [email protected]" has unmet peer dependency "graphql@^0.11.3 || ^0.12.3 || ^0.13.0".
warning "apollo-angular-link-http > [email protected]" has unmet peer dependency "apollo-link@^1.0.0".
warning "apollo-angular-link-http > [email protected]" has unmet peer dependency "graphql@^0.11.3 || ^0.12.3 || ^0.13.0".
warning " > [email protected]" has unmet peer dependency "[email protected] || ^0.12.0 || ^0.13.0".
warning " > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0".
warning "apollo-client > [email protected]" has unmet peer dependency "graphql@^0.11.3 || ^0.12.3 || ^0.13.0 || ^14.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 39.46s.
Removing intermediate container 5c04efc3e1ad
 ---> 1390d02cb152
Step 7/9 : COPY . .
 ---> 66ce4136a1c7
Step 8/9 : EXPOSE 8080
 ---> Running in c308b6ef13fa
Removing intermediate container c308b6ef13fa
 ---> 288e619440e4
Step 9/9 : RUN set -ex;     if ["$NODE_ENV" = "production"]; then         yarn build:prod     fi;
 ---> Running in 3211c43f09c6
/bin/sh: syntax error: unexpected end of file (expecting "fi")
ERROR: Service 'client' failed to build: The command '/bin/sh -c set -ex;     if ["$NODE_ENV" = "production"]; then         yarn build:prod     fi;' returned a non-zero code: 2
marcus-sa@DESKTOP-FUHH564:/e/Git/nest-prisma-angular-docker$ docker-compose up --build --remove-orphans
Building client
Step 1/9 : FROM node:alpine
 ---> 5ffbcf1d9932
Step 2/9 : ARG NODE_ENV=development
 ---> Using cache
 ---> a943a9eaa495
Step 3/9 : ENV NODE_ENV=${NODE_ENV}
 ---> Using cache
 ---> 349ada5022a1
Step 4/9 : WORKDIR /usr/app/client
 ---> Using cache
 ---> ad0c66dbfb9d
Step 5/9 : COPY ./package.json .
 ---> Using cache
 ---> 4db7715d4607
Step 6/9 : RUN yarn
 ---> Using cache
 ---> 1390d02cb152
Step 7/9 : COPY . .
 ---> bfdd009dc792
Step 8/9 : EXPOSE 8080
 ---> Running in b50726163591
Removing intermediate container b50726163591
 ---> 78fa6f2af004
Step 9/9 : RUN set -ex;     if ["$NODE_ENV" = "production"]; then         yarn build:prod;     fi;
 ---> Running in 54b5e0bea7e3
+ '[development' '=' production]
/bin/sh: [development: not found
Removing intermediate container 54b5e0bea7e3
 ---> 9a3b15ea99b3
Successfully built 9a3b15ea99b3
Successfully tagged client:latest
Building server
Step 1/9 : FROM node:alpine
 ---> 5ffbcf1d9932
Step 2/9 : ARG NODE_ENV=development
 ---> Using cache
 ---> a943a9eaa495
Step 3/9 : ENV NODE_ENV=${NODE_ENV}
 ---> Using cache
 ---> 349ada5022a1
Step 4/9 : WORKDIR /usr/app/server
 ---> Running in 97c12e798c88
Removing intermediate container 97c12e798c88
 ---> b9d853e03877
Step 5/9 : COPY ./package.json .
 ---> e9ce8755780b
Step 6/9 : RUN yarn
 ---> Running in ba56cf48b5a8
yarn install v1.9.4
warning package.json: No license field
info No lockfile found.
warning @npa/[email protected]: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
(node:1) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@nestjs/graphql > [email protected]" has incorrect peer dependency "graphql@^0.11.7 || ^0.13.0".
warning " > [email protected]" has incorrect peer dependency "graphql@^0.13.0".
warning "apollo-server-express > [email protected]" has incorrect peer dependency "graphql@^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0".
warning "apollo-server-express > apollo-server-core > [email protected]" has incorrect peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0".
warning "apollo-server-express > @apollographql/[email protected]" has incorrect peer dependency "graphql@^0.13.1".
warning "prisma > [email protected]" has incorrect peer dependency "graphql@^0.12.0 || ^0.13.0".
warning " > [email protected]" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
warning "prisma-binding > [email protected]" has incorrect peer dependency "graphql@^0.11.3 || ^0.12.3 || ^0.13.0".
warning "prisma-binding > [email protected]" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
warning "prisma-binding > [email protected]" has incorrect peer dependency "graphql@^0.13.0".
warning "prisma-binding > [email protected]" has incorrect peer dependency "graphql@^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.1".
warning "prisma-binding > [email protected]" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
warning "prisma-binding > graphql-binding > [email protected]" has incorrect peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 36.16s.
Removing intermediate container ba56cf48b5a8
 ---> 6da36da96c51
Step 7/9 : COPY . .
 ---> 5cbf9f43aaf3
Step 8/9 : EXPOSE 4242
 ---> Running in 3b724af3f3a4
Removing intermediate container 3b724af3f3a4
 ---> dc2f82318399
Step 9/9 : RUN set -ex;     if ["$NODE_ENV" = "production"]; then         yarn build;     fi;
 ---> Running in 7d318d723049
+ '[development' '=' production]
/bin/sh: [development: not found
Removing intermediate container 7d318d723049
 ---> a37ec2260c27
Successfully built a37ec2260c27
Successfully tagged server:latest
Starting nest-prisma-angular-docker_prisma_1   ... done
Recreating nest-prisma-angular-docker_client_1 ... done
Starting nest-prisma-angular-docker_postgres_1 ... done
Recreating nest-prisma-angular-docker_server_1 ... done
Attaching to nest-prisma-angular-docker_prisma_1, nest-prisma-angular-docker_postgres_1, emerald-client, emerald-server
postgres_1  | 2018-09-18 22:00:27.700 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2018-09-18 22:00:27.700 UTC [1] LOG:  listening on IPv6 address "::", port 5432
emerald-client | yarn run v1.9.4
emerald-server | yarn run v1.9.4
postgres_1  | 2018-09-18 22:00:27.738 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2018-09-18 22:00:27.786 UTC [26] LOG:  database system was interrupted; last known up at 2018-09-18 21:50:54 UTC
emerald-client | error Command "start" not found.
emerald-client | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
emerald-server | $ /usr/app/server/node_modules/.bin/prisma deploy
emerald-server | /bin/sh: /usr/app/server/node_modules/.bin/prisma: not found
emerald-server | error Command failed with exit code 127.
emerald-server | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
postgres_1  | 2018-09-18 22:00:28.911 UTC [26] LOG:  database system was not properly shut down; automatic recovery in progress
postgres_1  | 2018-09-18 22:00:28.924 UTC [26] LOG:  invalid record length at 0/1677BC0: wanted 24, got 0
postgres_1  | 2018-09-18 22:00:28.924 UTC [26] LOG:  redo is not required
postgres_1  | 2018-09-18 22:00:29.040 UTC [1] LOG:  database system is ready to accept connections
postgres_1  | 2018-09-18 22:00:32.554 UTC [34] ERROR:  database "prisma" already exists
postgres_1  | 2018-09-18 22:00:32.554 UTC [34] STATEMENT:  CREATE DATABASE "prisma"
emerald-client exited with code 1
emerald-server exited with code 1
prisma_1    | Obtaining exclusive agent lock...
prisma_1    | Obtaining exclusive agent lock... Successful.
prisma_1    | Deployment worker initialization complete.
postgres_1  | 2018-09-18 22:00:33.605 UTC [33] ERROR:  null value in column "lastPinged" violates not-null constraint
postgres_1  | 2018-09-18 22:00:33.605 UTC [33] DETAIL:  Failing row contains (2d4cea92-4c6c-4c06-80a5-6632fd665a63, null).
postgres_1  | 2018-09-18 22:00:33.605 UTC [33] STATEMENT:  insert into "TelemetryInfo" ("id","lastPinged")  values ($1,$2)
prisma_1    | Initializing workers...
prisma_1    | Successfully started 1 workers.
emerald-client | yarn run v1.9.4
emerald-client | error Command "start" not found.
emerald-client | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
emerald-client | yarn run v1.9.4
emerald-client | error Command "start" not found.
emerald-client | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
emerald-server | yarn run v1.9.4
emerald-server | $ /usr/app/server/node_modules/.bin/prisma deploy
emerald-server | /bin/sh: /usr/app/server/node_modules/.bin/prisma: not found
emerald-server | error Command failed with exit code 127.
emerald-server | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
emerald-server | yarn run v1.9.4
emerald-server | $ /usr/app/server/node_modules/.bin/prisma deploy
emerald-server | /bin/sh: /usr/app/server/node_modules/.bin/prisma: not found
emerald-server | error Command failed with exit code 127.
emerald-server | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
prisma_1    | Server running on :4466
emerald-server | yarn run v1.9.4
emerald-client | yarn run v1.9.4
emerald-server | $ /usr/app/server/node_modules/.bin/prisma deploy
emerald-server | /bin/sh: /usr/app/server/node_modules/.bin/prisma: not found
emerald-server | error Command failed with exit code 127.
emerald-server | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
emerald-client | error Command "start" not found.
emerald-client | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
prisma_1    | Version is up to date.

So my question is, what would be the best approach to resolve what I'm trying to accomplish?
I did find this but doesn't seem like the most convenient solution (which didn't work either)
 
Last edited:

Users who are viewing this thread

Top