主要記錄一下過(guò)程新的
docker環(huán)境
參考 菜鳥教程(https://www.runoob.com/docker/centos-docker-install.html)
安裝所需的軟件包傍衡。yum-utils 提供了 yum-config-manager ,并且 device mapper 存儲(chǔ)驅(qū)動(dòng)程序需要 device-mapper-persistent-data 和 lvm2。
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
使用以下命令來(lái)設(shè)置穩(wěn)定的倉(cāng)庫(kù)
# 官方鏡像
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
docker-compose環(huán)境
參考 菜鳥教程(https://www.runoob.com/docker/docker-compose.html)
安裝包發(fā)布地址: https://github.com/docker/compose/releases
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 1.28.2 是版本號(hào),可以去 https://github.com/docker/compose/releases 找最新的版本號(hào)
docker-compose.yml
version: '3.7'
networks:
dep:
services:
# docker 私服
registry:
image: registry:2
container_name: registry
restart: always
networks:
dep:
aliases:
- registry
ports:
- "5000:5000"
volumes:
- /var/lib/registry:/var/lib/registry
# jenkins 部署
jenkins:
image: jenkins/jenkins:lts
container_name: jenkins
restart: always
networks:
dep:
aliases:
- jenkins
ports:
- "8080:8080"
- "50000:50000"
volumes:
- /etc/localtime:/etc/localtime # 時(shí)區(qū)
- /var/jenkins_home:/var/jenkins_home # 這個(gè)地方需要注意給jenkins_home權(quán)限偿乖,不然無(wú)法啟動(dòng)成功:執(zhí)行:sudo chown -R 1000 jenkins_home
- /usr/bin/docker:/usr/bin/docker
- /var/run/docker.sock:/var/run/docker.sock
- /usr/lib64/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
user: root # 解決容器中執(zhí)行docker權(quán)限問(wèn)題
# 用來(lái)測(cè)試自動(dòng)化構(gòu)建的vue工程
vue3play:
image: 127.0.0.1:5000/vue3-play:latest
container_name: vue3play
restart: always
networks:
dep:
aliases:
- vue3play
jenkins docker命令問(wèn)題,以及權(quán)限問(wèn)題
參考:https://www.isolves.com/it/cxkf/rongqi/2020-11-06/32886.html
構(gòu)建命令
選擇自由風(fēng)格:執(zhí)行shell
pwd
docker build -t vue3-play .
docker tag vue3-play:latest 127.0.0.1:5000/vue3-play:latest
docker push 127.0.0.1:5000/vue3-play
ssh遠(yuǎn)程執(zhí)行命令
cd /home/ly # 你的docker-compose.yml文件路徑
sh restart-dc.sh
附上 restart-dc.sh
只是簡(jiǎn)單的啟動(dòng)docker-compose
乌妒,然后清理none的image
#!/bin/bash
echo "--start docker-compose up -d"
cd /home/ly
docker-compose up -d
echo "--start rmi none image"
docker rmi $(docker images | grep "none" | awk '{print $3}')
vue3-play 參考來(lái)源于 vue-cli
Dockerfile
FROM node:14.15.4-alpine3.10
COPY ./ /app
WORKDIR /app
RUN npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
RUN npm install --registry=https://registry.npm.taobao.org && npm run build
FROM nginx
RUN mkdir /app
COPY --from=0 /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
github webhook
通過(guò)github給jenkins觸發(fā)構(gòu)建任務(wù)
參考:https://blog.csdn.net/qq_38588845/article/details/112404336
- 先配置github密鑰
- jenkins添加github服務(wù)器汹想,用密鑰鏈接github
- github添加jenkins鏈接:
http(s)://jenkins的地址/github-webhook/
- 構(gòu)建項(xiàng)目中勾選
GitHub hook trigger for GITScm polling