How to write a .gitlab-ci.yml file?

Hello,
I have two servers as follows:

GitLab: GitLab Server
Runner: Docker and GitLab-Runner

I created a Node.js file on the GitLab server and I want to run this file through Nginx and Node.js containers. I know that I should have two Dockerfile and .gitlab-ci.yml files on the GitLab server.
The Dockerfile is as follows:

FROM node:latest as build-stage
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/package.json
RUN npm install
RUN npm update
COPY . /usr/src/app
EXPOSE 3000


#production stage
FROM nginx:latest as production-stage
COPY --from=build-stage /usr/src/app /usr/share/nginx/html
COPY ./cfiles/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD nginx -g 'daemon off;'

The default.conf is as follows:

upstream nodejs {
    server nodejs:3000;
}

server {
   listen 80;
   server_name default_server;
   error_log  /var/log/nginx/error.system-default.log;
   access_log /var/log/nginx/access.system-default.log;
   charset utf-8;


    root /usr/share/nginx/html;
    index index.html index.php index.js;

location ~ \.js$ {
    proxy_pass http://nodejs;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }

    location / {
     autoindex on;
     try_files $uri $uri/ $uri.html =404;
    }
}

But I don’t know what to do about the .gitlab-ci.yml file. I searched the internet for examples, but none of them related to what I want to do.
Please advice me.

Thank you.

This is basically the same question as Configuring GitLab Runner with Node.js - #10 by hack3rcon, so the answer is the same to: neither gitlab nor a gitlab runner can run your website. That’s not what they do.

You need .gitlab-ci.yml to build docker containers for you (example in referenced thread) and then you need to run those containers somewhere so they can be accessed.

If you own the gitlab server I suppose you could serve it from there, but I personally wouldn’t want to dilute a server with two very different purposes and just get a third server to serve the website. Or, run the gitlab runner on the gitlab server so the gitlab runner server is free to do something else.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.