[Fastlane] Fastlane을 통해 빌드를 자동화하자 1편

[Fastlane] Fastlane을 통해 빌드를 자동화하자 1편

이채현

노션으로 보기

What is the Fastlane?

  • ruby 코드로 만들어진 앱 배포 자동화 툴
  • 커맨드라인으로 빌드 할 수 있음
  • CI 시스템과의 통합 용이
  • 여러 구성원이 App Store에 앱을 배포하거나 단일 장치에 앱을 설치할 때 별도의 코드 서명 ID가 필요하지만, fastlane의 match를 사용하여 하나의 중앙저장소를 만들 수 있음
    • 기존 배포 인증서는 팀원 각각 만들어야 하고, 만료 기한이 있었던 것과 달리 깃 저장소에 저장된 배포 인증서로 사용 가능
    • 단, 이중인증 필요하다는 한계 존재

Run Fastlane

01. setting

fastlane 설치 및 세팅

#1. Install the latest Xcode command line tools

1
xcode-select --install

#2. ruby 2.5.0이상 버전 다운로드 필요

  • Homebrew를 이용한 설치

  • macOS Sierra 기준으로, 맥에는 이미 ruby가 설치되어 있음

  • 기본설치 되어 있는 Ruby가 오래된 버전이라면 rbenv를 다운로드 하여 버전관리를 하는 것이 좋음

    1
    brew install rbenv ruby-build
  • rbenv 초기화

  • rbenv의 설치가 완료되었다면 아래에 명령어를 실행하여 rbenv을 초기화한다.

  • 아래 명령어를 실행하면 다음과 같이 나온다

    1
    2
    3
    4
    5
    rbenv init

    ---
    # Load rbenv automatically by appending
    # the following to ~/.bashrc_profile:*eval "$(rbenv init -)"`
  • 위에 설명과 같이 .bashrc_profile 파일을 열고 아래와 같이 수정한다.

    1
    2
    3
    4
    5
    eval "$(rbenv init -)" 또는
    eval "$(rbenv init - zsh)"

    # 그리고 아래 줄을 작성한다.
    export PATH=$HOME/bin:/usr/local/bin:$PATH
    1
    source ~/.zshrc
  • 루비 2.5.0 이상 설치

    1
    2
    3
    4
    5
    rbenv install 3.1.2

    rbenv global 3.1.2 rbenv rehash

    ruby -v

#3. fastlane을 설치하는 두가지 방법

02. Init Fastlane

fastlane을 위해 사용할 폴더 구조는 다양하다. 필자는 RN 프로젝트에서 다음과 같이 사용하고 있음.

#1. 프로젝트 최상위 루트에서 init 후 아래와 같은 폴더 구조 생성

1
2
3
bundle exec fastlane init

이후 4번 선택

Untitled

Untitled

root project |_ fastlane |_ android |Fastfile | ios |Fastfile | android |_ ios

#2. Fastfile설정

1
2
3
4
5
6
7
fastlane_require 'dotenv'

before_all do
end

import("./ios/Fastfile")
import("./android/Fastfile")

#3. env 설정

  • Android와 iOS의 빌드를 위해 env를 분리시킨다.

    • 프로젝트 최상위 루트에 .env.FLAndroid, .env.FLIos 파일을 생성한다.

    env파일

    • .env.FAndroid
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # 개발

    APPCENTER_API_TOKEN={앱센터 토큰}
    APPCENTER_OWNER_NAME={"앱센터 사용자 이름"}
    APPCENTER_APP_NAME={"앱센터 앱 이름"}
    APPCENTER_DISTRIBUTE_APK="./android/app/build/outputs/apk/development/release/app-development-release.apk"

    # 상용

    JSON_KEY={"플레이스토어 API 액세스 키"}
    STORE_DISTRIBUTE_AAB="./android/app/build/outputs/bundle/productionRelease/app-production-release.aab"
    PACKAGE_NAME="앱 패키지 이름"
    • .env.FLIos
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    IOS_PROJECT_PATH="./ios/project.xcodeproj"

    SIGNING_IDENTITY_DEBUG="Apple Development: "
    SIGNING_IDENTITY_RELEASE="Apple Distribution: "

    # 개발
    MATCH_ENV_PREFIX_DEVELOPMENT="sigh_io.project.dev_development"
    MATCH_ENV_PREFIX_DEVELOPMENT_EXT="sigh_io.project.dev.OneSignalNotificationServiceExtension-Dev_development"

    MATCH_ENV_PREFIX_ADHOC="sigh_io.project.dev_adhoc"
    MATCH_ENV_PREFIX_ADHOC_EXT="sigh_io.project.dev.OneSignalNotificationServiceExtension-Dev_adhoc"

    APPCENTER_API_TOKEN=앱센터 토큰
    APPCENTER_OWNER_NAME="앱센터 사용자 이름"
    APPCENTER_APP_NAME="앱센터 앱 이름"
    APPCENTER_DISTRIBUTE_IPA="./projectDev.ipa"

    # 상용
    MATCH_ENV_PREFIX_APPSTORE="sigh_io..project.app_appstore"
    MATCH_ENV_PREFIX_APPSTORE_EXT="sigh_io.project.app.OneSignalNotificationServiceExtension-Prod_appstore"

    STORE_DISTRIBUTE_IPA="./project.ipa"

#4. env 로드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
platform :android do
before_all do
Dotenv.overload '../.env.FLAndroid'
...
end
...
en

----------------------------------------------

platform :ios do
before_all do
Dotenv.overload '../.env.FLIos'
...
end
...
en

#5. Appfile 셋팅 (환경변수 파일)

  • 필요에 따라 작성하면 된다.
1
2
3
4
5
# app_identifier('io.project') # The bundle identifier of your app
apple_id('[email protected]') # Your Apple email address

# itc_team_id('####') # App Store Connect Team ID
# team_id("ABCDE") # Developer Portal Team ID

03. How to Run Fastlane

local에 설치 된 ruby 버전이 아닌 프로젝트에서 지정한 ruby버전을 사용하기 위해 bundle exec 명령어를 이용

1
2
bundle update --bunder
bundle exec fastane ....

Install Plugin

1
2
3
4
5
bundle exec fastlane add_plugin appcenter
bundle exec fastlane add_plugin load_json
bundle exec fastlane add_plugin yarn

# ... 등등 필요한 플러그인을 추가한다.
  • add plugin 이후, fastlane 폴더 내 Pluginfile이 생성

    1
    2
    3
    4
    5
    6
    7
    # Autogenerated by fastlane
    #
    # Ensure this file is checked in to source control!

    gem 'fastlane-plugin-appcenter'
    gem 'fastlane-plugin-load_json'
    gem 'fastlane-plugin-yarn'
  • Pluginfile 생성 체크 후, 프로젝트 루트 디렉토리에 Gemfile 내에 생성된 경로와 일치한지 확인하기

    1
    2
    3
    4
    ...

    plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
    eval_gemfile(plugins_path) if File.exist?(plugins_path)
  • 마무리

    1
    2
    bundle install
    # 이후, Gemfile.lock에 추가한 플러그인이 생겼는지 확인
[Ubuntu] Certbot을 이용한 인증서 발급하기

[Ubuntu] Certbot을 이용한 인증서 발급하기

노션에서 보기

이채현

snapd 설치하기 (snapd 없는 경우)

최신 버전의 우분투에는 snapd가 설치되어있는 것으로 알고 있음

1
2
3
4
# apt # snap
# Ubuntu
sudo apt install snapd
sudo reboot

certbot 설치하기 (snap)

1
2
3
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

cloudflare plugin 설치하기

1
2
3
# dns  cloudflare
sudo snap set certbot trust-plugin-with-root=ok
sudo snap install certbot-dns-cloudflare

cloudflare api token 넣기

1
2
3
4
5
6
mkdir -p ~/.secrets/certbot
vi ~/.secrets/certbot/cloudflare.ini
----------------------------------
# Cloudflare API token used by Certbot
dns_cloudflare_api_token = IdgrE2pGEQxdq43kQPJ8*****************
chmod 600 ~/.secrets/certbot/cloudflare.ini

자신의 도메인 인증서 등록하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# *.4084.live
sudo certbot certonly --dns-cloudflare \\
--dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \\
-d *.4084.live

-----------------
ubuntu@dev-project-app:~$ sudo certbot certonly --dns-cloudflare \\
> --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \\
> -d *.4084.live
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
<https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf>. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
Requesting a certificate for *.4084.live
Waiting 10 seconds for DNS changes to propagate

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/4084.live/fullchain.pem
Key is saved at: /etc/letsencrypt/live/4084.live/privkey.pem
This certificate expires on 2022-02-26.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: <https://letsencrypt.org/donate>
* Donating to EFF: <https://eff.org/donate-le>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

생성된 인증서 경로 /etc/letsencrypt/live/4084.live/fullchain.pem /etc/letsencrypt/live/4084.live/privkey.pem

인증서 갱신하기

1
2
3
4
5
#     (--dry-run)
sudo certbot renew --dry-run

#(xx )
sudo certbot renew

crontab을 이용하여 주기적으로 갱신

(매주 일요일 2시 1분에 실행)

1
2
3
4
crontab -e
-----------
# cert renewal
1 2 * * 0 sudo /usr/bin/certbot renew

참고링크


[Ubuntu] EC2 Ubuntu에 접속 후 초기 셋팅

[Ubuntu] EC2 Ubuntu에 접속 후 초기 셋팅

노션에서 보기

이채현

인스턴스를 생성할 때 키페어 생성하여 위치확인하기

키 페어 저장

다운로드 한 키페어를 ~/.ssh 폴더 안에 위치시키고 권한을 600으로 변경한다

1
2
cp ~/Downloads/{keypair-name.pem} ~/.ssh/AWS
chmod 600 {keypair-name.pem}

접속

1
ssh -i ./{keypair-name.pem} ubuntu@{public ipv4 주소}

로그인 후

패키지 업데이트

1
2
sudo apt update
sudo apt upgrade

hostname 변경

1
2
sudo hostnamectl set-hostname {원하는 이름}
# 재접속

타임존 변경

1
sudo timedatectl set-timezone Asia/Seoul

개인PC에서 간단히 접속하기

ssh명령어를 이용하여 접속할 때에는 인증키의 위치를 계정명, 주소를 같이 입력해줘야하는 번거로움이 있다.

이를 개인pc의 인증서를 등록하여 인증서없이 바로 로그인해보자

id_rsa 키 생성하기 (개인-Mac)

1
2
cd ~/.ssh
ssh-keygen

이후 ~/.ssh 폴더 내부에 생성 된 id_rsa(private) id_rsa.pub(public) 두개의 키를 확인할 수 있다.
이 중 id_rsa.pub의 내용을 복사한다.

authorized_keys 수정하기 (원격-Ubuntu)

1
2
vim ~/.ssh/authorized_keys
위에서 복사한 id_rsa.pub 내용을 붙여넣고 저장한다.
[MySQL] 사용자 계정 생성 및 삭제, 권한관리

[MySQL] 사용자 계정 생성 및 삭제, 권한관리

MySQL 접속

1
2
3
sudo mysql 
-------------------
mysql -u root -p

새로운 유저 생성

1
mysql> CREATE USER 'username'@'host' IDENTIFIED WITH authentication_plugin BY 'password';

사용자 계정 삭제

1
mysql> DROP USER 'user명'@'server명';


새로운 데이터베이스 생성

1
2
mysql> CREATE DATABASE test;
mysql> SHOW DATABASES;

특정 계정에 모든 데이터베이스 사용 권한 부여

1
2
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
mysql> FLUSH PRIVILEGES;

특정 계정에 특정 데이터베이스 사용 권한 부여

1
2
mysql> GRANT ALL PRIVILEGES ON 데이터베이스이름.* TO 'username'@'localhost';
mysql> FLUSH PRIVILEGES;

특정 권한 부여

1
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER ON 'database명'.'tabel명' TO 'user명'@'server명';

모든 권한 삭제

1
mysql> REVOKE ALL ON 'database명'.'table명'FROM 'user명'@'server명';

특정 권한 삭제

1
mysql>  REVOKE INSERT, DROP ON 'database명'.'table명'FROM 'user명'@'server명';
[AWS] EC2 Ubuntu에서 MySQL 사용하기

[AWS] EC2 Ubuntu에서 MySQL 사용하기

Ubuntu 패키지 정보 업데이트

1
2
sudo apt update
sudo apt upgrade

MySQL 설치

1
sudo apt install -y mysql-server

MySQL 기본 세팅

1
2
3
sudo ufw allow mysql # 외부 접속 기능 설정 (포트 3306 오픈)
sudo systemctl start mysql # Mysql 실행
sudo systemctl enable mysql # Ubuntu 서버 재시작시 Mysql 자동 재시작

MySQL 외부접속 설정

1
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

bind-address를 127.0.0.1 -> 0.0.0.0 으로 변경

MySQL 언어셋 한글 설정

1
sudo vi /etc/mysql/my.cnf

맨 밑에 다음 코드 첨부

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[client]
default-character-set = utf8

[mysqld]
init_connect = SET collation_connection = utf8_general_ci
init_connect = SET NAMES utf8
character-set-server = utf8
collation-server = utf8_general_ci

[mysqldump]
default-character-set = utf8

[mysql]
default-character-set = utf8
1
2
3
sudo systemctl restart mysql # Mysql 재실행
sudo mysql # MySQL 접속
mysql> status;

MySQL 상태확인

1
sudo systemctl status mysql


MySQL 사용자 등록 및 권한 설정

1
2
mysql> create user '계정이름'@'%' identified by '패스워드';
mysql> grant all privileges on *.* to '계정이름'@'%' with grant option;

인스턴스 인바운드 규칙 설정


외부에서 MySQL 접속확인

MySQL Workbench를 이용하여 접속확인을 한다.

[RPI] 라즈베리파이에서 CRIU 작동시키기

[RPI] 라즈베리파이에서 CRIU 작동시키기

라즈베리파이, OS, Kernel, Docker, Criu… 이 다섯개의 각 버전들은 매우 다양하며 checkpoint와 restore 기능이 작동하는 적당한 버전을 찾기까지 많은 노가다 작업이 있었다.

사용 버전

기기: 라즈베리파이 3B

OS: Ubuntu Mate 16.04.2

Kernel: rpi-4.12.y

Docker version: 17.06.0~CE

Criu version: 3.11


작업

1. 기기에 OS설치

라즈베리파이 3B버전을 이용한 이유는 Ubuntu Mate 16.04버전이 4B버전을 지원하지 않아서다.

16.04버전을 사용하려는 이유를 대충 요약하자면 criu를 사용할 때, 안정적으로 동작한 Docker의 버전은 17.X이였고, 이 버전은 우분투 18.X 버전부터 정상적으로 동작하지 않았다. 그래서 16.04를 사용한다.

2. Docker 설치

wget을 이용하여 다운, dpkg를 이용하여 설치

1
2
3
# wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/armhf/docker-ce_17.06.0~ce-0~ubuntu_armhf.deb

# dpkg -i docker-ce_17.06.0~ce-0~ubuntu_armhf.deb

3. Criu 설치

1
apt install criu

위 코드로도 설치가 가능하나, 아래로 설치하겠음. (특정 버전 설치를 위함)

1
2
3
4
5
6
curl -O -sSL http://download.openvz.org/criu/criu-3.11.tar.bz2
tar xjf criu-3.11.tar.bz2
cd criu-3.11
make
cp ./criu/criu /usr/local/bin
cd

4. Kernel config 수정

커널의 설정을 criu linux kernel 이 사이트대로 수정해야하지만, 이것은 x86_64 용인 것같고, arm용으로 설정을 약간 더 손봤다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CONFIG_CHECKPOINT_RESTORE=y
CONFIG_NAMESPACES=y
CONFIG_UTS_NS=y
CONFIG_IPC_NS=y
CONFIG_SYSVIPC_SYSCTL=y
CONFIG_PID_NS=y
CONFIG_NET_NS=y
CONFIG_FHANDLE=y
CONFIG_EVENTFD=y
CONFIG_EPOLL=y
CONFIG_UNIX_DIAG=y
CONFIG_INET_DIAG=y
CONFIG_INET_UDP_DIAG=m
CONFIG_PACKET_DIAG=y
CONFIG_NETLINK_DIAG=y
CONFIG_NETFILTER_XT_MARK=m
CONFIG_TUN=y

CONFIG_PROC_PAGE_MONITOR=y
CONFIG_VDSO=n
CONFIG_IDLE_PAGE_TRACKING=y

참고

라즈베리파이… ARM는 soft-dirty기능을 미지원 à “CONFIG_MEM_SOFT_DIRTY”가 없음

대신 “CONFIG_PROC_PAGE_MONITOR=y” 이는 Dumpee 메모리 레이아웃에 대한 정보를 얻기 위해 필요하다고 함.

그리고 ARM에는 VDSO라는 매개변수가 없으므로 “CONFIG_VDSO=n” 셋팅을 해야 VDSO 때문에 덤프가 실패하는 것을 피할 수 있음. à 비활성화 시, signal trampoline(?)이 ARM의 VDSO페이지가 아닌 SIG페이지에 자동으로 배치됨.

컴파일 후에 적용하고 재부팅을 하면 기본 설정은 끝이다.


테스트

docker와 busy box를 이용하여 체크포인트와 복구를 테스트

1
2
3
4
5
sudo docker run --name counter busybox /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done'

sudo docker checkpoint create counter cp1

sudo docker start -a --checkpoint cp1 counter

테스트영상

[Linux] 리눅스에서 압축 및 해제 하는법

[Linux] 리눅스에서 압축 및 해제 하는법

1. tar 압축

1
2
3
4
> tar -cvf [파일명.tar] [폴더명]

ex) abc라는 폴더를 aaa.tar로 압축하고자 한다면
> tar -cvf aaa.tar abc

2. tar 압축풀기

1
2
3
4
> tar -xvf [파일명.tar]

ex) aaa.tar라는 tar파일 압축을 풀고자 한다면
> tar -xvf aaa.tar

3. tar.gz 압축

1
2
3
4
> tar -zcvf [파일명.tar.gz] [폴더명]

ex) abc라는 폴더를 aaa.tar.gz로 압축하고자 한다면
> tar -zcvf aaa.tar.gz abc

4. tar.gz 압축풀기

1
2
3
4
> tar -zxvf [파일명.tar.gz]

ex) aaa.tar.gz라는 tar.gz파일 압축을 풀고자 한다면
> tar -zxvf aaa.tar.gz

5. zip 압축

1
2
3
4
> zip [파일명.zip] [폴더명]

ex) abc라는 폴더를 aaa.zip으로 압축하고자 한다면
> zip aaa.zip abc

6. zip 압축풀기

1
2
3
4
5
6
7
> unzip [파일명.zip]

ex) aaa.zip라는 zip파일 압축을 풀고자 한다면
> unzip aaa.zip

ex) 특정 폴더에 압축풀기
> unzip aaa.zip -d ./target

자주 쓰는 tar 옵션 명령어

옵션 설명
-c 파일을 tar로 묶음
-p 파일 권한을 저장
-v 묶거나 파일을 풀 때 과정을 화면으로 출력
-f 파일 이름을 지정
-C 경로를 지정
-x tar 압축을 풂
-z gzip으로 압축하거나 해제함
[AWS] Start Amazon EC2

[AWS] Start Amazon EC2

Select Instance(Amazon Linux2 AMI) With t2.micro

Configure Security group - Add types [SSH(22), HTTP(80)]

Instance Spec

[AWS] Amazon Web Service's survey

[AWS] Amazon Web Service's survey

Survey (EC2, Auto Scaling, S3, RDS)

What is Amazon EC2?

Abbreviation for Amazon Elastic Compute Cloud, it provides scalable computing capacity in the Amazon Web Services (AWS) cloud.

With Amazon EC2, you can,

  • Build as many virtual servers as you want,
  • Manage security, network configuration, storage
  • •Reduces the need to predict server traffic more

What is Amazon Auto Scaling?

With AWS Auto Scaling, you can configure automatic scaling of the AWS resources in your application in minutes.

Amazon Auto Scaling monitors your application,

  • Set up scaling quickly,
  • Make smart scaling decisions,
  • Maintain performance automatically,
  • Reliable,
  • Pay only for what you need. (the lowest possible cost) more

What is Amazon S3?

Abbreviation for Amazon Simple Storage Service, it provides storage through a web service interface.

With Amazon S3, you can easily

  • Organize your data,
  • Fine-grained access controls according to your specific business, organization, and compliance requirements.
  • Designed to provide 99.999999999% durability more

What is Amazon RDS?

Abbreviation for Amazon Relational Database Service, Amazon RDS is a web service that operates in the cloud.

With it, you can easily

  • Set up, Operate, and Scale your relational database in the cloud.
  • Automate Hardware provisioning, Database setup, Patching and Backups more

Survey (Detail Specification of EC2)

Instance Types:

It is divided into “General purpose(T2, T3…)”, “Computing optimization(C4, C5…)”, “Memory optimization(z1d, R5…)”, “Accelerated computing(P4…)”, and “Storage optimization(H1, I3…)”. more

Pricing Plans:

  • On-Demand Instance - You are charged for what you use. However, since the unit of billing is 1 minute, even if you use 1 second, you will be charged 1 minute.
  • Spot Instance – You can use EC2 resources that are not currently in use by receiving a cheap bid at auction. They are offered at a discount of up to 90% compared to the On-Demand rate.
  • Reserved Instance - When you reserve the usage period (1 or 3 years) and usage (No/Partial/All Upfront) and pay the initial prepayment, you receive a discount on the hourly usage fee. more