簡單搭建CICD前端自動化構建平臺
-
安裝docker
1.先刪除舊的版本
sudo yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-engine
2.安裝依賴
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
新增stable的Docker-ce源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3.安裝docker-ce
sudo yum install docker-ce docker-ce-cli containerd.io
4.啟動docker
sudo systemctl start docker -
安裝docker-compose
1.下載docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
或者換成比較快的源:
curl -L "
2.給予執行許可權
sudo chmod +x /usr/local/bin/docker-compose
3.測試命令
docker-compose --version
docker-compose version 1.23.2, build 1110ad01
更換源:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl restart docker
systemctl daemon-reload
- 安裝gitlab-runner
- 在docker裡面註冊docker
image: node:16.3.0
stages:
- install
- build
- deploy
cache:
key: vitepro
paths:
- node_modules
job_install:
stage: install
tags:
- docker
script:
- npm config set registry http://registry.npm.taobao.org/
- npm install
job_build:
stage: build
tags:
- docker
script:
- npm run build
artifacts:
paths:
- dist/
job_deploy:
stage: deploy
image: docker
tags:
- docker
script:
- echo 'deploy'
- docker build -t jenkinsvue .
- if [ $(docker ps -aq --filter name=myvite-container) ]; then docker rm -f myvite-container;fi
- docker run -d -p 8082:80 --name myvite-container jenkinsvue
job_deploy_oss:
stage: deploy
tags:
- docker
script:
- wget http://gosspublic.alicdn.com/ossutil/1.6.18/ossutil64
- chmod 755 ossutil64
- ./ossutil64 config -e ${endPoint} -i ${accessKeyID} -k ${accessKeySecret} -L CH --loglevel debug -c ~/.ossutilconfig
- ls
- pwd
- ./ossutil64 -c ~/.ossutilconfig cp -r -f dist oss://bucketdem/
when: manual
FROM node:16.3.0 as builder
WORKDIR /app
COPY package.json .
RUN npm install --registry=http://registry.npm.taobao.org
COPY . .
RUN npm run build
FROM nginx:latest
COPY --from=builder /app/dist /usr/share/nginx/html