When building Npm for front-end projects, it often takes a long time to pull the front-end library. In addition, reuse between different jobs is also a problem. Whether it is artifacts or cache, we need to persist the reused files. Here we take cache as an example
Note: The Gitlab runner here is deployed to the k8s cluster using the helm chart method, and the runner deployment is ignored; the ceph s3 key pair needs to be prepared in advance to configure accesskey and secretkey
cache:## General settingscacheType:s3cachePath:"devops"#Specify ceph s3 cache path, here we distinguish by departmentcacheShared:true## S3 settingss3ServerAddress:"ops-rgw.test.cn"s3BucketName:"runners-cache"s3BucketLocation:s3CacheInsecure:truesecretName:"gitlab-runner-s3"
stages:- Buildbuild-and-deploy:image:registry.test.cn/devops/node:lateststage:Buildcache:key:devops-vuepaths:- node_modules/-.yarntags:-devopstestscript:-yarn config set registry https://r.cnpmjs.org-yarn config set @test:registry https://npm.test.cn/-yarn --pure-lockfile --cache-folder .yarn --network-timeout 600000-yarn buildwhen:always
After Gitlab CI triggers the build task, we observe the real-time status of the JOB build task. At this time, the cache file has been uploaded to ceph s3, and the efficiency of later build and compilation is greatly improved!
64Creating cache devops-vue-4...65 node_modules/:found 30710 matching files and directories66 .yarn:found 34390 matching files and directories 67Uploading cache.zip to https://ops-rgw.test.cn/runners-cache/devops/project/4187/devops-vue-js-starter-468Created cache70Cleaning up file based variables00:0072Job succeeded