Deployment in CI issue

So I created a gitlab CI configuration and deploy job within.

gitlab-ci.yml

deploy-job: # This job runs in the deploy stage.
  image: docker:stable
  services:
    - docker:dind
    - node:16-bullseye-slim
  stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
  variables:
    FLY_API_TOKEN: $FLY_API_TOKEN
  before_script:
    - apk add --update curl && rm -rf /var/cache/apk/*
    - curl -L https://fly.io/install.sh | sh
  script:
    - echo "Deploying application..."
    - /root/.fly/bin/flyctl auth docker -t {token}
    - /root/.fly/bin/flyctl deploy . -t {token}
    - echo "Application successfully deployed."

Building process is fine. If I do deploy with --build-only everything works fine, but without this flag at the end fly throws error:

Error failed to fetch an image or build from source: error rendering push status stream: unauthorized: not allowed

Not familiar with gitlab CI, but you should ref this GitHub Actions usage with flyctl auth docker: kentcdodds.com/deployment.yml at 61923537967f5f488ca2e9af690163194c09fd98 · kentcdodds/kentcdodds.com · GitHub

Specifically note, username is set to x, docker image tag set to git tip, and deploys done with -i switch linking to a docker/runc image in registry.fly.io.

Assuming you have a fly.toml in project root setup with appname and other fly config as approp and have flyctl launched the app.

You can set app name at deploy time when running fly deploy -a <appname> too.