cd /var/lib/jenkins
sudo mkdir .ssh
cd .ssh
pwd
/var/lib/jenkins/.ssh
sudo ssh-keygen -t rsa -b 4096 -C "주석쓰"
2-2. ssh 디렉토리 선택
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /var/lib/jenkins/.ssh/id_rsa_{프로젝트명}
2-3. 기타 설정
Enter passphrase (empty for no passphrase): {보안암호 설정}
2-4. ssh-keygen Success 화면
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256: ...
The key's randomart image is:
+---[RSA 4096]----+
...
+----[SHA256]-----+
2.5 ssh-private-key, ssh-public-key 확인
cd /var/lib/jenkins/.ssh
ls -al
total 16
drwxr-xr-x 2 root root 4096 Feb 11 18:30 .
drwxr-xr-x 15 jenkins jenkins 4096 Feb 11 18:24 ..
-rw------- 1 root root 3243 Feb 11 18:30 id_rsa_{프로젝트명}
-rw-r--r-- 1 root root 749 Feb 11 18:30 id_rsa_{프로젝트명}.pub
jenkins 서버에서 생성한 ssh-public-key를 jenkins Credentials 에서 등록한다
jenkins관리 > Manage Credentials
Kind : SSH Username with private key 선택
Username : 원하는 유저명
private Key : (private Key 영역의 id_rsa 값)
pyenv build wrapper : 프로젝트의 python 버전 입력 ex(3.8.5)
해당 서버에 pyenv 관련 script가 실행되지 않는 경우, 아래와 같은 라이브러리를 설치해야한다
sudo apt install gcc
sudo apt install make
if [ ! -d "$WORKSPACE/venv" ]; then
python -m venv venv;
if [ -f $WORKSPACE/requirements.txt ]; then
. $WORKSPACE/venv/bin/activate;
pip3 install -r requirements.txt;
fi
fi
PID=`ps -ef | grep commonlife2-admin | awk '{print $2}'`
sudo kill -9 $PID
cd /var/lib/jenkins/workspace/commonlife2-admin
. venv/bin/activate
gunicorn --bind 0:9090 --access-logfile access.log --error-logfile error.log manage:gunicorn_app --daemon --reload