Gitlab runner and flutter_dotenv in CI/CD

399 Views Asked by At

I want to build a desktop application for linux with flutter that will be used by clients in a controlled environment, I mean it is not a public app that will be downloaded by anyone.

I've thought about building the app from the Gitlab runners and storing it in the gitlab packages. Then the clients, managed by me, download the new versions through the gitlab api.

I'm using the flutter_dotenv package to load environment variables in my flutter app. The documentation recommends adding the .env file to the assets and also adding it to the .gitignore.

The truth is that in the CI/CD when I build the flutter app that is going to be used in production, it gives an error because the .env file does not exist and yet it is being referenced in the assets. This is the error it shows.

enter image description here

The only thing that occurs to me is from the runner itself to know if I am building for test or for prod and create the .env as appropriate. Obviously there is no other option for testing, but I'm not sure if it's good practice and if it's the responsibility of the gitlab runners to create the prod env.

Any ideas?

1

There are 1 best solutions below

2
b perreault On

You don't say what your CI/CD environment is - edit - I see it. GitLab. If it were Azure - you could upload your .env to local secure files storage and in a step of your CI/CD deployment you could copy it in from secure files to the working directory where your app is being built. That is how I have dealt with a missing local.properties file for Android deployment from Azure

sample for Azure, maybe can be adapted to GitLab format

         - task: DownloadSecureFile@1
        name: local_properties
        displayName: 'Download local properties'
        inputs:
          secureFile: 'local.properties'

      - script: |
          echo Installing $(local_properties.secureFilePath) to the android build folder $(Build.SourcesDirectory)/android ...
          sudo cp $(local_properties.secureFilePath) $(Build.SourcesDirectory)/android
          sudo chown -R $(whoami) /home/vsts/work/1/s/android/local.properties