# CI flow gitlab + k8s

**URL:** <https://discuss.kubernetes.io/t/ci-flow-gitlab-k8s/6908>\
**Category:** General Discussions\
**Created:** [June 24, 2019, 10:51am UTC](https://discuss.kubernetes.io/t/ci-flow-gitlab-k8s/6908 "2019-06-24T10:51:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tornado67](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/tornado67/32/3878_2.png) [@tornado67](https://discuss.kubernetes.io/u/tornado67)\
**Post date:** [June 24, 2019, 10:51am UTC](https://discuss.kubernetes.io/t/ci-flow-gitlab-k8s/6908/1 "2019-06-24T10:51:11Z")

</div>

Hi everyone!  
I’m completely new to k8s and I need to setup CI using it. My current flow is:  
Gitlab is building docker cotainer with my appllication and pushes it to local registry, than helm chart installs my app to k8s cluster.

Here are some configuration files :  
My Docker file:

```
FROM node:11
WORKDIR /opt/app/
COPY ./ /opt/app
ARG CI_JOB_TOKEN
ENV CI_JOB_TOKEN=$CI_JOB_TOKEN
RUN git config --global http.sslVerify false
RUN yarn config set "strict-ssl" false -g && \
yarn install && \
yarn add https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.domain.com:6443/<project>.git#develop && \ 
yarn add https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.domain.com:6443/<project>.git#develop
RUN yarn build --env=test
EXPOSE 3000
CMD ["npm", "run", "start"]

```

My gitlab-ci.yaml

```
variables:
   LANG: en_US.UTF-8
   GIT_SSL_NO_VERIFY: "true"
   GITLAB_URL: "https://gitlab.domain.com:6443/"
   UNTAR_PATH: /tmp/alphatest
   DOCKER_TAG: '<mytag>:30500/app:latest'
   TAR: /tmp/app.tar.gz
   USER: root
   
image: node:11
stages:
  - build
  - build-image

build:
  stage: build
  before_script: 
   - apt-get update -qq && apt-get install
   - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
   - eval $(ssh-agent -s)
   - echo "$SSH_DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
   - 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

  script:
   - ls -al 
   - tar czf $CI_PROJECT_DIR/build.tar.gz ./*
   - "scp $CI_PROJECT_DIR/build.tar.gz $USER@host.domaim.com:$TAR"
   - "ssh -tt $USER@host.domaim.com \"mkdir -p $UNTAR_PATH && tar xf $TAR -C $UNTAR_PATH\" "
   - ssh -tt $USER@host.domaim.com "cd $UNTAR_PATH && docker build -t $DOCKER_TAG --build-arg CI_JOB_TOKEN=${CI_JOB_TOKEN} . "
   - ssh -tt $USER@host.domaim.com "cd $UNTAR_PATH && docker push $DOCKER_TAG "
   - "ssh -tt $USER@host.domaim.com \"helm delete --purge app || : && helm install $UNTAR_PATH/helm/nodeserver --set REACT_APP_PUBLIC_URL=$REACT_APP_PUBLIC_URL --set REACT_APP_API_URL=$REACT_APP_API_URL --set REACT_APP_API_AUTH_METHOD=$REACT_APP_API_AUTH_METHOD --set BROWSER=$BROWSER --set SKIP_PREFLIGHT_CHECK=$SKIP_PREFLIGHT_CHECK --name app \" "
   
  after_script:
    - ssh -tt $USER@host.domaim.com "rm -rf $UNTAR_PATH; rm -rf $TAR"

```

May be there are some better way to deploy app on k8s using gitlab ? Or may be anybody could recommend some improvements for this deploy config?
