GitLab CI Pipeline produces `base64: truncated input` unnecessarily

Problem to solve

I am getting into deploying a Docker artefact onto fly@io.
The image is built and supposed to be deployed in the same pipeline.
All this is just, as of now, for testing, so I can see, how I can leverage GitLab CI for this specific use case.

The thing is, fly@io offers pretty long and not ideally formatted API access tokens. They contain commas, whitespace, etc.
When I wanted to set a secret environment variable, the GitLab Web UI did not let me, due to these formatting issues.

So, I set up a workaround, by encoding the value as Base64, then used the result as the variable’s value.

When I try to decode the string in the script section of the build job in the GitLab CI pipeline, it constantly errors out like this.

$ set -x
$ export FLY_ACCESS_TOKEN="$(echo "B64_FLY_ACCESS_TOKEN" | base64 -dw0)"
+ echo '$ export FLY_ACCESS_TOKEN="$(echo "B64_FLY_ACCESS_TOKEN" | base64 -dw0)"'
+ echo B64_FLY_ACCESS_TOKEN
+ base64 -dw0
base64: truncated input
$ flyctl deploy --yes --now --image $DOCKER_IMAGE_NAME:$CI_COMMIT_SHORT_SHA --app $FLY_APP_NAME
+ export 'FLY_ACCESS_TOKEN=a�-�D�L��'
+ echo '$ flyctl deploy --yes --now --image $DOCKER_IMAGE_NAME:$CI_COMMIT_SHORT_SHA --app $FLY_APP_NAME'
+ flyctl deploy --yes --now --image regimage:123 --app app
Error: failed retrieving current user: Post "https://api.fly@io/graphql": net/http: invalid header field value for "Authorization"
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1

Note the base64: truncated input which is the root culprit of above snippet.

Sounds like an issue with the image, producing the container or base64 or something like that, right?
Well, sounds like it, but it’s not true.
I reproduced the entire pipeline locally, with the exact same images, exact same commands, etc. Everything works!

Therefore, there is some GitLab CI magic, which breaks all this.

To be clear, the image containing this core utility supports input as long as it is provided in this use case. It works. It only does not work, when run inside GitLab CI, although the exact same image and binary is used.

Steps to reproduce

  1. Build Docker image inside pipeline.
  2. Try to deploy image to fly@io.
  3. Notice base64: truncated input.
  4. Reproduce locally and notice, that there is no issue outside of the GitLab CI environment.

Configuration

deploy:
  stage: deploy
  image:
    name: mprokopi/flyctl
    entrypoint: [""]
  variables:
    DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE/app
    FLY_APP_NAME: app
  script:
    - set -x
    # In the debugging process, I tried several solutions as to how to decode the string. None worked inside GitLab CI.
    # Locally, all worked equally, without any issue whatsoever.
    - export FLY_ACCESS_TOKEN="$(printf '%s' "B64_FLY_ACCESS_TOKEN" | base64 -dw0)"
    - flyctl deploy --yes --now --image $DOCKER_IMAGE_NAME:$CI_COMMIT_SHORT_SHA --app $FLY_APP_NAME
  environment:
    name: development
  only:
    - master

Versions

  • Self-managed
  • GitLab.com SaaS
  • Dedicated
  • Self-hosted Runners

No idea, why it’s not allowed to post the fly.io link…

Okay, cringe, I see it now! :weary: