From c920d9ed8fae7935c61e7c186c93741ec029e65b Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 8 Sep 2024 00:15:21 +1000 Subject: [PATCH] feat: initial commit - add Makefile - add gitea workflows - add Dockerfile --- .gitea/workflows/build.yaml | 82 +++++++++++++++++++++++++++++++++++++ Dockerfile | 18 ++++++++ Makefile | 33 +++++++++++++++ README.md | 11 ++++- 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/build.yaml create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..45167f0 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,82 @@ +name: Build + +on: + pull_request: + branches: + - '**' + push: + branches: + - master + +jobs: + build: + name: Build Docker Image + runs-on: almalinux-8 + services: + docker: + image: docker:dind + options: --privileged + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + apk add --no-cache make bash git + + - name: Build Docker image + if: github.event_name == 'pull_request' + run: | + make build + + - name: Save Docker context + if: github.event_name == 'pull_request' + run: tar -czf build-context.tar.gz . + + - name: Upload build artifacts + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v3 + with: + name: build-context + path: build-context.tar.gz + + deploy: + name: Deploy Docker Image + runs-on: almalinux-8 + needs: build + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + services: + docker: + image: docker:dind + options: --privileged + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: build-context + + - name: Extract build artifacts + run: tar -xzf build-context.tar.gz + + - name: Install dependencies + run: | + apk add --no-cache make bash git + + - name: Log in to Docker + env: + UPLOAD_USER: ${{ secrets.UPLOAD_USER }} + UPLOAD_PASS: ${{ secrets.UPLOAD_PASS }} + run: echo "${{ secrets.UPLOAD_PASS }}" | docker login --username "${{ secrets.UPLOAD_USER }}" --password-stdin git.query.consul + + - name: Push Docker image + run: | + make push diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0d637c7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Start with the AlmaLinux 8.10 base image +FROM git.query.consul/unkin/almalinux8:latest + +# Clean and update the repository cache +RUN dnf clean all && \ + dnf makecache + +# Install nodejs:20 for actions +RUN dnf module enable -y nodejs:20 && \ + dnf install -y nodejs + +# Install build-essential +RUN dnf groupinstall -y 'Development Tools' && \ + dnf install -y make cmake gcc gcc-c++ rpm rpmdevtools wget + +# Cleanup +RUN dnf clean all && \ + rm -rf /var/cache/dnf diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..63d06f6 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +# Get the current Git commit hash +GIT_COMMIT := $(shell git rev-parse --short HEAD) + +# Get the current date in YYYYMMDD format +DATE_TAG := $(shell date +%Y%m%d) + +# Set the Docker image name and repository information +IMAGE_NAME := alma8-buildagent +REGISTRY := git.query.consul +OWNER := unkin + +# Build the Docker image (without tags) +build: + docker build --network=host -t $(REGISTRY)/$(OWNER)/$(IMAGE_NAME) . + +# Tag the Docker image with the Git commit hash, the date, and 'latest' +tag: + docker tag $(REGISTRY)/$(OWNER)/$(IMAGE_NAME) $(REGISTRY)/$(OWNER)/$(IMAGE_NAME):$(GIT_COMMIT) + docker tag $(REGISTRY)/$(OWNER)/$(IMAGE_NAME) $(REGISTRY)/$(OWNER)/$(IMAGE_NAME):$(DATE_TAG) + docker tag $(REGISTRY)/$(OWNER)/$(IMAGE_NAME) $(REGISTRY)/$(OWNER)/$(IMAGE_NAME):latest + +# Push the Docker image to a repository with all tags +push: tag + docker push $(REGISTRY)/$(OWNER)/$(IMAGE_NAME):$(GIT_COMMIT) + docker push $(REGISTRY)/$(OWNER)/$(IMAGE_NAME):$(DATE_TAG) + docker push $(REGISTRY)/$(OWNER)/$(IMAGE_NAME):latest + +# Clean up dangling Docker images +clean: + docker image prune -f + +# Default target +default: build diff --git a/README.md b/README.md index 5b416e8..2bf4630 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ -# docker-almalinux-buildrunner +# Docker Image Build: almalinux buildrunner -Create almalinux docker images for buildagents \ No newline at end of file +[![Build Status](https://droneci.query.consul/api/badges/unkin/docker-almalinux-base/status.svg)](https://droneci.query.consul/unkin/docker-almalinux-base) + +This project provides a reproducible Docker image build process for `almalinux:8.10`, with custom YUM repository configurations and package installations. The build is automated using a `Makefile` and managed via CI tasks to ensure consistent and reliable Docker image builds. + +This build includes: +- build-essentials +- nodejs:20 for actions +- make, git, rpmbuild, etc