Deployment configuration in Gitlab

For setup your app you have two options. First one is setup the project manually or you can use cli tool plant if you have NodeJs already installed just install npm install -g @goodservers/plant. The cli is console tool that helps you with setup. Run it in root directory and the guide will show you the options. First of all you need to save Gitlab access token (all actions eg. creating new project, saving variables and defining servers to deploy are automatized) and Gitlab instance domain and afterwards the guide will start.

Installation

I'm using gitlab.com account. So after login, click on create new project. I'm going to name it static, because we will server only static content. I'm going to add new file index.html which is basically our content that'll be deployed in docker container. Now let's go to the project settings to configure needed variables in Settings => CI/CD. There is the Variables section. Here we can store our private key and server name where content will be deployed. Variable names are DEPLOYMENT_SERVER_IP and DEPLOY_SERVER_PRIVATE_KEY. So your section should looks like this.

Now we are going to setup the Docker. We need two files Dockerfile and docker-compose.yml file.

Copy
Dockerfile

In Dockerfile we specify the core image, which is tiny nginx server. We are using the current version in alpine mode. Alpine means that the origin image is build in Alpine linux (securely and size oriented). The huge benefit of apline image is mainly low size and low future memory costs.

Copy
docker-compose.yml

Now we are going to setup the Gitlab pipeline where the deployment process will be provided. We need to create the new file .gitlab-cy.yml in our repository.

Copy
Group.gitlab-ci.yml

We splited CI into two parts which is runnable only on master branch. The first phase is the build phase, where we build the docker image and save it to gitlab image repository. The second phase is the deployment phase. It consists of establishing connection to the remote server and pulling the latest built image from image repository. When it's pulled, its started. After few seconds, when you open http://static.123.123.123.123.xip.io/ you should see the result.

👏
And that's it.
Your first app is running!