Juan Olvera

  • How to resize a disk on Ubuntu server 20.04

    I had an issue with my Thinkpad x220; when I installed Ubuntu, I had only 100GB available out of 1000 GB. So it ran out of available space quickly.

    To resize to all the space available, I ran these commands:

    lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
    
    resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

    Sources:

  • Deploy Gitea to Dokku

    Requirements

    Steps

    Create an application.

    dokku apps:create gitea

    Expose the ports for http and ssh. By default, gitea exposes 3000 for http and 22 for ssh. We want our application to listen externally on port 80, but we need to map our ssh to a different port because 22 is used by the host.

    We will rely on the docker-options plugin to expose ssh properly.

    # expose container `http` port 3000 on host `http` port 80
    dokku proxy:ports-add gitea http:80:3000
    
    # expose the container port 22 on host port 2222
    dokku docker-options:add git deploy -p 2221:22

    Add a rule in your firewall to allow connections on 2221.

    sudo ufw allow 2221/tcp

    Create a storage directory for the Gitea files.

    sudo mkdir /var/lib/dokku/data/storage/gitea_data
    sudo chown user:user /var/lib/dokku/data/storage/gitea_data
    dokku storage:mount gitea /var/lib/dokku/data/storage/gitea_data:/data

    Pull and deploy the Docker image from dockerhub.

    docker pull gitea/gitea:latest
    docker tag gitea/gitea:latest dokku/gitea:latest
    dokku git:from-image gitea dokku/gitea:latest

    Add a Let’s encrypt TLS certificate with the Dokku letsencrypt plugin.

    dokku letsencrypt:set git email <your-email>
    dokku letsencrypt:enable git

    Now, go visit gitea.<yourdomain>, e.g., gitea.yourdomain.com.

    Configuration

    Most of the options are autopopulated, use the following settings as needed.

    • Get the database information from dokku postgres:info gitea.
    • Set the SSH port as 2221. Gitea will use this to format your projects’ SSH connection info in the UI.

    Resources

    No artificial intelligence was used in the making of this post.

  • Build your own ngrok

    This simple setup can help us expose our local development environment to the public internet. I usually paid for ngrok, but the last time I tried them, they were expensive, and their customer support was terrible.

    For a small-size project, we can build our own small ngrok with Linux, Caddy, and SSH port forwarding.

    Requirements:

    • A VPS with Linux. In this example, we will use Ubuntu 20.01 LTS
    • SSH access to your server
    • Caddy
    • A domain name. In this example, we will use mydomain.io

    Add DNS record

    We need to add two A records to our domain DNS zone:

    • An A record pointing to our server’s IP address
    • A wildcard A record pointing to our server’s IP address

    For example, if our server IP address is 5.164.71.442, our records will look like this:

    HostnameTypeAddress
    @A5.164.71.442
    *A5.164.71.442
    DNS records example

    Configure Caddy

    First, Install Caddy.

    Then, create a Caddyfile to route traffic from a specific domain name to a local port; in this case, we will do app.mydomain.io and port 8881.

    touch ~/Caddyfile
    app.mydomain.io {
      reverse_proxy 127.0.0.1:8881
      log {
        output file /var/log/access.log
      }
    }

    Reload caddy.

    caddy reload
    
    > 2023/05/30 17:55:25.272 INFO    using adjacent Caddyfile

    And our server is ready.

    Create an SSH tunnel

    With SSH, you can create a secure connection between your computer and the server, with the services relayed, i.e., every request to the server will be forwarded to your local development environment.

    For example, if we are building our application in localhost:8000, we can do the following:

    # ssh -R <server port>:<server domain>:<local port> <server ssh user>@<server domain>
    ssh -R 8881:app.mydomain.io:8000 user@mydomain.io

    Now, every request you send to app.mydomain.io will be forwarded to localhost:8000 on your computer.

    Resources

    No artificial intelligence was used in the making of this post.