320x100
320x100

※ CI/CD 방식 변경
- 젠킨스를 이용한 컨테이너 제어
: github push > jenkins build > Docker image build > Docker Stack off > Docker stack on


1. Dockerfile 통합 (for Multi stage build)
: main / api / db 통합
: main 및 api 서버의 디렉터리에 각각 package.json 생성 
: Dockerfile 수정
=> 멀티 스테이지는 이런 기능이 아니므로 Dockerfile을 3개 두고 push


2. 젠킨스 옮기기
: 배포 컨테이너를 없에고 호스트OS에서 배포 서버 운영

ㆍjenkins home 확인
: vi /etc/sysconfig/jenkins
: 10번째 JENKINS_HOME
: jenkins home & workspace (/var/lib/jenkins/workspace/mohaemookji)

ㆍssl 젠킨스 연동
: Docker file 수정
: 젠킨스 및 깃허브에 ssh 수정




 

젠킨스 도커 컨테이너 참조 
https://alsyean.tistory.com/60
https://more-learn.tistory.com/26


※ 오늘의 목표 
1. 젠킨스 도커 연동
: build > Execute shell > 쉘파일 실행
: 쉘 파일 작성 필요
: push > build > deploy까지 구축


쉘 파일 flow
docker build --tag 2mukee/mh_main_image:latest /var/lib/jenkins/workspace/mohaemookji/main && docker push 2mukee/mh_main_image:latest
docker build --tag 2mukee/mh_api_image:latest /var/lib/jenkins/workspace/mohaemookji/api && docker push 2mukee/mh_api_image:latest
docker build --tag 2mukee/mh_db_image:latest /var/lib/jenkins/workspace/mohaemookji && docker push 2mukee/mh_db_image:latest
docker stack rm <스택명>
docker stack deploy -c mohaemookji-compose.yml <스택명> && echo Build Success


젠킨스 sudo 없이 실행
sudo usermod -aG jenkins $USER

Execute Shell
sudo bash /var/lib/jenkins/workspace/mohaemookji/setup.sh
=> SSL의 build 이후 실행되도록 (chmod +x setup.sh)

※ dial unix /var/run/docker.sock: connect: permission denied
: sudo chmod 666 /var/run/docker.sock

※ SSH 관련 참조 
https://mingzz1.github.io/development/basic/2021/04/19/jenkins_with_private_repo.html/

※ We trust you have received the usual lecture from the local System
: vi /etc/sudoers
jenkins ALL=(ALL) NOPASSWD:ALL

※ denied: requested access to the resource is denied
: export docker_id / pw = ~~~

※ Cannot perform an interactive login from a non TTY device
: winpty docker login -u $docker_id -p $docker_pw
: cat ~/my_password.txt | docker login --username 2mukee --password-stdin
=> 도커허브에서 토큰 생성 > login.sh 생성 (docker login -u 진짜아이디 -p 토큰) > setup.sh에서 읽기

 

참조
ㆍ젠킨스 도커
https://more-learn.tistory.com/26
https://alsyean.tistory.com/60

ㆍAWK에 대해서
https://recipes4dev.tistory.com/171



github에 올라가는 쉘파일에 대한 권한 추가 
: git update-index --chmod=+x setup.sh

재부팅 후 젠킨스 docker 권한 자동 등록
: vi /etc/rc.d/rc.local
: chmod 666 /var/run/docker.sock



300x250
728x90

'Development > Project' 카테고리의 다른 글

Hermes 개발일지  (0) 2021.10.20
Hermes_ 개발 중 공부 정리 본  (0) 2021.10.20
210929~05 모해묵지 개발일지  (0) 2021.10.19
210916~28 모해묵지 개발일지  (0) 2021.10.19
210912~15 모해묵지 개발일지  (0) 2021.10.19