Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Requirements and Setup
12%

The GitLab Repository

To push the code to a GitLab repository, you need a GitLab account to follow this guide. You can use either the free tier of GitLab.com or use your hosted GitLab instance if you have one. For simplicity, we will use GitLab.com in this guide, it's free at some level and easy to use. The free tier is more than enough for our learning purposes.

Create a new account or log in to your existing account. After logging in, create a new group to store your projects (https://gitlab.com/groups/new) and a new project. You can use learning as the name of the group and todo as the name of the project. We are not going to use or add any specific settings, templates, README file or licenses for this project, just an empty repository. So start a project from scratch and disable any additional settings.

After creating the project, GitLab will generate a URL for it. For example:

https://gitlab.com/learning9042634/todo

Where learning9042634 is your group name and todo is your project name. Let's export both as environment variables since we will use them later:

# Export the group and project names
cat << EOF >> $HOME/.bashrc
export GITLAB_GROUP="learning9042634"
export GITLAB_PROJECT="todo"
EOF

# Source the .bashrc file to apply the changes
source $HOME/.bashrc

Add a ".git" at the end of the URL to get the Git URL and export it as an environment variable. Example:

# Export the GitLab repository URL
cat << EOF >> $HOME/.bashrc
export GITLAB_URL="https://gitlab.com/$GITLAB_GROUP/$GITLAB_PROJECT.git"
EOF

# Source the .bashrc file to apply the changes
source $HOME/.bashrc

Other variables you need to export are the username and email you used to create the GitLab account:

# Export the GitLab username and email
cat << EOF >> $HOME/.bashrc
export GITLAB_USERNAME=""
export GITLAB_EMAIL=""
EOF

# Source the .bashrc file to apply the changes
source $HOME/.bashrc

Make sure to change and to your actual GitLab username and email.

Let's push the code to the GitLab repository. First, install Git:

# Install Git
apt update; apt install -y git

Initialize a new Git repository in the todo application directory:

cd $HOME/todo/app

# Initialize a new Git repository with main as the initial branch
git init --initial-branch=main

Add the global Git configuration:

# Configure Git with your GitLab username
git config --global user.name "$GITLAB_USERNAME"

# Configure Git with your GitLab email
git config --global user.email "$GITLAB_EMAIL

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.