안녕하세요 데브리프터 입니다!
회사에서 프로젝트를 진행하면서 여러가지 상황에 따라서 빌드를 모두 다르게 해야하는 상황이 많았습니다.
이런 이유로 flag 를 활용한 코드제어에 대한 내용을 이전 글에서 포스팅했습니다.
오늘은 실제로 빌드환경에 따라서 In House 방식으로 배포하기 위해 ipa 파일을
생성하는 방법에 대해서 작성해 보겠습니다!
서론 그만하고 시작합니다!!
사용 및 작성 목적
- SI 프로젝트 중 보안정책이 강한 몇몇 회사는 그 특성상 현장에가서 직접 개발 / 디버깅 / 테스트 하기에 자원이 부족합니다
- 특히 테스트 기간에 여러가지 이슈사항으로 보안테스트 , 배포용 , 개발환경테스트용 등 다양한 환경을 적용해서 빌드파일을 전달해야할 상황이 여러 프로젝트에서 동시다발적으로 생깁니다. 이에 따라서 잘못된 파일이나 잘못된 환경설정이 적용되는 휴먼에러가 발생할 수 있는 빈도가 높아집니다.
- 이를 해결하기 위하여 배포 및 ipa/ apk 생성 시 환경설정을 명시적으로 작성하고 자동화하여 에러를 줄이고 이에 따른 시간적 리소스를 최소화하는 것이 해당 기술도입의 이유 및 목적입니다.
목표
- Fastlane을 사용하여 CI/CD의 파이프라인을 구축
- 이를 통해서 다양한 조건의 빌드환경을 오차없이 적용할 수 있도록 자동화
- 문서화를 통해서 규칙을 정함으로써 프로젝트 구성원들이 정보를 공유할 수 있도록 명시
- 프로젝트 배포 이후 관리자에게 인수인계
- 이 목표를 달성하기 위해 다음과 같은 단계를 거친다.
- Background of Fastlane
- Fastlane 설치 및 기본 설정
- 빌드 스크립트 작성 및 테스트
- CI/CD 파이프라인 구성 및 연동
Background of Fastlane
- iOS 앱을 개발하여 디바이스에 테스트를 하기위해서는 다음과 같은 과정이 필요합니다.
- 인증서 생성 (Certificates)
- APP ID 등록 (bundle Identifier)
- Provisioning Profile 생성
- iOS Developer 사이트에 접속하여
- Fastlane을 사용하여 앱을 배포, 테스트하기 전에 반드시 위의 과정들을 통하여 Apple Developer 계정에 앱, 인증서, 프로파일을 등록 및 생성해야 합니다.
FastLane Tool 의 개요
다음 tool 들을 Fastfile의 lane명령어아래에 추가하여 명령을 커스텀 할 수 있습니다.
scan : 앱의 테스트를 실행
snapshot : 지역화된 스크린샷 생성
frameit : snapshot에서 생성한 스크린샷에 기기 프레임을 적용하고 위에 텍스트를 넣어서 멋진 설명 사진을 만들어준다.
pem : 푸시 알림 인증 생성을 자동화
cert : 유효한 코드 사이닝 identify를 생성
sigh : 프로비저닝 파일을 생성
produce : 커맨드 라인으로 iTunes Connect와 Apple Developer portal에 앱ID를 등록
gym : 앱을 빌드하여 ipa 파일을 생성
deliver : iTunes Connect에 앱의 메타데이터, 스크린샷, 바이너리 파일을 올릴 수 있는 툴
FastLane Install
- Xcode command line tools (mac OS)
- Xcode 커맨드 라인툴을 설치합니다.
Xcode command line tools (mac OS)
- 2 - 1 Homebrew ( macOS)
대부분 맥을 사용하면 homebrew를 사용하고, homebrew를 사용하면 Ruby를 별도로 설치 하지 않고 fastlane에 적절한 루비버전을 설치합니다. 가장 추천됩니다.
brew install fastlane
- 2 - 2 Ruby
macOS 라면 Ruby는 추천하지 않습니다.
$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
- 2 - 3 Bundler
source "<https://rubygems.org>"
gem "fastlane"
Setting up fastlane
프로젝트 최상단 루트로 가서 터미널에 다음 명령어를 입력합니다.
fastlane init
- fastlane 사용목적을 선택합니다 : in house 방식 배포를 위해 사용하기 때문에 4번 메뉴얼 세팅을 선택합니다.
Setting up fastlane
프로젝트 최상단 루트로 가서 터미널에 다음 명령어를 입력합니다.
fastlane init
- fastlane 사용목적을 선택합니다 : in house 방식 배포를 위해 사용하기 때문에 4번 메뉴얼 세팅을 선택합니다.
init이 끝나면 프로젝트 폴더아래에 fastlane 폴더가 생성 됩니다.
fastlane/Appfile 에 다음과 같은 설정을 넣어줍니다.
# default 번들 ID
app_identifier("com.회사명.회사명")
# Your Apple email address
apple_id("이름@회사명.com")
# Developer Portal Team ID
team_id("영어대문자와숫자의조합")
team_id 는 애플개발자계정에서 확인할 수 있습니다.
fastlane/Fastfile에서는 명령어의 정의와 명령 세부 설정등을 세팅하고 fastlane {laneName} 을 실행하면 Fastfile 에 설정한 스크립트를 토대로 배포 및 빌드를 실행합니다.
아래는 그 예시와 같습니다 ( gym 을 사용한 ipa 파일 추출 동작 )
default_platform(:ios)
platform :ios do
desc "Description of what the lane does" # Description
lane :custom_lane do # 실행할 lane 명령어
gym( # ipa 파일 생성을 위한 gym 명령어
export_method: "ad-hoc" # 배포 버전 명시
)
ENV["SLACK_URL"] = "<https://hooks.slack.com/services/생략>"
slack(
message: "Exporting ipa file complete ><"
)
end
end
// 명령어: lane: custom_lane
// tool : gym ( ipa 파일 생성을 위한 명령여 ) : ad-hoc 용 파일 생성
// slack: webHook 등록등을 위한 추가 옵션
// 테스트용 IPA 파일 추출을 위하여 gym 명령어를 실행합니다.
// 이때, export method(gym 옵션) 를 ad-hoc으로 명시하고 webhook 옵션이 있다면 추가해줍니다.
Fastfile 작성
# This file contains the fastlane.tools configuration
# You can find the documentation at <https://docs.fastlane.tools>
#
# For a list of all available actions, check out
#
# <https://docs.fastlane.tools/actions>
#
# For a list of all available plugins, check out
#
# <https://docs.fastlane.tools/plugins/available-plugins>
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
# ====================================================
# 스킴별로 다르게 url 세팅 해야할 시 사용
$web_dis_url = ""
$web_dev_url = ""
# 팀 ID : appFile 또는 developer.apple/account 에서 확인
$team_id = "********"
# ====================================================
default_platform(:ios)
platform :ios do
desc "Description of what the lane does"
lane :custom_lane do
# add actions here: <https://docs.fastlane.tools/actions>
end
desc "Export Debug Ipa"
lane :build_ipa_debug do
# 프로젝트 루트 경로 설정
project_root = File.expand_path('..', Dir.pwd)
# output 폴더 생성 (없는 경우)
output_dir = File.join(project_root, "output")
FileUtils.mkdir_p(output_dir) unless File.directory?(output_dir)
# signingCertificate 동적으로 생성
certificate_name = "Apple Distribution: Your company name (*********(temaId)"
signing_certificate = `security find-certificate -c "#{certificate_name}" -p | openssl x509 -noout -fingerprint -sha1 | sed 's/^.*=//' | sed 's/://g'`.strip
# ExportOptions.plist 생성
export_options = {
method: "enterprise",
provisioningProfiles: {
"com.company.name.ios" => "profileName" # profile name
},
compileBitcode: false,
destination: "export",
teamID: "*********",
signingCertificate: signing_certificate,
signingStyle: "manual",
stripSwiftSymbols: true,
thinning: ""
}
export_plist_path = File.join(output_dir, "ExportOptions.plist")
File.write(export_plist_path, export_options.to_plist)
# gym 실행 -> ipa 생성
gym(
clean: true,
scheme: "Selected Scheme",
export_method: "enterprise",
export_options: export_plist_path,
output_directory: "./output",
verbose: true
)
# gym 실행 후 임시 디렉토리에서 파일 복사 시도
# -> DistributionSummary.plist , Packaging.log 파일 복사
fastlane_require "gym"
temp_dir = Gym.cache[:temporary_output_path]
if temp_dir
FileUtils.cp(File.join(temp_dir, "DistributionSummary.plist"), output_dir) if File.exist?(File.join(temp_dir, "DistributionSummary.plist"))
FileUtils.cp(File.join(temp_dir, "Packaging.log"), output_dir) if File.exist?(File.join(temp_dir, "Packaging.log"))
end
end
end
Faselane 실행
$ fastlane build_ipa_debug
Output
다음과 같은 파일들이 생성됨을 확인 할 수 있습니다.
참조
https://jepark-diary.tistory.com/20
Fastlane을 이용한 iOS 개발 환경 (.ipa 파일 추출)
Fastlane을 이용한 iOS 개발 환경 (.ipa 파일 추출-AppStore용) 참고. https://github.com/fastlane/fastlane 1. 인증서, 프로비저닝 파일 생성 및 사용 시행착오(팀단위 개발)회사에서 팀원들과 같이 iOS 앱을 개발했
jepark-diary.tistory.com
Setup - fastlane docs
Getting started with fastlane for iOS Setup Xcode for fastlane xcode-select --install Installing fastlane fastlane can be installed in multiple ways. The preferred method is with Bundler. fastlane can also be installed directly through Homebrew (if on macO
docs.fastlane.tools
'iOS' 카테고리의 다른 글
객체 지향 프로그래밍적 사고 - 3 : OOP의 4가지 특징 (1) | 2024.08.30 |
---|---|
동기(sync)/비동기(Async) & 블로킹(blocking)/논블로킹(Non-blocking) (0) | 2024.08.22 |
객체지향 프로그래밍적 사고 - 2 (0) | 2024.08.16 |
객체지향 프로그래밍적 사고 (0) | 2024.08.13 |
.DS_Store 파일이란? (0) | 2024.04.16 |