简体   繁体   English

CI/CD 中的 Gitlab runner 和 flutter_dotenv

[英]Gitlab runner and flutter_dotenv in CI/CD

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.我想为 linux 和 flutter 构建一个桌面应用程序,供客户端在受控环境中使用,我的意思是它不是任何人都可以下载的公共应用程序。

I've thought about building the app from the Gitlab runners and storing it in the gitlab packages.我考虑过从 Gitlab 跑步者构建应用程序并将其存储在 gitlab 包中。 Then the clients, managed by me, download the new versions through the gitlab api.然后由我管理的客户通过 gitlab api 下载新版本。

I'm using the flutter_dotenv package to load environment variables in my flutter app.我正在使用flutter_dotenv package 在我的 flutter 应用程序中加载环境变量。 The documentation recommends adding the .env file to the assets and also adding it to the .gitignore .文档建议将.env文件添加到资产中,并将其添加到.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.事实是,在 CI/CD 中,当我构建将在生产中使用的 flutter 应用程序时,它给出了一个错误,因为.env文件不存在,但它在资产中被引用。 This is the error it shows.这是它显示的错误。

在此处输入图像描述

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.我唯一想到的是跑步者本身知道我是为测试还是为生产而.env 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.显然没有其他测试选项,但我不确定这是否是好的做法,也不确定gitlab跑步者是否有责任创建产品环境。

Any ideas?有任何想法吗?

You don't say what your CI/CD environment is - edit - I see it.你没有说你的 CI/CD 环境是什么——编辑——我看到了。 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. GitLab。如果它是 Azure - 您可以将您的 .env 上传到本地安全文件存储,并且在 CI/CD 部署的一个步骤中,您可以将它从安全文件复制到正在构建您的应用程序的工作目录。 That is how I have dealt with a missing local.properties file for Android deployment from Azure这就是我从 Azure 处理 Android 部署丢失的 local.properties 文件的方式

sample for Azure, maybe can be adapted to GitLab format样本为 Azure,也许可以适应 GitLab 格式

         - 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM