Deploying to Fly via CircleCI

We’ve been using Fly for a while, and deploying commits on our main branch to a staging environment. Up until now, we had been doing this via a multi-stage Dockerfile, but builds had been taking a while since we weren’t doing them locally. So, we opted to build the Docker image locally in CI and deploy to Fly. More info in the Circle docs here. Figured I would post what we learned.

To achieve this, we simplified our Dockerfile to just deploy, rather than to build and deploy, and moved our build step into a Circle step. Then, we simply need to create the Docker image in Circle, push it to Fly, and deploy the image tag. Here’s the code - this is for a Node.js app:


FROM mhart/alpine-node:slim-12.16.3

COPY ./dist .


Relevant part of config.yml


      docker_layer_caching: true
      - checkout
      - run:
          name: Deploy Fly
          command: |
            wget -qO- '' | tar xz
            ./flyctl auth docker
            docker build -t$FLY_APP_NAME:$CIRCLE_BUILD_NUM .
            docker push$FLY_APP_NAME:$CIRCLE_BUILD_NUM
            ./flyctl deploy -i$FLY_APP_NAME:$CIRCLE_BUILD_NUM -a $FLY_APP_NAME


That was all we had to do. One caveat - this broke Bcrypt functionality. Tried adding RUN apk add --no-cache make gcc g++ python to our Dockerfile, to no avail, so that’s one thing we are still trying to track down. Also note that I had to do this on a machine executor - was getting 401 errors during the deploy step despite the flyctl auth login line - I suspect it has something to do with the environment.

Hope this helps somebody - it has shrunk our deploy CI step from 8 minutes down to 1-2 minutes.


Wow that’s a nice build speed.

What version of bcrypt are you using? I think if you upgrade to bcrypt 3.0.0 it might work without a rebuild. Alpine is really nice but musl makes native modules tricky.