Skip to content

Instantly share code, notes, and snippets.

@devansvd
Last active January 8, 2021 12:23
Show Gist options
  • Select an option

  • Save devansvd/621ddc51bf0ae1c6436f3e81c6451e55 to your computer and use it in GitHub Desktop.

Select an option

Save devansvd/621ddc51bf0ae1c6436f3e81c6451e55 to your computer and use it in GitHub Desktop.

Revisions

  1. devansvd renamed this gist Jan 8, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. devansvd revised this gist Jan 8, 2021. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # Ci pipeline to buid docker images
    # and push to gitlab docker registry
    # auto deploy as well

    stages:
    - build

    docker-build-master:
    image: docker:latest
    stage: build
    services:
    - docker:dind
    before_script:
    #- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - echo -n $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | ssh-add -
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" .
    - docker push "$CI_REGISTRY_IMAGE"
    - ssh -t -t host@ip "docker pull '$CI_REGISTRY_IMAGE' && docker rm -f imagename && docker run -d ... --restart unless-stopped '$CI_REGISTRY_IMAGE' && exit"
    only:
    - master
  3. devansvd revised this gist Jan 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitlab-ci-2.yml
    Original file line number Diff line number Diff line change
    @@ -41,6 +41,6 @@ deploy:

    script:
    - npm i -g pm2
    - pm2 deploy cumi-ecosystem.config.js production
    - pm2 deploy ecosystem.config.js production
    only:
    - master
  4. devansvd revised this gist Jan 5, 2021. 1 changed file with 46 additions and 0 deletions.
    46 changes: 46 additions & 0 deletions gitlab-ci-2.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    ## Auto deployer ci/cd

    # This file is a template, and might need editing before it works on your project.
    # Official framework image. Look for the different tagged releases at:
    # https://hub.docker.com/r/library/node/tags/
    image: node:alpine

    stages:
    - deploy

    deploy:
    stage: deploy
    before_script:
    # Install ssh-agent if not already installed, it is required by Docker.
    # (change apt-get to yum if you use a CentOS-based image)
    - 'which ssh-agent || ( apk add --update openssh )'

    # Add bash
    - apk add --update bash

    # Add git
    - apk add --update git

    # Run ssh-agent (inside the build environment)
    - eval $(ssh-agent -s)

    # Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
    - echo "$SSH_PRIVATE_KEY" | ssh-add -

    # For Docker builds disable host key checking. Be aware that by adding that
    # you are suspectible to man-in-the-middle attacks.
    # WARNING: Use this only with the Docker executor, if you use it with shell
    # you will overwrite your user's SSH config.
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    # In order to properly check the server's host key, assuming you created the
    # SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
    # instead.
    # - mkdir -p ~/.ssh
    # - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'

    script:
    - npm i -g pm2
    - pm2 deploy cumi-ecosystem.config.js production
    only:
    - master
  5. devansvd created this gist Jan 5, 2021.
    19 changes: 19 additions & 0 deletions gitlab-ci.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # Ci pipeline to buid docker images
    # and push to gitlab docker registry

    stages:
    - build

    docker-build-master:
    image: docker:latest
    stage: build
    services:
    - docker:dind
    before_script:
    #- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - echo -n $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
    script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" .
    - docker push "$CI_REGISTRY_IMAGE"
    only:
    - master