Notice
Recent Posts
Recent Comments
Link
관리 메뉴

김종권의 iOS 앱 개발 알아가기

[fastlane] fastlane 환경변수 사용 방법 (.env.default 사용하여 가장 간단한 match 사용방법, Certificate 갱신 방법) 본문

iOS 앱 배포와 출시

[fastlane] fastlane 환경변수 사용 방법 (.env.default 사용하여 가장 간단한 match 사용방법, Certificate 갱신 방법)

jake-kim 2022. 11. 1. 22:56

Fastlane match란?

  • Certificate, Provisioning Profile을 특정 git 레포에 저장해놓고 개발자들 사이 or ci/cd 때 쉽게 관리할 수 있는 기능
  • mathc명령어를 통해 terminal에서 Apple 개발자 사이트에 접속하여 Certificate 만들기도 가능
  • Certificate를 만들고 Provisioning Profile 생성도 같이 지정해둔 git repo에 저장하고 끌어다 쓰기가 가능
  • 사용 방법
    • 팀 내 개발자 대표자 한명은 match를 통해 certificate를 새로 만들어서 git repo에 저장 (Certs, Profiles 내용 생성)
    • 팀 개발자들은 match 명령어를 통해 certs, profiles 정보를 땡겨와서 Xcode에 세팅
      (이때 팀 개발자가 match를 통해 업데이트 시도 시, certs가 이미 존재하면 그 certs은 그대로 사용하고 profiles만 업데이트)

Fastlane match 사용 전 준비

  • 샘플 프로젝트 생성
    • com.jake.ExMatch라는 Bundle ID를 가지고 있는 프로젝트 앱

  • certs, profiles 정보가 저장될 git repo를 privarte으로 추가

환경 변수를 이용하여 Fastlane match 준비

  •  match 초기화
$ cd/root/project
$ fastlane init

4번 선택

  • /fastlane 폴더와 Appfile, Fastfile 생성된 것을 확인

  • fastlane 폴더로 이동하고 .env.default파일 생성
    • .env.default에 환경 변수를 저장해놓으면, fastlane 하위에서 변수명으로 접근이 가능
    • ex) ABC 환경 변수 값 접근 -> ENV['ABC']
cd fastlane
vi .env.default
  • .env.default에 필요한 환경변수 입력
    • GIT_BRANCH: certs, profiles이 저장되는 레포의 타겟 브랜치
    • APP_IDENTIFIER: 콤마로 여러개 설정 가능 (한 프로젝트에 여러개의 Bundle ID가 존재할때)
    • ex) 여러개의 Bundle ID: iOS와 Watch 앱 둘 다 지원하는 경우 타겟이 두개 이므로 Bundle ID도 두 개 존재
GIT_BRANCH="master"
APP_IDENTIFIER="com.jake.ExMatch,com.jake.ExMatch2"
APPLE_ID="someID@google.com"
TEAM_ID="SS71UUJNK"
  • fastlane/Appfile에 App의 기본 정보 입력
app_identifier(ENV['APP_IDENTIFIER'])
apple_id(ENV['APPLE_ID'])
team_id(ENV['TEAM_ID'])
  • match 파일을 만들어서 이곳에서 certs, profiles 저장 및 관리하는 정보 입력
$ cd/project/root
fastlane match init

1번 선택

  • 위에서 만든 certs, profiles 정보가 저장될 git repo의 주소 입력
    • 생성된 Matchfile 확인

  • Matchfile 내용 업데이트

as-is

git_url("https://github.com/JK0369/ExMatch-match.git")

storage_mode("git")

type("development")

to-be

git_url("https://github.com/JK0369/ExMatch-match.git")
git_branch(ENV['GIT_BRANCH'])
storage_mode("git")
type("development")

app_identifier(ENV['APP_IDENTIFIER'].split(","))
username(ENV['APPLE_ID'])
team_id(ENV['TEAM_ID'])

Matchfile 사용 방법

  • 팀 내 개발자 대표자 한명은 match를 통해 certificate를 새로 만들어서 git repo에 저장 (Certs, Profiles 내용 생성)
    • 명령어를 입력하면 terminal에서 MatchFile에 입력된 username과 app_identifier를 참고하여 Apple Developer에 Certificates를 새로 생성하고 Profiles도 자동으로 추가
$ cd/project/root
$ fastlane match development

위 명령어 입력 시, Passphrase 입력할때 주의할 점: 이 비밀번호는 따로 기록하여 개발자 팀원들과 공유

passphrase 입력

완료)

  • Apple Developer에 Certificates가 생성 (기존에 없었다면)

이곳에 Certificate 생성

  • Apple Developer에 Profiles도 생성되고 git repo에도 certs, profiles 생성

  • 팀 개발자들은 match 명령어를 통해 certs, profiles 정보를 땡겨와서 Xcode에 세팅
    (이때 팀 개발자가 match를 통해 업데이트 시도 시, certs가 이미 존재하면 그 certs은 그대로 사용하고 profiles만 업데이트)
$ cd/project/root
fastlane match development --readonly

기존에 사용하던 development certificate가 invalid된 경우 대처 방법

  • certs, profile이 저장된 repo에서 certs/development 폴더 아예 삭제 (삭제 안하면 업뎃이 안됨)
  • 애플 개발자 페이지에서 invalid된 certificate가 남아있다면 삭제
  • fastlane으로 certs를 만든 후, profile 생성하면 완료
fastlane match development

* 전체 코드: https://github.com/JK0369/ExMatch-fastlane

 

* 참고

https://docs.fastlane.tools/best-practices/keys/

Comments