useblacksmith / remote-buildkit-terraform

11 stars 0 forks source link

Non EC2 support #2

Open BRAVO68WEB opened 2 months ago

BRAVO68WEB commented 2 months ago

Can also deploy this to an non AWS servers? I have my infrastructure setup on Hetzner Cloud

adityamaru commented 2 months ago

Hey @BRAVO68WEB! It's actually a lot simpler in Hetzner Cloud. You need to setup a buildkit instance inside your box using:

#!/bin/bash
    set -e

    # Update and install dependencies
    yum update -y
    yum install -y docker git

    # Start and enable Docker
    systemctl start docker
    systemctl enable docker

    # Add ec2-user to the docker group
    usermod -aG docker ec2-user

    # Download and install BuildKit
    export BUILDKIT_VERSION=0.12.0
    curl -sSL "https://github.com/moby/buildkit/releases/download/v$${BUILDKIT_VERSION}/buildkit-v$${BUILDKIT_VERSION}.linux-amd64.tar.gz" -o buildkit.tar.gz
    tar -xzf buildkit.tar.gz -C /usr/local/bin --strip-components=1

    # Create buildkitd systemd service
    cat <<EOT > /etc/systemd/system/buildkitd.service
    [Unit]
    Description=BuildKit daemon
    After=network.target

    [Service]
    ExecStart=/usr/local/bin/buildkitd --addr tcp://0.0.0.0:9999 --addr unix:///run/buildkit/buildkitd.sock --debug
    Restart=always

    [Install]
    WantedBy=multi-user.target
    EOT

    # Enable and start buildkitd service
    systemctl daemon-reload
    systemctl enable buildkitd
    systemctl start buildkitd

In your GitHub Actions you then add a snippet of the form:

- name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
      with:
        driver: remote
        endpoint: tcp://your-hetzner-ip:9999

This will route all your docker builds to use the buildkit instance in Hetzner. You will want to setup mTLS to ensure only your GitHub Actions can talk to this buildkit instance. You can do this by setting up the server side certs in Hetzner and storing the client side certs as GitHub secrets that your workflows can use.

Let me know if you have anymore questions!

BRAVO68WEB commented 2 months ago

Sure, let check back with this.

On Tue, 13 Aug, 2024, 10:15 pm Aditya Maru, @.***> wrote:

Hey @BRAVO68WEB https://github.com/BRAVO68WEB! It's actually a lot simpler in Hetzner Cloud. You need to setup a buildkit instance inside your box using:

!/bin/bash

set -e

# Update and install dependencies
yum update -y
yum install -y docker git

# Start and enable Docker
systemctl start docker
systemctl enable docker

# Add ec2-user to the docker group
usermod -aG docker ec2-user

# Download and install BuildKit
export BUILDKIT_VERSION=0.12.0
curl -sSL "https://github.com/moby/buildkit/releases/download/v$${BUILDKIT_VERSION}/buildkit-v$${BUILDKIT_VERSION}.linux-amd64.tar.gz" -o buildkit.tar.gz
tar -xzf buildkit.tar.gz -C /usr/local/bin --strip-components=1

# Create buildkitd systemd service
cat <<EOT > /etc/systemd/system/buildkitd.service
[Unit]
Description=BuildKit daemon
After=network.target

[Service]
ExecStart=/usr/local/bin/buildkitd --addr tcp://0.0.0.0:9999 --addr unix:///run/buildkit/buildkitd.sock --debug
Restart=always

[Install]
WantedBy=multi-user.target
EOT

# Enable and start buildkitd service
systemctl daemon-reload
systemctl enable buildkitd
systemctl start buildkitd
```

In your GitHub Actions you then add a snippet of the form:

  • name: Set up Docker Buildx uses: @.*** with: driver: remote endpoint: tcp://your-hetzner-ip:9999

This will route all your docker builds to use the buildkit instance in Hetzner. You will want to setup mTLS to ensure only your GitHub Actions can talk to this buildkit instance. You can do this by setting up the server side certs in Hetzner and storing the client side certs as GitHub secrets that your workflows can use.

Let me know if you have anymore questions!

— Reply to this email directly, view it on GitHub https://github.com/useblacksmith/remote-buildkit-terraform/issues/2#issuecomment-2286684017, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ4HJV4WBIYZ5KG7WLB4T2TZRIZZ5AVCNFSM6AAAAABMOPWY6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBWGY4DIMBRG4 . You are receiving this because you were mentioned.Message ID: @.***>