1

I have got the following gitlab CI file but it is stuck on "Creating an optimized production build..."

I have tried to build the same file locally and the build is completed within 15 minutes.

What am I doing wrong here ?

image: docker:18.09.7

stages:
  - build
  - create-docker
  - deploy

variables:
  DOCKER_USER: 'xxx'
  DOCKER_PASSWORD: 'xxx'
  CI_REGISTRY: https://index.docker.io/v1/

build:
  image: node:8.16.1
  stage: build
  script:
    - npm install
    - npm run build --verbose
  artifacts:
    when: always
    expire_in: 12 hour
    paths:
      - build
  allow_failure: true

create_docker_python:
  image: docker:18.09.7
  stage: create-docker
  services:
    - docker:18.09.7-dind
  variables:
    APP_IMAGE: xyz/image:1.13
  script:
    - docker login $CI_REGISTRY -u $DOCKER_USER -p $DOCKER_PASSWORD
    - docker build -t $APP_IMAGE -f Dockerfile . && echo "Publishing docker image on $image"
    - docker push $APP_IMAGE

kube_deploy:
  before_script:
    - export KUBECONFIG=configFiles/admin.conf
  stage: deploy
  image: lwolf/helm-kubectl-docker:v152_213
  script:
    - kubectl delete ing backend
    - kubectl delete cm file-configmap
    - kubectl delete deployment saas
    - kubectl apply -f folder1/k8s/ingress.yaml --validate=false
    - kubectl apply -f folder1/k8s/k8s-deployment.yaml --validate=false
    - kubectl apply -f folder1/k8s/k8s-configmaps.yaml --validate=false
jeril
  • 1,109
  • 2
  • 17
  • 35

2 Answers2

3

If your application is heavy it will require more resources and gitlab shared runner wouldn't be enough and you will have to use a dedicated runner.

To resolve the issue I increased the RAM. I purchased a server in Digital Ocean with 16GB RAM and did npm run build or to use a dedicated runner in your CI/CD pipeline you can follow the below steps

  1. install gitlab runner
  2. register your gitlab runner

You can follow this guide.

https://about.gitlab.com/blog/2016/04/19/how-to-set-up-gitlab-runner-on-digitalocean/

After increasing the RAM my build was completed in 15 minutes.

jeril
  • 1,109
  • 2
  • 17
  • 35
0

In my case it turned out, we were using a shared runner with caching enabled, which is an anti pattern, as neither increasing resources nor swap resolved the issue.

If increasing resources does not help you can consider:

  1. Adding a dedicated gitlab-runner with a tag for a project. Make sure to disable shared runners and add tags section to your .gitlab-ci.yml file:
default:
  tags: [ your-tag-associated-with-specified-runner ]
  1. Adding a cache cleanup job when all jobs are finished.

For more details please check:

  1. Caching good practices https://docs.gitlab.com/ee/ci/caching/index.html
  2. Clearing cache job Clearing the pipeline cache with Gitlab CI
jckmlczk
  • 359
  • 4
  • 11