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?