Building Docker Images in Gitea
Categories: programming
Tags: gitea docker kubernetes github
Simple goal: build and push a container on push. Simple is always famous last words 😀 .
Within Github Actions it would look something like the following according to [Docker’s official action] (https://github.com/marketplace/actions/build-and-push-docker-images).
on:
push:
branches:
- 'main'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: user/app:latest
Trying this out quickly provides an error Unable to locate executable file: docker
.
A Gitea Solution?
There is an article which uses a bespoke image to have Docker installed and ready to run. This allows one to otherwise run Docker like normal.
Honestly I am hoping for a more native solution. On Kubernetes I am running Gitea Actions within a container already with rootless docker. I am wondering if there is not an easy mechanism.
There is a method to use Kubernetes directly. Definitely would be an easy and efficient solution. However I am nervous about what is required within the Kubernetes name spaces. Will try another time.
Exploring Buildah
Figured now would be a good time to explore other container building systems to see if they are easier. buildah
is an often referenced build system. Using the build
should consume the Dockerfile to hopefully produce the
desired images.
Installation
Initial I setup buildah
following the instructions within the repository. apt-get update && apt-get install buildah
installed a significantly outdated version. Not sure if this is in part due to an old execution environment.
Attempting to use redhat-actions/buildah-build@v2 resulted in the
same failure for ubuntu-latest
and ubuntu-18.04
. Saddly buildah does not have binary releases for linux.
Otherwise I would just pull those and try. Building from source looks hostile at best. Tried a configuration like the
following.
name: Deploy to dev
on:
push:
branches:
- main
defaults:
run:
shell: bash
jobs:
# Build job
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Buildah Action
uses: redhat-actions/buildah-build@v2
with:
image: registry.example.com/app
tags: latest ${{ github.sha }}
containerfiles: |
./cmd/service/Dockerfile
platforms: |
linux/amd64
linux/arm64
Docker in Docker
For a while I tried getting Docker in Docker working on within Kubernetes. Both rootless and root modes. I had luck with neither.
I eventually got the Docker instance to launch and start pulling source images. However, Docker quickly complained about
needing to mount /sys
with sysfs
. To even get to this point it took about three minutes. Building with Tekton was
also slow.
Back to the familiar: Docker running on bare metal.
This was an interesting experiment with Docker and Docker’s usage of TLS. Using this I went back to the simplest solution: run Docker on a machine and have Gitea connect in. Not ideal as I now have a strong dependency on the machine being available to build Docker images. You can get fancy with multiple hosts too. For now this allows me to get back to building applications.