jenkins
amazon linux2
t3.medium
--- 젠킨스 설치 https://www.jenkins.io/download/
$ sudo su -
# timedatectl set-timezone Asia/Seoul
# yum update -y
# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
# amazon-linux-extras install epel -y
# amazon-linux-extras install -y java-openjdk11
# yum install -y jenkins
# systemctl enable --now jenkins
# cat /var/lib/jenkins/secrets/initialAdminPassword # 패스워드 수정
# 도커 설치
amazon-linux-extras install docker -y
systemctl start docker && systemctl enable docker
curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
usermod -a -G docker ec2-user
# 도커 그룹에 추가
Jenkins 사용자를 Docker 그룹에 추가하는 방법은 다음과 같습니다:
Jenkins 서버에 SSH로 로그인합니다.
sudo usermod -aG docker jenkins 명령을 실행하여 Jenkins 사용자를 docker 그룹에 추가합니다. (jenkins는 Jenkins 서버에서 사용되는 Jenkins 사용자 이름입니다. 시스템에 따라 다를 수 있습니다.)
sudo service jenkins restart 명령을 실행하여 Jenkins 서버를 재시작합니다.
이제 Jenkins 서버의 Jenkins 사용자는 Docker 그룹에 속하므로 Docker 데몬에 액세스할 수 있어야 합니다. 파이프라인을 다시 실행해보세요. 문제가 계속되면 다른 해결 방법을 시도해야 할 수도 있습니다
# git 설치
yum install git
Plugin: docker pipeline, nodejs plugin,Amazon ECR, AWS Global Configuration, Slack Notification(구성 = megazone-finalproject,token)
Credential: git token, dockerhub token (eeapbh, docker-hub, docker-hub), ecr, slack (secret text)
Developer Settings -> token
token 설정
사용자 이름은 Docker Hub 사용자 이름이어야 하고 비밀번호는 Docker Hub 비밀번호 또는 액세스 토큰이어야 합니다.
nodejs plugin 설치하고
git webhooks랑 crediential 똑같이 해주고
pipeline {
agent any
environment {
SLACK_CHANNEL = '#jenkins'
}
stages {
stage ('Clone repository') {
steps{
checkout scm
slackSend (channel: SLACK_CHANNEL, color: '#FFFF00', message: "==================================================================\nDEPLOY PIPELINE START !!!!!\nSTARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' ")
}
}
stage('React Build') {
steps{
nodejs(nodeJSInstallationName: '16.20.1'){
sh "npm install"
sh "npm run build"
}
}
post {
success {
slackSend (channel: SLACK_CHANNEL, color: '#00FF00', message: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' React Build SUCCESS.")
}
failure {
slackSend (channel: SLACK_CHANNEL, color: '#FF0000', message: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' React Build FAIL")
}
}
}
stage ('Build image for ECR') {
steps{
script{
app = docker.build("869906837484.dkr.ecr.ap-northeast-2.amazonaws.com/myapp", "--build-arg ENVIRONMENT=${env} .")
}
}
post {
success {
slackSend (channel: SLACK_CHANNEL, color: '#00FF00', message: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' ECR Image Build SUCCESS.")
}
failure {
slackSend (channel: SLACK_CHANNEL, color: '#FF0000', message: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' ECR Image Build FAIL")
}
}
}
stage ('Push image to ECR') {
steps{
script{
docker.withRegistry('http://869906837484.dkr.ecr.ap-northeast-2.amazonaws.com', 'ecr:ap-northeast-2:infra_admin') {
app.push("mzc-final-front-v3.0.${env.BUILD_NUMBER}")
app.push("mzc-final-front-latest")
}
}
}
post {
success {
slackSend (channel: SLACK_CHANNEL, color: '#00FF00', message: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' ECR Image Push SUCCESS.")
}
failure {
slackSend (channel: SLACK_CHANNEL, color: '#FF0000', message: "'${env.JOB_NAME} [${env.BUILD_NUMBER}]' ECR Image Push FAIL")
}
}
}
stage('Update mzc-final-front image tag'){
steps{
withCredentials([usernamePassword(credentialsId: 'eeapbh', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
git credentialsId: 'eeapbh',
url: 'https://github.com/eeapbh/mzc-final-infra.git',
branch: 'master'
sh("""
#!/usr/bin/env bash
git config --local credential.helper "!f() { echo username=\\$GIT_USERNAME; echo password=\\$GIT_PASSWORD;}; f"
sed -i 's/mzc-final-front-.*\$/mzc-final-front-v3.0.${currentBuild.number}/g' app/front-deployment.yaml
git add app/front-deployment.yaml
git commit -m 'update mzc-final-front image tag'
git push origin master
""")
}
}
}
}
post {
success {
slackSend (channel: SLACK_CHANNEL, color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'DEPLOY SUCCESS!! \n==================================================================")
}
failure {
slackSend (channel: SLACK_CHANNEL, color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'DEPLOY FAIL!! \n==================================================================")
}
}
}
mobaXterm docker vm 키고 테스트
git clone https://github.com/eeapbh/mzc-final-back.git
docker build -t mzc-final-back:v1.0 .
docker tag mzc-final-back:v1.0 eeapbh/mzc-final-back:v1.0
docker push eeapbh/mzc-final-back:v1.0
test 하고싶은 vm켜서
docker pull eeapbh/mzc-final-back:v1.0
sudo dkcer run -d --name bongtestback1 -p 8080:5000 -dt eeapbh/mzc-final-back:v1.0
git clone https://github.com/eeapbh/mzc-final-front.git
레포 만들고
vm하나 켜서
aws configure
설정다하고
태깅작업하고 ecr로 push
[Jenkins] Amazon ECR plugin
[Jenkins] AWS Global Configuration Plugin
설치하고
https://2zzangho.tistory.com/86
overlay2 Cache 사용량 정리
docker system prune -a -f
-> 볼륨 용량 20GB으로 해결완료
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl -n argocd get po,service,configmap,secret
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
시간 좀 지나고 들어가면 들어가짐
비밀번호 확인하고
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
admin, 비번으로 로그인 ㄱ
https://sungwook-choi.gitbook.io/argocd/private-repository/git-private-repo
https://junhyunny.github.io/information/jenkins/jenkins-slack-notification/
#!/bin/bash
sudo timedatectl set-timezone Asia/Seoul
sudo yum update -y
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo amazon-linux-extras install epel -y
sudo amazon-linux-extras install -y java-openjdk11
sudo yum install -y jenkins
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-0f19a713e170da651.efs.ap-northeast-2.amazonaws.com:/ /var/lib/jenkins
echo "fs-0f19a713e170da651.efs.ap-northeast-2.amazonaws.com:/ /var/lib/jenkins nfs" >> /etc/fstab
sudo amazon-linux-extras install docker -y
sudo systemctl start docker && systemctl enable docker
sudo curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
sudo usermod -a -G docker ec2-user
sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
. ~/.nvm/nvm.sh
nvm install 16
sudo usermod -aG docker jenkins
sudo systemctl enable --now jenkins
sudo yum install -y git
pvt 2a, 2c에 젠킨스 인스턴스 생성하고 로벨만들어서 대상그룹
80 - 8080
대상선택 구성 고정 설정까지 (안그러면 로그인할때 에러남)
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-08285fbb9000759f3.efs.ap-northeast-2.amazonaws.com:/ /var/lib/jenkins
회원가입
로그인
수강 과목 리스트
수강 신청 상세 페이지
monitoring management 페이지