Giter Club home page Giter Club logo

gitlab-automation's Introduction

GCP automation via GitLab

This repository contains PoCs for various experimental DevOps approaches when harnessing GitLab to perform deployment of dockerized applications to the Cloud

In particular, the idea of dynamically generated CI/CD pipeline is investigated (ie. gitlab-ci.yml file or its parts are generated in runtime)

Pre-requisites

  • gcloud (with non-null value of env var GOOGLE_APPLICATION_CREDENTIALS)
  • npm
  • python3.8
  • account at GitLab

Creating sample application

To demonstrate how to work with containerized apps, we are going to use a simple node.js app

Local run

cd ./app
npm install
node index.js

Go to localhost:8080 and observe "Hello, World!" simple web page

Dockerize and publish app to GCR

sudo docker build -t nodejs-demo:1.0.0 .
sudo docker images
sudo docker run -ti --name nodejs-app -p 8080:8080 -d nodejs-demo:1.0.0

(In case of "container already running error", stop that container with command sudo docker rm <container_id>)

The last command will run the container with app in a daemon mode; it can also be visible using the docker command:

sudo docker ps

CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS          PORTS                                       NAMES
6aadf0b63d2f   nodejs-demo   "docker-entrypoint.sā€¦"   24 seconds ago   Up 23 seconds   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   nodejs-app

To stop container, type the command:

sudo docker stop 6aadf0b63d2f

After successful testing tag and publish docker to GCR:

GOOGLE_CLOUD_PROJECT=gcp-tooling-api
gcloud config set project gcp-tooling-api
gcloud services enable containerregistry.googleapis.com 
sudo docker tag nodejs-demo:1.0.0 eu.gcr.io/$GOOGLE_CLOUD_PROJECT/nodejs-demo:v1
sudo docker push eu.gcr.io/$GOOGLE_CLOUD_PROJECT/nodejs-demo:v1

To create GCP infrastructure with aforementioned simple app, use the script gcp/create_insfrastructure.sh

This script will do the following:

  • create template for instance in instance group
  • create managed instance group itself
  • create and attach auto-scaling policy to instance group

Building image for GitLab Runner

First for convinience create env variables GITLAB_USERNAME, GITLAB_PASSWORD to hold GitLab's docker registry creds (note, this is not the secure place to hold secrets and consider using providers); set docker registry url via export GITLAB_DOCKER_REGISTRY=registry.gitlab.com:

sudo nano ~/.profile
source ~/.profile

The following commands build and push image for GitLab runners

cd ./docker
export GROUP=<name of the group>
./build_image.sh

Note the image URL - it can be used now for GitLab Runners.

Create a GitLab trigger token (Settings -> CI/CD -> Pipeline triggers) and put it into GITLAB_TOKEN env variable. Create a GitLab access token (PAT, User Settings -> Access Tokens) and put it into PAT_TOKEN env variable. Create a RUNNER_CUSTOM_IMAGE env variable in CI/CD area:

curl --request POST --header "PRIVATE-TOKEN: $PAT_TOKEN" \
     "https://gitlab.com/api/v4/projects/41024544/variables" \
     --form "key=RUNNER_CUSTOM_IMAGE" \
     --form "value=registry.gitlab.com/automation299/gitlab-automation:a9316a0"

gitlab-automation's People

Contributors

akaliutau avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.