menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Team

Any way to use a custom Dockerfile for building static sites on Now v2?

February 26, 2020 at 2:23pm

Any way to use a custom Dockerfile for building static sites on Now v2?

February 26, 2020 at 2:23pm

I've been searching, but can't find it anywhere.

We've been using Now to host our CRA for a while, since v1, and use a custom Dockerfile to build it. This is because we fetch packages from our private Bitbucket repository, and need some commands to set up the proper SSH keys before running yarn install.

The file looks like this:

FROM mhart/alpine-node:12.13.1 as base
WORKDIR /usr/src
RUN apk update && apk add openssh && apk add git
RUN git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"
RUN mkdir /root/.ssh
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
ARG SSH_KEY
RUN echo "$SSH_KEY" | base64 -d > /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
# You want to move these two files only first and then install,
# because that will cache the dependencies for the next build.
COPY yarn.lock package.json ./
RUN yarn install --network-concurrency 1
ARG REACT_APP_API_ENDPOINT
ARG REACT_APP_VERSION
ARG REACT_APP_GOOGLE_MAPS_KEY
ARG REACT_APP_GOOGLE_OAUTH_CLIENT_ID
ARG REACT_APP_ENV
ARG NODE_ENV
COPY . .
RUN sh build.sh
FROM mhart/alpine-node:12.13.1
WORKDIR /public
# Copy over the files from the build container src
COPY --from=base /usr/src/build /public

However, lately we've had some users experiencing being shown a Zeit 404 page when hard-refreshing our webapp all of a sudden. We can't find any reason why this should happen, and out of sheer desperation, I'm now investigating moving our deployment and the pipelines to Now v2, and ran into this issue promptly. Searching for a solution, it seems that guides and examples show how to use private NPM packages, not private Git-hosted packages (i.e. "

/project-name": "git+https://bitbucket.org/team/project.git#[commithash]"

How would I go about achieving this in v2?


February 26, 2020 at 2:31pm

Note: Removed the Dockerfile mentioned above due to this guide. Also tried committing with it back in, but the build process doesn't seem to use it for anything.

I'd prefer to deploy manually using commands instead of using the Git integration, but I tried the latter as well, hoping that it could solve the issue. However, whenever I press "Connect with Bitbucket" it just connects to my own profile rather than the team profile where all the repositories are hosted, and never gives me the option to choose.

Edited
  • reply
  • like

March 4, 2020 at 4:27pm

For anyone finding this, we ended up building the app on our CircleCI and then deploying to Now, allowing us to control the entires build process better and reuse our Dockerfile to a large extent. Another approach could be moving the Dockerfile commands to shell scripts and run those, but we had issues fetching private Bitbucket dependencies using the previously used SSH keys, so we went another way

  • reply
  • like
private
This channel has been archived