Skip to content

Build docker image locally

ear-dev edited this page Sep 2, 2021 · 13 revisions

Our CI builds and deploys docker images to our Elastic Container Registries in the veranda-dev and veranda-prod AWS environments every time a PR is merged into the develop_pwa branch of this git repo.

Sometimes however, you may want to build an image from some other branch so that you can deploy and test it. You can do that by building the image locally and manually pushing it to the repo from where you make your deployments.

"Inception" workaround for OSX

When on a Mac however, you have to build the Rocketchat server in a linux based docker container because it builds proprietary dependencies from our repos, and they have to be built for linux to run properly in our kubernetes clusters. You need to mount a shared directory with your laptop to this development docker container, and use that as the build directory. Once the build is complete, you can build the target docker image from the shared directory on the laptop itself.

The docker image used as the linux development environment

  • First you have to build this image. It will serve as your development environment where you will build the rocketchat server code. Create a file named Dockerfile with these contents:
FROM node:12.18.3
VOLUME /tmp/rc_build

# ENV NODE_VERSION 12.18.3
# ENV NODE_ENV production

# OS environment
RUN set -ex \
 && apt update \
 && apt-get install -y build-essential python3.5-dev vim \
 && groupadd -g 65533 -r rocketchat \
 && useradd -u 65533 -r -g rocketchat rocketchat \
 && command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh \
 && mkdir /app \
 && chown rocketchat:rocketchat /app

# User environment
USER rocketchat

ENV HOME /app

WORKDIR /app

RUN export PATH=$HOME/.local/bin:$PATH \
 && curl -O https://bootstrap.pypa.io/get-pip.py \
 && python3.5 get-pip.py --user \
 && pip install awscli --upgrade --user

RUN set -ex \
 && git clone --depth 1 https://github.com/WideChat/Rocket.Chat.git
#  && cd Rocket.Chat \
#  && meteor --version \
#  && meteor npm i
  • run this command: docker build -t rocketchat:dev-image .
  • start and enter the container from this image: docker run -v /tmp/rc_build:/tmp/rc_build -it rocketchat:dev-image /bin/bash

Working in the container

  • You should now be in the container
  • cd Rocket.Chat
  • git status
  • Sync with whichever branch you want to build
  • meteor npm install
  • meteor build --server-only --directory /tmp/rc_build

Build your target image

  • Now exit the development container where you just built your server code.

  • cd /tmp/rc_build

  • cp <path-to-your-local-WideChat/Rocket.Chat/.docker/Dockerfile /tmp/rc_build/Dockerfile

  • docker build -t rocketchat:desired_tag .

  • You now have a deployable Rocketchat docker image in your local docker host repo. You can tag and push it to whichever remote repo you are deploying from.

  • NOTE: We use ECR for our veranda deployments and Artifactory for the vega-infrastructure deployments.

  • Add info on all that here??

Clone this wiki locally