ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [CI-CD] fastlane으로 배포 자동화(CD)
    iOS/CI-CD 2024. 2. 1. 00:07
    728x90
    반응형

    오늘은 앱을 업데이트한 기념으로 자동화 배포를 적용해보기로 했다.

    자동화 시스템이 어떤것이 있는지 찾아봤는데 요즘 iOS 배포에서 많이 쓴다는 FastLane을 사용해보기로 했다.

     

    사실 이걸 해야겠다라고만 생각해봤지 CD? FastLane? 아무런 개념이 없는 상태였다.

     

    CI/CD 관련 개념은 나중에 포스팅 하겠고 오늘은 FastLane에 대해서 집중적으로 사용해 보겠다.

     

    FastLane이란?

     

    앱의 자동화 및 CI/CD (Continuous Integration/Continuous Delivery) 프로세스를 관리하기 위한 도구 모음이다.

    Ruby기반으로 작성된 Fastlane은 앱 개발자 및 팀이 빌드, 테스트, 배포 등의 작업을 자동화하고 스트리밍하도록 도와주는 강력한 도구라고 한다.

     

    현재 앱을 배포하고 유지보수를 하고 있는 입장에서 애플 커넥트를 들어가서 일일히 버전,업데이트 이력, 여러 것들을 수정하고 제출하는데 까지 시간이 많이 낭비가 된다고 생각한다. 이런 귀찮은 작업들을 테스트 및 빌드해주고 배포를 해주는것도 모자라 코드 서명 및 보안 문제까지 해결해 줄 수 있는 것이 이 FastLane이라는 시스템이다.

     

    사실 아직 지속적 통합(CI)부분은 건드리지 못했다... 오늘 이것 설정하는데만 하루를 꼬박 썼기 때문이다..

     

    하지만 같은것만 계속보니 이제 이해가 어느정도 된거 같아서 포스팅을 시작한다.

     

    FastLane로 배포하기

     

    brew install fastlane

     

    일단 homebrew를 이용해 설치를 해준다. 다른 설치도구로도 설치할 수 있지만 나는 homebrew가 설치 되어있었기에 이걸로 진행했다.

    참고로 Xcode Command Line Tools 가 필요할 수도 있다.(나 또한..)

     

    그래서 다음과 같은 툴을 설치해준다.

    xcode-select --install

     

    설치 과정을 보여주고 싶었지만 이건 설치한지 오래되서 사진이 없다.. 양해 부탁한다.

     

    본격적으로 오늘 시작한 부분은 지금 부터다.

     

     

    1. 초기화

    fastlane init

     

    위와 같은 명령어를 치면 본격적으로 fastlane로 프로젝트를 관리할 수 있다. 참고로 이건 본인이 관리하려는 프로젝트 폴더로 들어가서 해야한다.

    [23:42:57]: -----------------------------
    [23:42:57]: --- Welcome to fastlane 🚀 ---
    [23:42:57]: -----------------------------
    [23:42:57]: fastlane can help you with all kinds of automation for your mobile app
    [23:42:57]: We recommend automating one task first, and then gradually automating more over time
    [23:42:57]: What would you like to use fastlane for?
    1. 📸  Automate screenshots
    2. 👩‍✈️  Automate beta distribution to TestFlight
    3. 🚀  Automate App Store distribution
    4. 🛠  Manual setup - manually setup your project to automate your tasks
    ?

     

    그럼 이렇게 옵션을 선택할 수 있는데 본인이 하려는 옵션에 따라 선택하는데 난 앱스토어 배포가 목적이기 때문에 3번을 선택했다.

     

    [23:42:57]: --------------------------------
    [23:42:57]: --- Login with your Apple ID ---
    [23:42:57]: --------------------------------
    [23:42:57]: To use App Store Connect and Apple Developer Portal features as part of fastlane,
    [23:42:57]: we will ask you for your Apple ID username and password
    [23:42:57]: This is necessary for certain fastlane features, for example:
    [23:42:57]:
    [23:42:57]: - Create and manage your provisioning profiles on the Developer Portal
    [23:42:57]: - Upload and manage TestFlight and App Store builds on App Store Connect
    [23:42:57]: - Manage your App Store Connect app metadata and screenshots
    [23:42:57]:
    [23:42:57]: Your Apple ID credentials will only be stored in your Keychain, on your local machine
    [23:42:57]: For more information, check out
    [23:42:57]: 	https://github.com/fastlane/fastlane/tree/master/credentials_manager
    [23:42:57]:
    [23:42:57]: Please enter your Apple ID developer credentials
    [23:42:57]: Apple ID Username:

     

    여기선 본인의 애플 계정(icloud.com)을 작성해주면 된다.

    [23:44:21]: This way, you'll be able to edit your app's metadata in local `.txt` files.
    [23:44:21]: After editing the local `.txt` files, just run fastlane and all changes will be pushed up.
    [23:44:21]: If you don't want to use this feature, you can still use fastlane to upload and distribute new builds to the App Store
    [23:44:21]: Would you like fastlane to manage your app's metadata? (y/n)

     

    여기선 y를 입력하고 엔터

     

    [23:45:18]: Generated Fastfile at path `./fastlane/Fastfile`
    [23:45:18]: Generated Appfile at path `./fastlane/Appfile`
    [23:45:18]: Gemfile and Gemfile.lock at path `Gemfile`
    [23:45:18]: Please check the newly generated configuration files into git along with your project
    [23:45:18]: This way everyone in your team can benefit from your fastlane setup
    [23:45:18]: Continue by pressing Enter ⏎
    
    
    
    [23:45:33]: fastlane will collect the number of errors for each action to detect integration issues
    [23:45:33]: No sensitive/private information will be uploaded, more information: https://docs.fastlane.tools/#metrics
    [23:45:33]: ----------------------
    [23:45:33]: --- fastlane lanes ---
    [23:45:33]: ----------------------
    [23:45:33]: fastlane uses a `Fastfile` to store the automation configuration
    [23:45:33]: Within that, you'll see different lanes.
    [23:45:33]: Each is there to automate a different task, like screenshots, code signing, or pushing new releases
    [23:45:33]: Continue by pressing Enter ⏎
    
    
    [23:46:09]: --------------------------------------
    [23:46:09]: --- How to customize your Fastfile ---
    [23:46:09]: --------------------------------------
    [23:46:09]: Use a text editor of your choice to open the newly created Fastfile and take a look
    [23:46:09]: You can now edit the available lanes and actions to customize the setup to fit your needs
    [23:46:09]: To get a list of all the available actions, open https://docs.fastlane.tools/actions
    [23:46:09]: Continue by pressing Enter ⏎

     

     

    여긴 계속 엔터를 누른다. 그러면 현재 디렉토리에 파일이 여러개 생긴다.

     

    fastlane/Appfile : Bundle/Apple/Team ID등 본인 계정을 세팅하기 위한 파일

    fastlane/Deilverfile : 앱스토어에 올릴 메타데이터 등을 저장하기 위한 파일

    fastlane/FastFile : 자동화 시킬 코드를 작성하는 파일

    fastlane/metadata : 메타정보 파일

    fastlane/screenshots : 스크린샷 파일

    Gemfile : Ruby 프로젝트의 종속성을 정의하는 파일

    Gemfile.lock : bundle install 명령을 실행할 때 생성되는 파일

     

    여기서 주의 만약에 이 포스팅을 보는 사람이 있다면 무조건 따라하지 마시오

    나는 fastlane을 알기 전에 이미 애플 커넥트에 스크린샷, 업데이트 내용, 여러 정보 등 이미 입력해서 저장해놓은 내용이 있었다.

    원래 그런것들 까지 설정하려면 명령어를 써서 설정을 일일히 해줘야한다.

    하지만 위에서 말한것처럼 난 상황이 다르기 때문에 여기서 Appfile과 Fastfile만 건드려줬다.

     

    Fastfile

    platform :ios do
      desc "Push a new release build to the App Store"
      lane :release do
        build_app(workspace: "[프로젝트이름].xcworkspace", scheme: "[프로젝트이름]")
        increment_build_number(xcodeproj: "[프로젝트이름].xcodeproj")
        upload_to_app_store(
          force: true,
          skip_screenshots: true,
          skip_metadata: false,
          submit_for_review: true,
          automatic_release: false,
          submission_information: {
            add_id_info_serves_ads: false,
            add_id_info_tracks_action: true,
            add_id_info_tracks_install: true,
            add_id_info_uses_idfa: true
          }
        )
    
        slack(
          message: "App Store 배포 완료",
          slack_url: "https://hooks.slack.com/services/[slack링크]"
        )
      end
    end

     

     

    Appfile

    app_identifier("[BundleId]")
    apple_id("[UserAppId]")

     

    세세한 설정에 대한 설명은 패스하겠다. 본인의 올리려는 자동화에 대한 내용을 ruby문법으로 작성하면 된다.

     

    이렇게 설정이 모두 끝났으면 

     

    위에서 lane이름을 release로 설정했기 때문에 명렁어를 사용해서 배포를 시작한다. 나는 3분이 걸렸다.

    fastlane realse

     

    그러면 마지막에

    [23:18:51]: Waiting for the build to show up in the build list - this may take a few minutes (check your email for processing issues if this continues)
    [23:19:09]: Waiting for App Store Connect to finish processing the new build (1.1.1 - 15) for IOS
    [23:19:25]: Waiting for App Store Connect to finish processing the new build (1.1.1 - 15) for IOS
    [23:19:43]: Waiting for App Store Connect to finish processing the new build (1.1.1 - 15) for IOS
    [23:19:59]: Successfully finished processing the build 1.1.1 - 15 for IOS
    [23:19:59]: Selecting build 1.1.1 (15)...
    [23:20:02]: Successfully selected build
    [23:20:04]: Successfully updated IDFA declarations on App Store Connect
    [23:20:22]: Successfully submitted the app for review!

    이런 문구와 함께 빌드가 완성이 된다.

     

    사실 설명할 것이 너무너무나 많지만... 나도 연구를 하고 진행해야하는 부분이 있기 때문에 짧게 짧게 포스팅 하겠다. 

     

     

Designed by Tistory.