hakk

software development, devops, and other drivel
Tree lined path

Streamlining Deployment: Installing Docker, Gitea, Gitea Act Runner, and Nginx on Ubuntu

Learn how to setup a robust source control system with CI/CD to deploy your applications on Ubuntu. This post will guide you through the process of installing Docker, Gitea, Gitea Act Runner, and Nginx on Ubuntu, empowering you to streamline your deployment workflow and enhance your server capabilities.

Installing Docker on Ubuntu

Docker provides a powerful platform for containerizing applications and simplifying deployment across different environments. To install Docker on Ubuntu, follow these steps:

Note: If you want the latest Docker follow the Docker docs.

sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker

After installing Docker, you can verify the installation by running:

docker --version

Setting Up Gitea on Ubuntu

Gitea is a lightweight, self-hosted Git service that allows you to manage repositories, collaborate with team members, and track code changes effectively. To install Gitea on Ubuntu, you can use the following steps:

Note: Full Instruction in the official Gitea installation doc.

Choose the latest version from the downloads page. At the time of this writing it’s 1.22.0.

wget -O gitea https://dl.gitea.com/gitea/1.22.0/gitea-1.22.0-linux-amd64
chmod +x gitea
sudo mv gitea /usr/local/bin/

Make sure git is installed:


sudo apt install git

Create a user to run Gitea:

sudo adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \
   git

Create the needed directory structure:

sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

Install the sample systemd service file:

sudo wget -P /etc/systemd/system/ https://github.com/go-gitea/gitea/blob/release/v1.22/contrib/systemd/gitea.service

Reload systemd daemon service files, enable and start Gitea:

sudo systemctl daemon-reload 
sudo systemctl enable gitea
sudo systemctl start gitea

At this point Gitea will be available locally at http://localhost:3000`. Next let’s install Nginx to use as a reverse proxy to access Gitea.

Configuring Nginx as a Reverse Proxy

Now let’s install Nginx which will serve as a reverse proxy that will enable us to access Gitea from a web browser, follow these steps:

sudo apt update
sudo apt install nginx

Once Nginx is installed, create a new server block configuration file for Gitea:

sudo nano /etc/nginx/sites-available/gitea

Add the following configuration to the file, adjusting the server_name and proxy_pass directives as needed:

server {
    listen 80;
    server_name git.example.com;

    location / {
    	client_max_body_size 512M;
        proxy_pass http://localhost:3000;
        proxy_set_header Connection $http_connection;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Test and enable the server block and restart Nginx to apply the changes:

sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Installing Gitea Act Runner

Gitea Act Runner enables you to run GitHub Actions and self-hosted runners within your Gitea environment. To install Gitea Act Runner on Ubuntu, you can following steps:

First download the latest binary from the release page, at the time of this writing it was 0.2.10.

wget https://gitea.com/gitea/act_runner/releases/download/v0.2.10/act_runner-0.2.10-linux-amd64
sudo mv act_runner-0.2.10-linux-amd64 /usr/local/bin/act_runner
sudo chmod +x /usr/local/bin/act_runner

Create the config and data directories for the runner:

sudo mkdir -p /var/lib/act_runner
sudo chmod -R 750 /var/lib/gitea/
sudo mkdir /etc/act_runner
sudo chmod 770 /etc/act_runner

Generate a config file, just the default will do for now:

act_runner generate-config > /etc/act_runner/config.yaml

Before finishing configuring the Act Runner, we need to configure Gitea and get a token.

Configure Gitea and get the Act Runner token

Navigate to the url that was configured in the above Nginx step. For example, above it was configured to git.example.com.

Follow the setup steps, select SQLite3 as the database, follow with any other configuration changes that you would like to make. Expand the mail and admin user sections on the bottom as needed.

Once that is finished, click on your use icon on the top right of the screen. Then navigate to Site Administration > Actions > Runners. Once on the Runners page you’ll see towards the top right a button “Create new Runner”, click this and a dropdown will appear with a token. Copy this token and go to the next step to finish configuring the Act Runner.

Gitea Act Runner Configuration

Using the token from the previous step; we will setup an instance level runner.

Back in the terminal run the following commands:

cd /var/lib/act_runner
act_runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>

Finally, create a systemd service file to run Act Runner. Run the following command to start a nano text editor and then paste the below content into the service file.

sudo nano /etc/systemd/system/act_runner.service
[Unit]
Description=Gitea Actions runner
Documentation=https://gitea.com/gitea/act_runner
After=docker.service

[Service]
ExecStart=/usr/local/bin/act_runner daemon --config /etc/act_runner/config.yaml
ExecReload=/bin/kill -s HUP $MAINPID
WorkingDirectory=/var/lib/act_runner
TimeoutSec=0
RestartSec=10
Restart=always
User=act_runner

[Install]
WantedBy=multi-user.target

Reload systemd daemon service files, enable and start Gitea Act Runner:

sudo systemctl daemon-reload 
sudo systemctl enable act_runner
sudo systemctl start act_runner

Lastly, go back to the browser that is still on the runner page and refresh. You should now see your runner listed and active.

Ansible Role for easy Deploy, Setip and Configuration

I have also created an Ansible Role that will do all these steps so you can just sit back and sip your latte until everything is ready.

Checkout the GitHub repo!

Conclusion

By following these steps, you can quickly set up a powerful version control system with CI/CD right on Ubuntu with Docker. Leveraging these tools allows you to enhance productivity, streamline deployment workflows, and ensure the reliability and scalability of your infrastructure. Start deploying with confidence and efficiency on Ubuntu today!