diff --git a/.dockerignore b/.dockerignore index 14b1fb97f..e413ac5ea 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,18 @@ +# excluded because we'll likely need to rebuild this. node_modules + +# scripts are used during development and testing, not +# production. +scripts + +# documentation should not be visable in production. +docs + +# static assets are rebuild in the docker container. +dist + +# tests are not run in the docker container. test + +# we won't use the .git folder in production. .git diff --git a/.gitignore b/.gitignore index d91635c94..62a765fff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,12 @@ node_modules npm-debug.log* dist -!dist/coral-admin -dist/coral-admin/bundle.js test/e2e/reports -.DS_Store -*.iml -*.swp dump.rdb .env *.cfg .idea/ coverage/ -.tags -.tags1 - -# remove plugin folders +*.swp plugins plugins.json diff --git a/Dockerfile b/Dockerfile index f8cb8a45d..4e2b77520 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,16 +5,20 @@ RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # Setup the environment -ENV NODE_ENV production ENV PATH /usr/src/app/bin:$PATH ENV TALK_PORT 5000 EXPOSE 5000 -# Install app dependencies -COPY package.json yarn.lock /usr/src/app/ -RUN yarn install --production - # Bundle app source COPY . /usr/src/app +# Install app dependencies and build static assets. +RUN yarn install && \ + yarn build && \ + yarn install --production && \ + yarn cache clean + +# Ensure the runtime of the container is in production mode. +ENV NODE_ENV production + CMD ["yarn", "start"] diff --git a/Dockerfile.onbuild b/Dockerfile.onbuild new file mode 100644 index 000000000..2476c6d1a --- /dev/null +++ b/Dockerfile.onbuild @@ -0,0 +1,13 @@ +FROM coralproject/talk:latest + +# Bundle app source +ONBUILD COPY . /usr/src/app + +# At this stage, we need to install the development dependancies again because +# we need to have webpack available. We then build the new dependancies and +# clear out the development dependancies again. After this we of course need to +# clear out the yarn cache, this saves quite a lot of size. +ONBUILD RUN NODE_ENV=development yarn install && \ + NODE_ENV=production yarn build && \ + NODE_ENV=production yarn install --production && \ + yarn cache clean \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh index fd681fc7f..efb182dc9 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -28,6 +28,7 @@ deploy_tag() { do echo "==> tagging $version" docker tag coralproject/talk:latest coralproject/talk:$version + docker tag coralproject/talk:latest-onbuild coralproject/talk:$version-onbuild done # Push each of the tags to docker hub, including latest @@ -35,16 +36,19 @@ deploy_tag() { do echo "==> pushing $version" docker push coralproject/talk:$version + docker push coralproject/talk:$version-onbuild done } deploy_latest() { echo "==> pushing latest" docker push coralproject/talk:latest + docker push coralproject/talk:latest-onbuild } -# build the repo -docker build -t coralproject/talk . +# build the repo, including the onbuild tagged versions. +docker build -t coralproject/talk:latest -f Dockerfile . +docker build -t coralproject/talk:latest-onbuild -f Dockerfile.onbuild . # deploy based on the env if [ -n "$CIRCLE_TAG" ]