Dear support, is there a way to configure one or more --build-arg values for a Docker-based service in the App Platform?

At the Docker build time, we pass arguments to fine-tune nginx configuration files. We use different Build Arg values for our development, staging, and production environments.

Also, it is not clear whether build_command happens after docker build, or is it actually the way to customize how docker build runs? Could you give some examples of using build_command with Dockerfiles?

Many thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

@ReWild 👋

The way to accomplish this today would be to pass in build-time environment variables. If you’re creating envs through the UI, then they’re by default build-and-run-time variables. If creating via raw app spec and doctl, then you can choose one or both using the scope field. We don’t currently support passing --build-args directly, but this is a good idea that we’ll consider adding to the product — your feedback here helps.

An example of an app spec with build-time environment variables might look like this:

name: sample-dockerfile-static
static_sites:
- name: site
  github:
    repo: digitalocean/sample-dockerfile-static
    branch: master
  envs:
  - key: API_URL
    value: https://api.example.com
    scope: BUILD_TIME

Hopefully that’s a sufficient workaround in the meantime. Stay tuned to our product release notes for updates on this and other features.

Thanks for using the App Platform, and happy coding!

  • Thanks @snormoredo. Apparently, this does not help, as host environment variables are not visible during the build time. For example, in Dockerfile:

    ARG ARG_APP_HOST=$ENV_APP_HOST
    or
    ARG ARG_APP_HOST=${ENV_APP_HOST}

    ENV_APP_HOST, which is a host environment variable, is not visible during the build time.

    For example, when building the container locally:

    ENV_APP_HOST=example.com docker build ...

    The Dockerfile can’t see the ENV_APP_HOST – it is empty. I expect the same to happen when the App Platform will build my Dockerfile. Even if I set an environment variable in my App Spec, it won’t be seen during the build time.

    So what would be a working workaround here?

    Without a workaround, we won’t be able to use the same nginx Dockerfile for two separate Apps running under two separate domains, e.g. example.com and example-staging.com. We will have to maintain two separate Dockerfiles, each hardcoding the domain name. Please advise.

Submit an Answer