# balena push vs build and deploy

**URL:** <https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109>\
**Category:** Product support\
**Created:** [January 29, 2020, 1:08am UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109 "2020-01-29T01:08:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [January 29, 2020, 1:08am UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/1 "2020-01-29T01:08:43Z")

</div>

I have a multi-service, multi-stage build for pi zero devices based on alpina images. I typically develop and optimize the image specs/dockerfile by building using `balena build -a my-app-name`, which builds it on my mac using my docker instance, but do the actual build and application deployment using `balena push my-app-name` which builds on the servers and then deploys to the application group. So far this seems to have worked but I’m a bit unclear on a few things:

- My understanding is that when I build using `build`, docker will automatically cross-compile based upon the architecture that comes from the application profile. Is that correct?
- the container size is different depending on whether I build on my docker or in the cloud (the latter is smaller). Is this because the local build automatically includes emulation libraries?
- Is doing a `balena deploy --build` equivalent to doing a `push`? It seems there is more flexibility with `build`, for example, by providing build arguments that can control the build.

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [January 29, 2020, 12:04pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/2 "2020-01-29T12:04:55Z")

</div>

If you’re using `balena build` to build your images then you should be using `balena deploy` to deploy the built artifacts. `balena push` bundles your directory and sends it for building (again) on our cloud builders and deploys in one go. The equivalent to push is indeed `balena deploy --build`. Both `build` and `deploy --build` will indeed cross compile if needed, but `push` will most likely use the ARM builders which means there’s no cross-copmilation.

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [January 29, 2020, 4:49pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/4 "2020-01-29T16:49:20Z")

</div>

Thank you. That’s clear. What would account for the differences in image size? 328MB when I build locally and 315MB when I build using push? It makes me worry a bit that the two are not in fact equivalent.

---

<div class="post-metadata">

**Author:** ![garethtdavies](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/garethtdavies/32/2669_2.png) [@garethtdavies](https://forums.balena.io/u/garethtdavies)\
**Post date:** [January 29, 2020, 5:08pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/5 "2020-01-29T17:08:12Z")

</div>

Hi, I’m not sure currently as to the difference in size which I will investigate, but in the interim I wanted to point you at this Masterclass that has a lot more information/examples on the build/push/deploy commands. [https://github.com/balena-io/balena-cli-masterclass#5-building-and-deploying-an-application-without-the-builder](https://github.com/balena-io/balena-cli-masterclass#5-building-and-deploying-an-application-without-the-builder)

---

<div class="post-metadata">

**Author:** ![thgreasi](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/thgreasi/32/454_2.png) [@thgreasi](https://forums.balena.io/u/thgreasi)\
**Post date:** [January 29, 2020, 6:13pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/7 "2020-01-29T18:13:03Z")

</div>

Hi @0xff  
Could you clarify where are those image size numbers from?  
Do the two releases show different image sizes in the release summary page in the balenaCloud dashboard?

This could be related to previously cached layers in the cloud builder or your cli build, while some of the dependencies have been updated.  
Could you try running a `balena deploy` with the additional `--nocache` argument and compare the results while also doing a `git push balena master:balena-nocache` ?

If they still differ, then this might be related to the fact that our CLI still uses 1024 to convert MB to KB in some places, while our builder fetches the image size as reported by the docker daemon, which uses 1000 for conversions.  
We do have a CLI issue to track this conversion issue. Let me point you to that for reference:

> <https://github.com/balena-io/balena-cli/issues/1451>
>
> Placeholder issue for tracking.
> It seems that the humanize package is using 1024 for those conversions.
> HQ: balena-io/balena#1962

Kind regards,  
Thodoris

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [January 29, 2020, 6:13pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/8 "2020-01-29T18:13:52Z")

</div>

I don’t know how I missed the cli-masterclass doc but it’s a great resource. Thanks for pointing it out.

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [January 29, 2020, 6:28pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/9 "2020-01-29T18:28:08Z")

</div>

Ah, I think you are correct that the issue is between the way docker shows the sizes. I just built using the standard `balena build -a` command and saw that the image size for this service as reported was

`[Build] solmon Image size: 314.15 MB`

Evidently I was looking at sizes in via `docker image ls` where I see:

`balena_solmon latest b90c8f90f78b 3 seconds ago 329MB`

The difference of about 4.8% is exactly the difference between (1024\*1024) = 1,048,576 vs 1000000, confirming your suspicion.

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [January 29, 2020, 7:57pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/12 "2020-01-29T19:57:22Z")

</div>

But here’s another issue related to `balena deploy app_name` vs `build push app_name`. When I use the former, I get the following message:

```auto
 solmon ok/usr/src/app/node_modules/bindings/bindings.js:121
 solmon throw e;
 solmon ^
 solmon  
 solmon Error: Error relocating /usr/src/app/node_modules/@serialport/bindings/build/Release/bindings.node: _ZN2v820EscapableHandleScope6EscapeEPPNS_8internal6ObjectE: symbol not found
 solmon at Object.Module._extensions..node (internal/modules/cjs/loader.js:1025:18)
 solmon at Module.load (internal/modules/cjs/loader.js:815:32)
 solmon at Function.Module._load (internal/modules/cjs/loader.js:727:14)
 solmon at Module.require (internal/modules/cjs/loader.js:852:19)
 solmon at require (internal/modules/cjs/helpers.js:74:18)
 solmon at bindings (/usr/src/app/node_modules/bindings/bindings.js:112:48)
 solmon at Object.<anonymous> (/usr/src/app/node_modules/@serialport/bindings/lib/linux.js:2:36)
 solmon at Module._compile (internal/modules/cjs/loader.js:959:30)
 solmon at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
 solmon at Module.load (internal/modules/cjs/loader.js:815:32)

```

when the container starts. Not a problem when I use the `balena push app_name` model.

I suspect this is caused by my limited understanding of how the specification of the architecture affects local builds.

---

<div class="post-metadata">

**Author:** ![jimsynz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jimsynz/32/4663_2.png) [@jimsynz](https://forums.balena.io/u/jimsynz)\
**Post date:** [January 29, 2020, 8:10pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/13 "2020-01-29T20:10:51Z")

</div>

Hi there,

Just to confirm; you’re seeing a build failure when doing `balena push` but not while doing `balena build`? Is it possible that your project depends on a tagged container that may have changed (and your workstation has cached older versions)? (eg `FROM balenalib/%%BALENA_MACHINE_NAME%%-node:latest`) If so it may be worth modifying your `Dockerfile` to point to a specific version rather than `latest` or `stable`? You can confirm this by manually running `docker pull` of the base images to see if there are new versions.

Thanks,  
James.

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [January 29, 2020, 8:44pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/14 "2020-01-29T20:44:43Z")

</div>

Sorry, not a build failure, a run failure when the container spins up.

---

<div class="post-metadata">

**Author:** ![jimsynz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jimsynz/32/4663_2.png) [@jimsynz](https://forums.balena.io/u/jimsynz)\
**Post date:** [January 29, 2020, 8:51pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/15 "2020-01-29T20:51:19Z")

</div>

Oh. I presume your Dockerfile copies the full contents of the `node_modules` directory into the final stage container without modification?

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [January 29, 2020, 10:02pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/17 "2020-01-29T22:02:47Z")

</div>

Yes - I do the build in my build image and then copy all the node\_modules into my run image - both are based on alpine images.

---

<div class="post-metadata">

**Author:** ![jimsynz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jimsynz/32/4663_2.png) [@jimsynz](https://forums.balena.io/u/jimsynz)\
**Post date:** [January 29, 2020, 10:11pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/18 "2020-01-29T22:11:14Z")

</div>

My best guess is that there is a runtime library required by `serialport` that is not present in the run image. This seems suspicious given that you said it builds fine on your local workstation. Can you try pulling the latest versions of the base images you’re using from the registry to verify that they’re the same?

Thanks,  
James.

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [February 5, 2020, 4:24pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/21 "2020-02-05T16:24:14Z")

</div>

My concern is that when it builds on my local workstation it uses local node bindings to map the serialport javascript code with the appropriate C code instead of the ones for the pi. Is that possible?

I’ve been building using the `push` model and it’s fine, except I would like to use build arguments which the `push` model doesn’t support.

---

<div class="post-metadata">

**Author:** ![ffissore](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ffissore/32/2842_2.png) [@ffissore](https://forums.balena.io/u/ffissore)\
**Post date:** [February 6, 2020, 11:15am UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/23 "2020-02-06T11:15:26Z")

</div>

Hi

`balena build` does indeed cross-compile, if provided with the `--emulated` flag, for example when building for the pi on an amd64 machine

Can you please double check you’re adding the `--emulated` flag to `balena build`? eg: `balena build -a <app> --emulated`

Regards

federico

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [February 18, 2020, 8:35pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/25 "2020-02-18T20:35:10Z")

</div>

Sorry about late response. Using the `--emulated` flags seems to not make any difference. I still get the same binding errors.

---

<div class="post-metadata">

**Author:** ![hedss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hedss/32/210_2.png) [@hedss](https://forums.balena.io/u/hedss)\
**Post date:** [February 18, 2020, 9:16pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/26 "2020-02-18T21:16:34Z")

</div>

Hi @0xff,

So given you’re copying the `node_modules` directory in completeness, I’ve a suspicion that this comes down to the way `balena push` deals with the build and that maybe you’ve got a `node-gyp` built binding in the `node_modules` directory that’s for the wrong architecture.

Is there a `node_modules/build` directory in your `node_modules` directory? When you originally created the directory, did you just carry out an `npm install` from the relevant source directory with `package.json` in it from your development machine or is it populated as part of the initial Dockerfile (it would be useful to see relevant portions of your Dockerfile here)? If the latter, then it should work as long as you’re not switching between base image architectures (for example `npm install`ing using a 64bit Arm image and then copying them into a 32bit Arm image).

Best regards,

Heds

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [February 18, 2020, 9:20pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/28 "2020-02-18T21:20:27Z")

</div>

Here’s the entire Dockefile.template:

```auto
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine-python:3.6-build as build

WORKDIR /usr/src/app

COPY /lib/requirements3.txt /lib/requirements3.txt
RUN pip3 install -r /lib/requirements3.txt

RUN apk upgrade --no-cache \
  && apk add --no-cache nodejs npm

# Install the node tools
COPY package.json package.json
RUN npm install && npm cache clean --force && rm -rf /tmp/*

# Install
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine-python:3.6-run
WORKDIR /usr/src/app

ENV UDEV=1
ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
ENV INITSYSTEM=off

RUN apk upgrade --no-cache \
  && apk add --no-cache nodejs npm iputils modemmanager networkmanager curl

COPY --from=build /usr/local/lib/python3.6/site-packages /usr/local/lib/python3.6/site-packages
COPY --from=build /usr/src/app/node_modules node_modules

COPY . ./
RUN cp bashRC.txt /root/.bashrc
RUN /bin/mkdir -p /data/config/ /data/logs && touch /data/config/ssid.txt
RUN chmod 700 connectCheck.sh

CMD ["/bin/bash","-c",". cmd.sh"]

```

---

<div class="post-metadata">

**Author:** ![robertgzr](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/robertgzr/32/1387_2.png) [@robertgzr](https://forums.balena.io/u/robertgzr)\
**Post date:** [February 19, 2020, 10:25am UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/29 "2020-02-19T10:25:27Z")

</div>

Have you tried this with a single-stage build instead?

---

<div class="post-metadata">

**Author:** ![0xff](https://avatars.discourse-cdn.com/v4/letter/0/5fc32e/32.png) [@0xff](https://forums.balena.io/u/0xff)\
**Post date:** [February 19, 2020, 3:51pm UTC](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109/31 "2020-02-19T15:51:49Z")

</div>

We started with single-stage builds but the image is excessively large. We cut the size to 1/3 by using the _build_ base image to build the various modules and the _run_ base for the actual image.

[Next page](https://forums.balena.io/t/balena-push-vs-build-and-deploy/60109.md?page=2)
