Skip to content

Instantly share code, notes, and snippets.

@MahdadGhasemian
Last active September 29, 2024 13:59
Show Gist options
  • Save MahdadGhasemian/e62fa77ca1c1fd1c36343d367c1db960 to your computer and use it in GitHub Desktop.
Save MahdadGhasemian/e62fa77ca1c1fd1c36343d367c1db960 to your computer and use it in GitHub Desktop.
Bash, APT, Docker, K3S, Gitlab Runner Behind Proxy ?

1. bash behind proxy:

Edit .profile file (with vi or nano)

nano .profile

And add following lines:

export http_proxy=http://127.0.0.1:8888/
export https_proxy=http://127.0.0.1:8888/

And run:

source .profile

2. apt and apt-get behind proxy:

Edit apt config file for proxy:

nano /etc/apt/apt.conf.d/proxy.conf

And Add following lines:

Acquire::http::Proxy "http://127.0.0.1:8888/";
Acquire::https::Proxy "http://127.0.0.1:8888/";

3. Docker behind Proxy:

Create service and config file:

mkdir -p /etc/systemd/system/docker.service.d
nano /etc/systemd/system/docker.service.d/proxy.conf

Add following config:

[Service]
Environment="HTTP_PROXY=http://127.0.0.1:8888/"
Environment="HTTPS_PROXY=http://127.0.0.1:8888/"
Environment="NO_PROXY=localhost,127.0.0.1,.local"

Reload and run it:

systemctl daemon-reload
systemctl restart docker.service
systemctl status docker.service

4. K3S behind proxy:

Edit k3s service env file:

nano /etc/systemd/system/k3s.service.env

And add following line:

HTTP_PROXY=http://127.0.0.1:8888/
HTTPS_PROXY=http://127.0.0.1:8888/
NO_PROXY="localhost,127.0.0.1,0.0.0.0,10.0.0.0/8,cattle-system.svc,192.168.10.0/24,.svc,.cluster.local,example.com"

5. Gitlab Runner behind proxy:

Create service and config file:

mkdir /etc/systemd/system/gitlab-runner.service.d
nano /etc/systemd/system/gitlab-runner.service.d/http-proxy.conf

Add following config:

[Service]
Environment="HTTP_PROXY=http://127.0.0.1:8888/"
Environment="HTTPS_PROXY=http://127.0.0.1:8888/"

Reload and run it:

systemctl daemon-reload
systemctl restart gitlab-runner
systemctl status gitlab-runner
systemctl show --property=Environment gitlab-runner

Note: Adding proxy to docker containers should be done after registration runners Adding proxy inside gilab runner:

nano /etc/gitlab-runner/config.toml

And and the following config into every single section [[runners]]_section :

pre_get_sources_script = "git config --global http.proxy $HTTP_PROXY; git config --global https.proxy $HTTPS_PROXY"
environment = ["https_proxy=http://127.0.0.1:8888", "http_proxy=http://127.0.0.1:8888", "HTTPS_PROXY=127.0.0.1:8888", "HTTP_PROXY=127.0.0.1:8888"]

Note

It consider your http proxy is run on the "127.0.0.1:8888", you should replace it with your proxy address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment