diff --git a/.github/workflows/build-debian-images.yaml b/.github/workflows/build-debian-images.yaml index 3e3feb8..412ac1c 100644 --- a/.github/workflows/build-debian-images.yaml +++ b/.github/workflows/build-debian-images.yaml @@ -2,19 +2,53 @@ name: Build Debian images for PDNS CI on: workflow_dispatch: + inputs: + pdns-repo-url: + description: HTTPS URL of the PDNS repository to clone from + type: string + default: https://github.com/PowerDNS/pdns.git + required: false + pdns-branch-name: + description: HTTPS URL of the PDNS repository to clone from + type: string + default: https://github.com/PowerDNS/pdns.git + required: false + image-tag: + description: Tag to use for the image + type: string + default: master + required: false + dockerfile: + description: Dockerfile to use to build images + type: string + default: Dockerfile + required: false push: pull_request: schedule: - cron: '0 23 * * *' +env: + DEFAULT_PDNS_REPO_URL: https://github.com/PowerDNS/pdns.git + jobs: + get-build-data: + name: generate docker runner image name + runs-on: ubuntu-22.04 + outputs: + pdns-branch-name: ${{ steps.get-branch-name.outputs.pdns-branch-name }} + env: + DEFAULT_PDNS_BRANCHES: '\"master\",\"rel/auth-4.9.x\",\"rel/dnsdist-1.9.x\"' + steps: + - id: get-branch-name + run: | + echo "pdns-branch-name=[${{ inputs.pdns-branch-name || env.DEFAULT_PDNS_BRANCHES }}]" >> "$GITHUB_OUTPUT" + build-and-push-debian-images: + needs: get-build-data strategy: matrix: - branch-name: - - master - - rel/auth-4.9.x - - rel/dnsdist-1.9.x + branch-name: ${{ fromJSON(needs.get-build-data.outputs.pdns-branch-name) }} image: - id: debian-11-pdns-base debian-image-name: python @@ -33,13 +67,15 @@ jobs: - run: | echo "image-id-lowercase=ghcr.io/${{ github.repository }}/${{ matrix.image.id }}" | tr '[:upper:]' '[:lower:]' >> "$GITHUB_ENV" echo "image-tag=$(echo ${{ matrix.branch-name }} | cut -d '/' -f 2)" >> "$GITHUB_ENV" + echo "dockerfile=$(echo Dockerfile${{ matrix.branch-name == 'master' && '-pipenv' || '' }} | cut -d '/' -f 2)" >> "$GITHUB_ENV" - name: Build image run: | - docker build . --file Dockerfile \ - --tag ${{ env.image-id-lowercase }}:${{ env.image-tag }} \ + docker build . --file ${{ inputs.dockerfile || env.dockerfile }} \ + --tag ${{ env.image-id-lowercase }}:${{ inputs.image-tag || env.image-tag }} \ --build-arg DEBIAN_IMAGE_NAME=${{ matrix.image.debian-image-name }} \ --build-arg DEBIAN_IMAGE_TAG=${{ matrix.image.debian-image-tag }} \ + --build-arg REPO_URL=${{ inputs.pdns-repo-url || env.DEFAULT_PDNS_REPO_URL }} \ --build-arg REPO_BRANCH=${{ matrix.branch-name }} - name: Login to GitHub Container Registry diff --git a/Dockerfile-pipenv b/Dockerfile-pipenv new file mode 100644 index 0000000..f3cc38e --- /dev/null +++ b/Dockerfile-pipenv @@ -0,0 +1,67 @@ +ARG DEBIAN_IMAGE_NAME +ARG DEBIAN_IMAGE_TAG +FROM ${DEBIAN_IMAGE_NAME}:${DEBIAN_IMAGE_TAG} + +ARG USER_HOME=/home/runner +ARG REPO_HOME=/home/runner/pdns +ARG REPO_BRANCH=master +ARG REPO_URL=https://github.com/PowerDNS/pdns.git +ARG DOCKER_GID=1000 + +ENV CLANG_VERSION='13' +ENV DECAF_SUPPORT=yes + +# Reusable layer for base update +RUN apt-get update && apt-get -y dist-upgrade && apt-get clean + +# Force the ID for docker group +RUN groupadd -g ${DOCKER_GID} docker + +# Install basic SW and debugging tools +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install \ + sudo git curl gnupg software-properties-common wget \ + ca-certificates apt-utils build-essential vim \ + iproute2 net-tools iputils-* ifupdown cmake acl \ + npm time mariadb-client postgresql-client jq + +# Install Docker client from the official Docker repository +RUN install -m 0755 -d /etc/apt/keyrings +RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg +RUN chmod a+r /etc/apt/keyrings/docker.gpg +RUN echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg]" \ + "https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + +RUN apt-get update +RUN apt-get install -y docker-ce-cli docker-compose-plugin + +# Run as user "runner", uid: 1001, gid: group ID for docker on the runner VM . Make this user a passwordless sudoer +RUN useradd -u 1001 -ms /bin/bash -g docker runner +RUN echo "runner ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers +USER runner + +# Clone repo an execute basic configuration. Do not delete folder +RUN mkdir -p ${USER_HOME} +WORKDIR ${USER_HOME} +RUN git clone ${REPO_URL} + +# Install required packages +WORKDIR ${REPO_HOME} +RUN git checkout origin/${REPO_BRANCH} +RUN build-scripts/gh-actions-setup-inv +RUN pipenv install -r meson/requirements.txt +RUN pipenv run inv install-clang +RUN pipenv run inv install-clang-tidy-tools +RUN pipenv run inv install-auth-build-deps +RUN pipenv run inv install-rec-build-deps +RUN pipenv run inv install-dnsdist-build-deps $([ "$(. /etc/os-release && echo $VERSION_CODENAME)" = "bullseye" ] && echo "--skipXDP=True") + +# Copy permissions for /opt and node_modules like Github runner VMs +RUN sudo mkdir -p /usr/local/lib/node_modules +RUN sudo chmod 777 /opt /usr/local/bin /usr/share /usr/local/lib/node_modules +RUN sudo chmod 777 -R /opt/pdns-auth || true + +WORKDIR ${USER_HOME} + +# Clean-up folder +RUN rm -rf pdns