SSL – Configure GitLab Docker Container with Plesk and LetsEncrypt

dockergitlablets-encryptpleskssl

Hi I have an issue with my GitLab setup.

What I'm trying to achieve:

  • running GitLab inside a Docker container
  • access GitLab through a subdomain (gitlab.mydomain.com) at ports 80 and 443 for https
  • manage SSL through a wildcard certificate for *.mydomain.com provided by LetsEncrypt and Plesk (already in use for subdomains managed by Plesk)
  • beeing able to run build tasks in GitLab container (npm scripts etc.) and finally move specific output files to directories of subdomains managed by Plesk (outside of container)

What I did so far:

  • got a v-server running Ubuntu 18.04.2 with preinstalled Plesk Onyx 17.8.11
  • setup mydomain.com through Plesk
  • setup LetsEncrypt wildcard certificate for mydomain.com through Plesk
  • installed Docker via ssh (not Plesk)
  • ran GitLab inside a container at mydomain.com:30080

I'm completely new to server envs and Docker so I'm not sure about the needed structure of things. Maybe you guys know what to do?

Thanks!

Best Answer

This setup is working for me:

  1. create a sub-domain from Plesk (ex. gitlab.mydomain.com)
  2. select your Let's Encrypt certificate in "Hosting Settings" and be sure to set a permanent 301 redirect on HTTPS (simply tick the checkbox)
  3. when starting your Docker container, expose port 80 (ex. 80:10080)
  4. in "Apache & nginx Settings" add the following:
location / {
    proxy_pass http://localhost:10080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}

This will serve your sub-domain through HTTPS and your Let's Encrypt certificate, while proxying requests to port 80 of your container so you don't have to bother about passing the certificate to GitLab from outside the container.

From my understanding this is safe, since un-encrypted traffic is confined in the server (if your Docker daemon is on the same server as Plesk) and unaccessible from the outside.

--

For your last point

beeing able to run build tasks in GitLab container (npm scripts etc.) and finally move specific output files to directories of subdomains managed by Plesk (outside of container)

that's a whole question by itself.

To run builds you'll need to install GitLab Runner. GitLab docs suggests to install it on a different host, but you may try using their Docker image on the same host.

For building and deploying your applications, see GitLab Runner docs. You will need to setup "pipelines" for what is called "Continuous Deployment".

To create a sub-domain for every app you could either:

  • create the sub-domains manually from Plesk and deploying the files with scripting as the final step of your "pipeline" build
  • use some scripting and Plesk API's to create sub-domains automatically
  • ignore Plesk and go full Docker; use a reverse-proxy that will handle all your sub-domains and Let's Encrypt certificates, such as Traefik

These are just pointers, I suggest you to search and read more on the subject of CI/CD.