From 6cf56b46fb1ae2ffd7b48f1978913c8e4dab5c62 Mon Sep 17 00:00:00 2001 From: George Adams Date: Thu, 10 Oct 2024 12:05:34 +0100 Subject: [PATCH] add test docker image to ghcr for dynamic VM testing --- .github/workflows/build_test_containers.yml | 69 +++++++++++++++++++++ ansible/docker/test/Dockerfile.Ubuntu2204 | 43 +++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 .github/workflows/build_test_containers.yml create mode 100644 ansible/docker/test/Dockerfile.Ubuntu2204 diff --git a/.github/workflows/build_test_containers.yml b/.github/workflows/build_test_containers.yml new file mode 100644 index 0000000000..8e4154f85a --- /dev/null +++ b/.github/workflows/build_test_containers.yml @@ -0,0 +1,69 @@ +name: Docker + +on: + pull_request: + paths: + - .github/workflows/build_test_containers.yml + - ansible/docker/test/Dockerfile* + branches: + - master + push: + paths: + - .github/workflows/build_test_containers.yml + - ansible/docker/test/Dockerfile* + branches: + - master + +permissions: + contents: read + packages: write + +jobs: + generate-matrix: + name: Generate Matrix + runs-on: ubuntu-latest + if: github.repository_owner == 'adoptium' + outputs: + matrix: ${{ steps.generate_matrix.outputs.matrix }} + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + fetch-depth: 0 + + # Get list of changed files in ansible/docker/test/Dockerfile* + - name: Get list of changed Dockerfiles + id: get_changed_files + run: | + changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep ansible/docker/test/Dockerfile) + echo "changed_files=$changed_files" >> "$GITHUB_OUTPUT" + + # Generate matrix + - name: Generate matrix + id: generate_matrix + run: | + matrix=$(jq -n --arg files "$changed_files" '{ + include: ($files | split("\n") | map(select(length > 0) | {dockerfile: .})) + }') + echo "matrix=$matrix" >> "$GITHUB_OUTPUT" + + build-dockerfiles: + name: Build Dockerfiles + runs-on: ubuntu-latest + needs: generate-matrix + strategy: + matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}} + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + # Generate tag name based on the Dockerfile name + - name: Set tag name + run: echo "TAG_NAME=$(basename ${{ matrix.dockerfile }} | cut -d'.' -f2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + + - name: Build Dockerfile + run: docker build -t ghcr.io/${{ github.repository_owner }}/test-containers:$TAG_NAME -f ${{ matrix.dockerfile }} . + + - name: Push Dockerfile to ghcr.io + if: github.event_name == 'push' + run: | + echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin + docker push ghcr.io/${{ github.repository_owner }}/test-containers:$TAG_NAME diff --git a/ansible/docker/test/Dockerfile.Ubuntu2204 b/ansible/docker/test/Dockerfile.Ubuntu2204 new file mode 100644 index 0000000000..24a22f64f4 --- /dev/null +++ b/ansible/docker/test/Dockerfile.Ubuntu2204 @@ -0,0 +1,43 @@ +FROM ubuntu:22.04 + +ARG ant_version="1.10.15" +ARG ant_512checksum="1de7facbc9874fa4e5a2f045d5c659f64e0b89318c1dbc8acc6aae4595c4ffaf90a7b1ffb57f958dd08d6e086d3fff07aa90e50c77342a0aa5c9b4c36bff03a9" +ARG user="jenkins" + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -qq -y \ + curl \ + fontconfig \ + gcc \ + git \ + gnupg \ + libxi6 \ + libxrender1 \ + libxtst6 \ + locales \ + make \ + openjdk-17-jdk-headless \ + openssh-client \ + perl \ + unzip \ + wget \ + xvfb \ + zip + +# Install ant +RUN wget -q -O /tmp/ant.zip "https://archive.apache.org/dist/ant/binaries/apache-ant-${ant_version}-bin.zip" +RUN wget -q -O /tmp/ant-contrib.tar.gz https://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-1.0b2/ant-contrib-1.0b2-bin.tar.gz +RUN echo "$ant_512checksum /tmp/ant.zip" > /tmp/ant.sha512 +RUN echo "0fd2771dca2b8b014a4cb3246715b32e20ad5d26754186d82eee781507a183d5e63064890b95eb27c091c93c1209528a0b18a6d7e6901899319492a7610e74ad /tmp/ant-contrib.tar.gz" >> /tmp/ant.sha512 +RUN sha512sum --check --strict /tmp/ant.sha512 +RUN ln -s /usr/local/apache-ant-${ant_version}/bin/ant /usr/bin/ant +RUN unzip -q -d /usr/local /tmp/ant.zip +RUN tar xpfz /tmp/ant-contrib.tar.gz -C /usr/local/apache-ant-${ant_version}/lib --strip-components=2 ant-contrib/lib/ant-contrib.jar + +# Clear up space +RUN rm /tmp/ant.zip /tmp/ant-contrib.tar.gz + +RUN locale-gen en_US.utf8 + +RUN groupadd -g 1000 ${user} +RUN useradd -c "Jenkins user" -d /home/${user} -u 1000 -g 1000 -m ${user}