From 530af83f555b2a51a3a89d37818ca81a0ab7baf7 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sat, 20 Jul 2024 15:38:21 -0400 Subject: [PATCH] feat: set up ubuntu base image build ci: tag image as latest --- .forgejo/workflows/ci.yml | 34 ++++++++++++++++++++++++ images/ubuntu-2204/Dockerfile | 33 +++++++++++++++++++++++ images/ubuntu-2204/files/registries.conf | 3 +++ script/build-image.sh | 19 +++++++++++++ script/get-tag.sh | 12 +++++++++ 5 files changed, 101 insertions(+) create mode 100644 .forgejo/workflows/ci.yml create mode 100644 images/ubuntu-2204/Dockerfile create mode 100644 images/ubuntu-2204/files/registries.conf create mode 100755 script/build-image.sh create mode 100755 script/get-tag.sh diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..de76b43 --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,34 @@ +on: + push: + tags: + - "v*" + +env: + REGISTRY_ENDPOINT: host.containers.internal:5000 + +jobs: + build-images: + runs-on: ubuntu-latest + strategy: + matrix: + image-name: ['ubuntu-2204'] + steps: + - uses: actions/checkout@v4 + - name: Login to Registry + run: podman login -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.REGISTRY_TOKEN }} ${{ env.REGISTRY_ENDPOINT }} + - name: Set image metadata + id: image-metadata + run: | + echo "image-tag=$(./script/get-tag.sh)" >> $GITHUB_OUTPUT + echo "full-image-name=${{ matrix.image-name }}:$(./script/get-tag.sh)" >> $GITHUB_OUTPUT + - name: Build image + run: ./script/build-image.sh ${{ matrix.image-name }} ${{ steps.image-metadata.outputs.image-tag }} + - name: Tag image as latest + run: podman tag ${{ steps.image-metadata.outputs.full-image-name }} ${{ matrix.image-name }}:latest + - name: List images + run: podman image ls + - name: Push tagged image to registry + run: | + podman push ${{ steps.image-metadata.outputs.full-image-name }} ${{ REGISTRY_ENDPOINT }}/forge-runners/${{ steps.image-metadata.outputs.full-image-name }} + podman push ${{ steps.image-metadata.outputs.full-image-name }} ${{ REGISTRY_ENDPOINT }}/forge-runners/${{ matrix.image-name }}:latest + diff --git a/images/ubuntu-2204/Dockerfile b/images/ubuntu-2204/Dockerfile new file mode 100644 index 0000000..9f0dcf3 --- /dev/null +++ b/images/ubuntu-2204/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:22.04 as skeleton + +ENV NODE_VERSION="20.12.2" + +RUN apt update && \ + apt upgrade -y && \ + apt install -y \ + curl \ + podman \ + jq \ + git \ + xz-utils \ + ca-certificates \ + unzip \ + --no-install-recommends \ + --autoremove + +FROM skeleton as build + +WORKDIR tmp + +RUN curl https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz \ + --output /tmp/node-v$NODE_VERSION-linux-x64.tar.xz && \ + tar -xf /tmp/node-v$NODE_VERSION-linux-x64.tar.xz + +FROM skeleton as runner + +WORKDIR /runner + +COPY --from=build /tmp/node-v$NODE_VERSION-linux-x64/bin/* /bin/ +COPY --from=build /tmp/node-v$NODE_VERSION-linux-x64/lib/* /lib/ + +COPY ./files/registries.conf /etc/containers/registries.conf diff --git a/images/ubuntu-2204/files/registries.conf b/images/ubuntu-2204/files/registries.conf new file mode 100644 index 0000000..067d712 --- /dev/null +++ b/images/ubuntu-2204/files/registries.conf @@ -0,0 +1,3 @@ +[[registry]] +insecure = true +location = "host.containers.internal:5000" diff --git a/script/build-image.sh b/script/build-image.sh new file mode 100755 index 0000000..e8c3f72 --- /dev/null +++ b/script/build-image.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +image_name=$1 +image_tag=$2 + +if [[ -z $image_name ]]; then + echo "An image name must be provided." + exit 1 +fi + +if [[ -z $image_tag ]]; then + echo "An image tag must be provided." + exit 1 +fi + +( + cd "images/$image_name" + podman build -t "$image_name:$image_tag" -f ./Dockerfile +) || exit 1 diff --git a/script/get-tag.sh b/script/get-tag.sh new file mode 100755 index 0000000..a949293 --- /dev/null +++ b/script/get-tag.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +has_changes=$(git status --short) +head_sha=$(git rev-parse --short HEAD) + +tag=$head_sha + +if [[ -n $has_changes ]]; then + tag="$tag-dev" +fi + +echo "$tag"