From 8eac5cb82271be54cbff1bb5ba16ddf4b2b61b15 Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Thu, 21 Nov 2024 14:14:46 -0600 Subject: [PATCH 1/6] Add testflinger-testenv container --- .../build-testflinger-testenv-container.yml | 52 +++++++++++++++++++ agent/extra/testflinger-testenv/Dockerfile | 12 +++++ agent/extra/testflinger-testenv/README | 1 + 3 files changed, 65 insertions(+) create mode 100644 .github/workflows/build-testflinger-testenv-container.yml create mode 100644 agent/extra/testflinger-testenv/Dockerfile create mode 100644 agent/extra/testflinger-testenv/README diff --git a/.github/workflows/build-testflinger-testenv-container.yml b/.github/workflows/build-testflinger-testenv-container.yml new file mode 100644 index 00000000..b8ca0d5f --- /dev/null +++ b/.github/workflows/build-testflinger-testenv-container.yml @@ -0,0 +1,52 @@ +name: Build testflinger-testenv container image + +on: + push: + branches: + - main + paths: + - agent/extra/testflinger-testenv/** + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}/testflinger-testenv + +jobs: + build-testflinger-testenv: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + config-inline: | + [registry."docker.io"] + mirrors = ["https://github-runner-dockerhub-cache.canonical.com:5000"] + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push backend Docker image + uses: docker/build-push-action@v6 + with: + context: ./agent/extra/testflinger-testenv + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/agent/extra/testflinger-testenv/Dockerfile b/agent/extra/testflinger-testenv/Dockerfile new file mode 100644 index 00000000..5a6d84eb --- /dev/null +++ b/agent/extra/testflinger-testenv/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:20.04 +ENV container docker +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common expect sudo openssh-client virtualenv curl wget build-essential python3-setuptools python3-dev python3-pip python3-requests python3-psutil git +RUN pip3 install PyYaml netifaces +RUN adduser -u 1000 --disabled-password ubuntu +RUN echo "ubuntu ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu && \ + chmod 0440 /etc/sudoers.d/ubuntu +#Avoid sudo rlimit error +RUN echo "Set disable_coredump false" >> /etc/sudo.conf +USER ubuntu +WORKDIR /home/ubuntu +CMD [ "/bin/bash" ] diff --git a/agent/extra/testflinger-testenv/README b/agent/extra/testflinger-testenv/README new file mode 100644 index 00000000..3ef680e6 --- /dev/null +++ b/agent/extra/testflinger-testenv/README @@ -0,0 +1 @@ +This Dockerfile creates a basic test environment for running the test phase of testflinger agents in a Docker container. From 17a1299428fadd7668d14e038cbf88008a562cba Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Fri, 22 Nov 2024 08:49:39 -0600 Subject: [PATCH 2/6] Build different versions of the testenv container --- .github/workflows/build-testflinger-testenv-container.yml | 8 ++++++++ agent/extra/testflinger-testenv/Dockerfile | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-testflinger-testenv-container.yml b/.github/workflows/build-testflinger-testenv-container.yml index b8ca0d5f..b45bd316 100644 --- a/.github/workflows/build-testflinger-testenv-container.yml +++ b/.github/workflows/build-testflinger-testenv-container.yml @@ -19,6 +19,10 @@ jobs: contents: read packages: write + strategy: + matrix: + version: [focal, jammy, noble] + steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -42,6 +46,8 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.base_version }} - name: Build and push backend Docker image uses: docker/build-push-action@v6 @@ -50,3 +56,5 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + BASE_IMAGE=ubuntu:${{ matrix.version }} diff --git a/agent/extra/testflinger-testenv/Dockerfile b/agent/extra/testflinger-testenv/Dockerfile index 5a6d84eb..86b44d72 100644 --- a/agent/extra/testflinger-testenv/Dockerfile +++ b/agent/extra/testflinger-testenv/Dockerfile @@ -1,4 +1,5 @@ -FROM ubuntu:20.04 +ARG BASE_IMAGE=ubuntu:20.04 +FROM ${BASE_IMAGE} ENV container docker RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common expect sudo openssh-client virtualenv curl wget build-essential python3-setuptools python3-dev python3-pip python3-requests python3-psutil git RUN pip3 install PyYaml netifaces From 6cec568dd64dbc7c413577dffbdc8b4bba98d7d3 Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Fri, 22 Nov 2024 09:32:20 -0600 Subject: [PATCH 3/6] Remove pip installs from testflinger-testenv container --- agent/extra/testflinger-testenv/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/agent/extra/testflinger-testenv/Dockerfile b/agent/extra/testflinger-testenv/Dockerfile index 86b44d72..d8012fcc 100644 --- a/agent/extra/testflinger-testenv/Dockerfile +++ b/agent/extra/testflinger-testenv/Dockerfile @@ -2,7 +2,6 @@ ARG BASE_IMAGE=ubuntu:20.04 FROM ${BASE_IMAGE} ENV container docker RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common expect sudo openssh-client virtualenv curl wget build-essential python3-setuptools python3-dev python3-pip python3-requests python3-psutil git -RUN pip3 install PyYaml netifaces RUN adduser -u 1000 --disabled-password ubuntu RUN echo "ubuntu ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu && \ chmod 0440 /etc/sudoers.d/ubuntu From 07b4feb89fc2a02e60fdbf046de72ab5879610c7 Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Fri, 22 Nov 2024 09:45:20 -0600 Subject: [PATCH 4/6] Allow for noble where ubuntu user already exists in container --- agent/extra/testflinger-testenv/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/extra/testflinger-testenv/Dockerfile b/agent/extra/testflinger-testenv/Dockerfile index d8012fcc..55768d2e 100644 --- a/agent/extra/testflinger-testenv/Dockerfile +++ b/agent/extra/testflinger-testenv/Dockerfile @@ -1,8 +1,8 @@ ARG BASE_IMAGE=ubuntu:20.04 FROM ${BASE_IMAGE} -ENV container docker +ENV container=docker RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common expect sudo openssh-client virtualenv curl wget build-essential python3-setuptools python3-dev python3-pip python3-requests python3-psutil git -RUN adduser -u 1000 --disabled-password ubuntu +RUN adduser -u 1000 --disabled-password ubuntu || /bin/true RUN echo "ubuntu ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu && \ chmod 0440 /etc/sudoers.d/ubuntu #Avoid sudo rlimit error From 66afbc96de16730ce8d8336b62546f4f3549cbfe Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Fri, 22 Nov 2024 09:58:15 -0600 Subject: [PATCH 5/6] fix tags --- .github/workflows/build-testflinger-testenv-container.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-testflinger-testenv-container.yml b/.github/workflows/build-testflinger-testenv-container.yml index b45bd316..a40203c0 100644 --- a/.github/workflows/build-testflinger-testenv-container.yml +++ b/.github/workflows/build-testflinger-testenv-container.yml @@ -6,6 +6,7 @@ on: - main paths: - agent/extra/testflinger-testenv/** + - .github/workflows/build-testflinger-testenv-container.yml workflow_dispatch: env: @@ -46,8 +47,7 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.base_version }} + tags: ${{ matrix.version }} - name: Build and push backend Docker image uses: docker/build-push-action@v6 From 7c10bc267bb0528a3f95613c3e92a39bbf8faa9d Mon Sep 17 00:00:00 2001 From: Paul Larson Date: Fri, 22 Nov 2024 11:10:41 -0600 Subject: [PATCH 6/6] Add pipx python3-venv sshpass jq gettext and sort packages installed --- agent/extra/testflinger-testenv/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/extra/testflinger-testenv/Dockerfile b/agent/extra/testflinger-testenv/Dockerfile index 55768d2e..8b88151c 100644 --- a/agent/extra/testflinger-testenv/Dockerfile +++ b/agent/extra/testflinger-testenv/Dockerfile @@ -1,7 +1,7 @@ ARG BASE_IMAGE=ubuntu:20.04 FROM ${BASE_IMAGE} ENV container=docker -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common expect sudo openssh-client virtualenv curl wget build-essential python3-setuptools python3-dev python3-pip python3-requests python3-psutil git +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y expect build-essential curl jq gettext git openssh-client pipx python3-dev python3-pip python3-psutil python3-requests python3-setuptools python3-venv software-properties-common sudo sshpass virtualenv wget RUN adduser -u 1000 --disabled-password ubuntu || /bin/true RUN echo "ubuntu ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu && \ chmod 0440 /etc/sudoers.d/ubuntu