Я очень новичок в Gitlab и не знаю, как правильно его настроить.Я хочу знать, как мы можем ускорить процесс CI в Gitlab, потому что в настоящее время мой проект занимал до 20 м, чтобы завершить процесс проверки, сборки и развертывания.
Я считаю, что причина в том, что каждая работа делает другуюбежать за npm install
или yarn install
.Я определил кэш следующим образом, но он не ускорил процесс:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
первое изображение, которое я использую, - docket:git
, должен ли я изменить его на другое изображение, чтобы я мог запустить npm install
в before_script
?Или есть другой способ ускорить процесс gitlab ci?
EDIT : добавьте файл gitlab-ci.yml, я удалил некоторую конфиденциальную информацию, в основном, то же самое, что и яб
image: docker:git
stages:
- build
- build-image
- build-staging
- build-image-staging
- build-production
- build-image-production
- release
- checkstyle #TO move up
- test #To move up
- deploy
variables:
CONTAINER_IMAGE: registry
HOST: ""
IP: ""
DOCKER_DRIVER: overlay2
before_script:
- git checkout -B "$CI_COMMIT_REF_NAME" "$CI_COMMIT_SHA"
- echo "CI_BUILD_REF_NAME = "$CI_BUILD_REF_NAME
- BRANCH=$(git rev-parse --abbrev-ref HEAD) && echo "BRANCH = "$BRANCH
- ID=$(git rev-list --count $BRANCH) && echo "ID = "$ID
- TAG=$(git describe --abbrev=0 --tags || true) && echo "TAG = "$TAG
- REGISTRY=$CONTAINER_IMAGE":"$ID"_"$BRANCH
- DATE=`date '+%Y-%m-%d %H:%M:%S'`
- echo $'\n\n----------\n'"REGISTRY = "$REGISTRY$'\n'"COMMIT = "$CI_COMMIT_SHA$'\n'"BRANCH = "$BRANCH$'\n'"DATE = "$DATE$'\n----------\n\n'
# - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.example.com
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
analysis-lint:
image: node:latest
stage: checkstyle
script:
- npm install
- ./node_modules/@angular/cli/bin/ng lint --type-check
build-integration:
stage: build
image: node
script:
- yarn install
- ./node_modules/@angular/cli/bin/ng build ---prod --configuration=integration --aot --output-hashing all --source-map=false
- npm run webpack:server
artifacts:
paths:
- dist
only:
- develop
build-testing:
stage: build
image: node
script:
- yarn install
- ./node_modules/@angular/cli/bin/ng build ---prod --configuration=testing --aot --output-hashing all --source-map=false
- npm run webpack:server
artifacts:
paths:
- dist
only:
- /^release.*$/
build-staging:
stage: build-staging
image: node
script:
- yarn install
- ./node_modules/@angular/cli/bin/ng build ---prod --configuration=staging --aot --output-hashing all --source-map=false
- npm run webpack:server
artifacts:
paths:
- dist
only:
- /^hotfix.*$/
- master
build-production:
stage: build-production
image: node
script:
- yarn install
- ./node_modules/@angular/cli/bin/ng build ---prod --configuration=production --aot --output-hashing all --source-map=false
- npm run webpack:server
artifacts:
paths:
- dist
only:
- master
build-image-integration:
stage: build-image
script:
- docker build -t $REGISTRY-integration -f Dockerfile --build-arg ENVIRONMENT=integration .
- docker push $REGISTRY-integration
only:
- develop
- universal
build-image-testing:
stage: build-image
script:
- docker build -t $REGISTRY-testing -f Dockerfile --build-arg ENVIRONMENT=testing .
- docker push $REGISTRY-testing
only:
- /^release.*$/
build-image-staging:
stage: build-image-staging
script:
- docker build -t $REGISTRY-staging -f Dockerfile --build-arg ENVIRONMENT=staging .
- docker push $REGISTRY-staging
only:
- /^hotfix.*$/
- master
build-image-production:
stage: build-image-production
script:
- docker build -t $REGISTRY-production -f Dockerfile --build-arg ENVIRONMENT=production .
- docker push $REGISTRY-production
only:
- master
release-image-integration:
stage: release
script:
- docker pull $REGISTRY-integration
- docker tag $REGISTRY-integration $CONTAINER_IMAGE:$BRANCH
- docker push $CONTAINER_IMAGE:$BRANCH
only:
- develop
- universal
release-image-testing:
stage: release
script:
- docker pull $REGISTRY-testing
- docker tag $REGISTRY-testing $CONTAINER_IMAGE:$BRANCH
- docker push $CONTAINER_IMAGE:$BRANCH
- docker tag $REGISTRY-testing $CONTAINER_IMAGE:release
- docker push $CONTAINER_IMAGE:release
only:
- /^release.*$/
release-image-staging:
stage: release
script:
- docker pull $REGISTRY-staging
- docker tag $REGISTRY-staging $CONTAINER_IMAGE:$BRANCH-staging
- docker push $CONTAINER_IMAGE:$BRANCH-staging
only:
- /^hotfix.*$/
- master
release-image-master:
stage: release
script:
- docker pull $REGISTRY-production
- docker tag $REGISTRY-production $CONTAINER_IMAGE:$BRANCH
- docker push $CONTAINER_IMAGE:$BRANCH
only:
- master
release-image-latest:
stage: release
script:
- docker pull $REGISTRY-production
- docker tag $REGISTRY-production $CONTAINER_IMAGE:latest
- docker push $CONTAINER_IMAGE:latest
- docker tag $REGISTRY-production $CONTAINER_IMAGE
- docker push $CONTAINER_IMAGE
only:
- master
release-image-production:
stage: release
script:
- if [ ! -z "$TAG" ]; then docker pull $REGISTRY-production;docker tag $REGISTRY-production $CONTAINER_IMAGE:$TAG;docker push $CONTAINER_IMAGE:$TAG;fi;
only:
- master
#- /^release.*$/
#- /^hotfix.*$/
development:
stage: deploy
image: appropriate/curl
script:
- echo "Deploy to development server"
- curl
environment:
name: development
url:
before_script: []
when: manual
only:
- develop
integration-universal:
stage: deploy
image: appropriate/curl
script:
- echo "Deploy to integration server"
- curl
environment:
name: integration
url:
before_script: []
when: manual
only:
- universal
integration:
stage: deploy
image: appropriate/curl
script:
- echo "Deploy to integration server"
- curl
environment:
name: integration
url:
before_script: []
when: manual
only:
- develop
testing:
stage: deploy
image: appropriate/curl
script:
- echo "Deploy to testing server"
- curl
environment:
name: testing
url:
before_script: []
when: manual
only:
- /^release.*$/
staging:
stage: deploy
image: appropriate/curl
script:
- echo "Deploy to staging server"
- curl
environment:
name: staging
url:
before_script: []
when: manual
only:
- /^release.*$/
- /^hotfix.*$/
- master
production:
stage: deploy
image: appropriate/curl
script:
- echo "Deploy to production server"
- curl
environment:
name: production
url:
before_script: []
when: manual
only:
- master