Browse Source

lighter apps docker image

Mokhtar Naamani 4 years ago
parent
commit
3c47cf69f3
7 changed files with 43 additions and 21 deletions
  1. 9 0
      .dockerignore
  2. 2 3
      README.md
  3. 19 4
      apps.Dockerfile
  4. 2 2
      build.sh
  5. 8 8
      docker-compose.yml
  6. 0 1
      package.json
  7. 3 3
      start.sh

+ 9 - 0
.dockerignore

@@ -5,3 +5,12 @@ target/
 query-node/generated
 query-node/**/dist
 query-node/lib
+pioneer/
+cli/
+tests/
+
+# It is generally a good idea not to ignore the yarn.lock file
+# Including it helps to get a more deterministic build.
+# However as we don't want to include some package from the workspace
+# we don't want their dependencies as baggage.
+yarn.lock

+ 2 - 3
README.md

@@ -25,9 +25,8 @@ After cloning the repo run the following initialization scripts:
 # Install rust toolchain
 ./setup.sh
 
-# Install npm package dependencies
-# Also good habit to run this when switching between branches
-yarn install
+# Install npm package dependencies and build project
+yarn && yarn build
 
 # run some tests
 yarn cargo-checks

+ 19 - 4
apps.Dockerfile

@@ -5,10 +5,25 @@ COPY . /joystream
 
 # Do not set NODE_ENV=production until after running yarn install
 # to ensure dev dependencies are installed.
-RUN yarn install --frozen-lockfile
-# Uncomment query-node build when mappings are fixed
-# RUN yarn workspace query-node-root build
-RUN yarn workspace pioneer build
+RUN yarn
+
+# Pioneer is the 'heaviest' package in terms of dependencies
+# RUN yarn workspace pioneer build
+RUN yarn workspace query-node-root build
 RUN yarn workspace storage-node build
 
+# Remove files that are not needed after build.
+# We will re-fetch only dependencies needed for running the apps.
+RUN rm -fr node_modules/
+RUN rm -fr .git/
+
+FROM node:12
+WORKDIR /joystream
+COPY --from=builder /joystream/ /joystream/
+
+# Skip installing devDependencies, since we have already built the packages.
+# Important to make sure packages have correctly identified what is a devDependency and what is not.
+ENV NODE_ENV=production
+RUN yarn install --forzen-lockfile --production
+
 ENTRYPOINT [ "yarn" ]

+ 2 - 2
build.sh

@@ -4,8 +4,8 @@ set -e
 
 yarn
 yarn workspace @joystream/types build
-yarn workspace @joystream/cli build
 yarn workspace query-node-root build
+yarn workspace @joystream/cli build
 yarn workspace storage-node build
 # Not strictly needed during development, we run "yarn workspace pioneer start" to start
 # a dev instance, but will show highlight build issues
@@ -16,7 +16,7 @@ then
   echo "docker-compose not found, skipping docker build!"
 else
   # Build joystream/apps docker image
-  docker-compose build pioneer
+  docker-compose build colossus
 
   # Optionally build joystream/node docker image
   # TODO: Try to fetch a cached joystream/node image

+ 8 - 8
docker-compose.yml

@@ -152,11 +152,11 @@ services:
     ports:
       - "127.0.0.1:6379:6379"
 
-  pioneer:
-    image: joystream/apps
-    build:
-      context: .
-      dockerfile: apps.Dockerfile
-    ports:
-      - "127.0.0.1:3000:3000"
-    command: workspace pioneer start
+  # pioneer:
+  #   image: joystream/apps
+  #   build:
+  #     context: .
+  #     dockerfile: apps.Dockerfile
+  #   ports:
+  #     - "127.0.0.1:3000:3000"
+  #   command: workspace pioneer start

+ 0 - 1
package.json

@@ -4,7 +4,6 @@
   "version": "1.0.0",
   "license": "GPL-3.0-only",
   "scripts": {
-    "postinstall": "yarn workspace @joystream/types build",
     "build": "./build.sh",
     "start": "./start.sh",
     "cargo-checks": "devops/git-hooks/pre-commit && devops/git-hooks/pre-push",

+ 3 - 3
start.sh

@@ -37,6 +37,6 @@ docker-compose up -d graphql-server
 docker-compose up -d processor
 
 echo "press Ctrl+C to shutdown"
-
-# Start a dev instance of pioneer and wait for exit
-docker-compose up pioneer
+while true; do 
+  read
+done