Skip to main content

Gitea Actions

· 4 min read
Austin Spencer

Gitea Actions with Gitea Container Registry

For whatever reason, I had a hard time setting up Gitea Actions to build and deploy Docker images to my local Gitea Container Registry running on my Raspberry Pi 4 model B. I'm setting up this blog so that I can remember how I did it in the future and also in the case someone else stumbles upon this while running into the same issues.

Prerequisites

  • Gitea Instance running locally
  • Gitea Actions enabled
  • Project you're building custom Docker Images with
  • Basic understanding of GitHub/Gitea Actions

Getting Started

  • Open your project that you are building custom Docker Images for
  • Create .gitea/workflows folders and then create a .yaml file within such as ci.yaml.

Create Secrets

We'll need to add a couple Runner secrets for the Action to work. We will need the username and token for authentication with Gitea for access to the container registry.

In the settings for either the repository or at the organization level - Set a username and token secret with their respective values. For this example, I will name the username key GCR_USERNAME and token key GCR_TOKEN.

Update Gitea Action File

Within the file that you created in your .gitea/workflows folder..

  1. Let's add the basic information to the file:
name: ci # Put whatever name you prefer
on:
push:
branches:
- main
- develop
- feature/**
# Publish semver tags as releases.
tags: ["**"]

In this section we have named our Action ci and defined the triggers. In my use case I am triggering builds on each push to main, develop, and feature branches. I am also triggering builds on all tags.

  1. Next, add some environment variables that we'll use later on
env:
# IP for your gitea
REGISTRY: 100.x.y.z:port
# gitea.repository as <account>/<repo>
IMAGE_NAME: ${{ gitea.repository }}
  1. Add our jobs
jobs:
build_and_push:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[registry."${{ env.REGISTRY }}"]
http = true
insecure = true
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.GCR_USERNAME }}
password: ${{ secrets.GCR_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

This looks mostly like a typical Action for build and push with Docker. However, the highlighted sections are what makes the difference.

The first highlighted section which specifies a specific container to use with the Runner. This container is setup specifically for GitHub/Gitea Actions.

The next section under Set up Docker Buildx. We are adding a config-inline argument which sets the registry as insecure, allowing us to use a local registry with http instead of https. Without this, the connection will fail with Private registry push fail: server gave HTTP response to HTTPS client.

Finally, the last highlighted section uses the secrets we set previously to login to our container registry. If you set your secrets as different names you will need to update them here.

Final File

Below is the completed action file

.zshrc
name: ci # Put whatever name you prefer
on:
push:
branches:
- main
- develop
- feature/**
# Publish semver tags as releases.
tags: ["**"]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: 100.x.y.z:port
# gitea.repository as <account>/<repo>
IMAGE_NAME: ${{ gitea.repository }}

jobs:
build_and_push:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[registry."${{ env.REGISTRY }}"]
http = true
insecure = true
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.GCR_USERNAME }}
password: ${{ secrets.GCR_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}