diff --git a/ansible/data/molecule/requirements.txt b/ansible/data/molecule/requirements.txt index b6889eab6..7f521b90a 100644 --- a/ansible/data/molecule/requirements.txt +++ b/ansible/data/molecule/requirements.txt @@ -1,5 +1,5 @@ -ansible==4.2.0 -ansible-core==2.11.11 +ansible==5.2.0 +ansible-core==2.12.8 ansible-compat==2.0.2 ansible-lint==5.4.0 asn1crypto==1.5.1 diff --git a/ansible/playbooks/molecule_ec2_server_and_nuc/molecule/server_and_nuc_desktop_icons_docker_ec2/molecule.yml b/ansible/playbooks/molecule_ec2_server_and_nuc/molecule/server_and_nuc_desktop_icons_docker_ec2/molecule.yml index 223cd1fe1..3d6d65596 100644 --- a/ansible/playbooks/molecule_ec2_server_and_nuc/molecule/server_and_nuc_desktop_icons_docker_ec2/molecule.yml +++ b/ansible/playbooks/molecule_ec2_server_and_nuc/molecule/server_and_nuc_desktop_icons_docker_ec2/molecule.yml @@ -26,7 +26,7 @@ lint: | platforms: # Adding CODEBUILD_BUILD_ID to instance name in order to allow parallel EC2 execution of tests from CodeBuild - name: server_and_nuc_desktop_icons_docker_ec2_${CODEBUILD_BUILD_ID} - image: ami-0820357ff5cf2333d + image: ami-00826bd51e68b1487 instance_type: t2.micro region: eu-west-2 vpc_id: vpc-0f8cc2cc245d57eb4 diff --git a/ansible/playbooks/molecule_ec2_simulation/molecule/teleop_server_desktop_icons_simulation_haptx_ec2/molecule.yml b/ansible/playbooks/molecule_ec2_simulation/molecule/teleop_server_desktop_icons_simulation_haptx_ec2/molecule.yml index 03a881afd..f391e7b53 100644 --- a/ansible/playbooks/molecule_ec2_simulation/molecule/teleop_server_desktop_icons_simulation_haptx_ec2/molecule.yml +++ b/ansible/playbooks/molecule_ec2_simulation/molecule/teleop_server_desktop_icons_simulation_haptx_ec2/molecule.yml @@ -26,7 +26,7 @@ lint: | platforms: # Adding CODEBUILD_BUILD_ID to instance name in order to allow parallel EC2 execution of tests from CodeBuild - name: teleop_server_desktop_icons_simulation_haptx_ec2_${CODEBUILD_BUILD_ID} - image: ami-0820357ff5cf2333d + image: ami-00826bd51e68b1487 instance_type: t2.micro region: eu-west-2 vpc_id: vpc-0f8cc2cc245d57eb4 diff --git a/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_check_desktop_icons_docker_ec2/molecule.yml b/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_check_desktop_icons_docker_ec2/molecule.yml index 8918dcdbb..1f5683002 100644 --- a/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_check_desktop_icons_docker_ec2/molecule.yml +++ b/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_check_desktop_icons_docker_ec2/molecule.yml @@ -26,7 +26,7 @@ lint: | platforms: # Adding CODEBUILD_BUILD_ID to instance name in order to allow parallel EC2 execution of tests from CodeBuild - name: teleop_server_check_desktop_icons_docker_ec2_${CODEBUILD_BUILD_ID} - image: ami-0820357ff5cf2333d + image: ami-00826bd51e68b1487 instance_type: t2.micro region: eu-west-2 vpc_id: vpc-0f8cc2cc245d57eb4 diff --git a/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_desktop_icons_haptx_bimanual_ec2/molecule.yml b/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_desktop_icons_haptx_bimanual_ec2/molecule.yml index a5ebebfd8..71abc1479 100644 --- a/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_desktop_icons_haptx_bimanual_ec2/molecule.yml +++ b/ansible/playbooks/molecule_ec2_teleop/molecule/teleop_server_desktop_icons_haptx_bimanual_ec2/molecule.yml @@ -26,7 +26,7 @@ lint: | platforms: # Adding CODEBUILD_BUILD_ID to instance name in order to allow parallel EC2 execution of tests from CodeBuild - name: teleop_server_desktop_icons_haptx_bimanual_ec2_${CODEBUILD_BUILD_ID} - image: ami-0820357ff5cf2333d + image: ami-00826bd51e68b1487 instance_type: t2.micro region: eu-west-2 vpc_id: vpc-0f8cc2cc245d57eb4 diff --git a/docker/molecule/base/jammy/Dockerfile b/docker/molecule/base/jammy/Dockerfile new file mode 100644 index 000000000..9205312a5 --- /dev/null +++ b/docker/molecule/base/jammy/Dockerfile @@ -0,0 +1,58 @@ +FROM public.ecr.aws/shadowrobot/ubuntu:jammy + +MAINTAINER "Shadow Robot's Software Team " + +LABEL Description="Ubuntu Jammy image contains Ansible and Molecule" Vendor="Shadow Robot" Version="1.0" + +ENV DEBIAN_FRONTEND noninteractive + +ENV LC_ALL C.UTF-8 + +ENV LANG C.UTF-8 + +ARG ml_base_aurora_branch + +ENV ml_base_aurora_branch ${ml_base_aurora_branch:-"master"} + +RUN set -x && \ + apt-get update && \ + \ + echo "Installing wget" && \ + apt-get install -y --no-install-recommends ca-certificates wget && \ + \ + echo "Installing dependencies for python3.8, SSL, pip3" && \ + apt-get install -y build-essential zlib1g-dev libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev && \ + \ + echo "Installing git, sudo and Python 3 pip and dev" && \ + apt-get install -y \ + python3-dev \ + python3-pip \ + git \ + libyaml-dev \ + python3-cryptography \ + libssl-dev \ + libffi-dev \ + sshpass \ + sudo && \ + pip3 install --upgrade pip gcovr && \ + echo "Cloning Aurora" && \ + git clone --depth 1 https://github.com/shadow-robot/aurora.git -b $ml_base_aurora_branch /tmp/aurora && \ + \ + pip3 --version && \ + python3 --version && \ + echo "Installing molecule" && \ + echo "cython<3" > /tmp/constraint.txt && \ + PIP_CONSTRAINT=/tmp/constraint.txt pip3 install -r /tmp/aurora/ansible/data/molecule/requirements.txt && \ + \ + echo "Clean up" && \ + apt-get clean && \ + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /root/.ansible \ + /root/.gitconfig \ + /root/.cache + +VOLUME /var/lib/docker + diff --git a/docker/molecule/base/jammy/README.md b/docker/molecule/base/jammy/README.md new file mode 100644 index 000000000..16625bc39 --- /dev/null +++ b/docker/molecule/base/jammy/README.md @@ -0,0 +1 @@ +Please read [these instructions](../../../../docs/molecule_dockers.md). diff --git a/docker/molecule/base/jammy/buildspec.yml b/docker/molecule/base/jammy/buildspec.yml new file mode 100644 index 000000000..50cc64e88 --- /dev/null +++ b/docker/molecule/base/jammy/buildspec.yml @@ -0,0 +1,43 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: 0.2 +env: + shell: bash + variables: + branch: master + image: aurora-molecule + tag: jammy + dockerfile_folder: docker/molecule/base/jammy/ + exported-variables: + - branch + - image + - tag + - dockerfile_folder +phases: + build: + commands: + - cd .. + - rm -rf aurora + - git clone https://github.com/shadow-robot/aurora.git + - cd aurora + - git checkout $branch + - cd $dockerfile_folder + - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/shadowrobot + - docker build -t $image . + - docker tag $image:latest public.ecr.aws/shadowrobot/$image:$tag + - docker push public.ecr.aws/shadowrobot/$image:$tag + - comm -13 <(aws ecr-public describe-image-tags --repository-name $image --region us-east-1 --output text | awk '{print $3}' | tr " " "\n" | sort -u) <(aws ecr-public describe-images --repository-name $image --region us-east-1 --output text | awk '{print $2}' | tr " " "\n" | sort -u) >> ids_to_delete.txt + - ids_to_delete=$(sed 's/^/imageDigest=/' ids_to_delete.txt) + - if [[ -s ids_to_delete.txt ]]; then aws ecr-public batch-delete-image --repository-name $image --region us-east-1 --image-ids $ids_to_delete --output text; fi diff --git a/docker/molecule/base/jammy/docker-compose.test.yml b/docker/molecule/base/jammy/docker-compose.test.yml new file mode 100644 index 000000000..0549b4f38 --- /dev/null +++ b/docker/molecule/base/jammy/docker-compose.test.yml @@ -0,0 +1,28 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: '3' + +services: + sut: + build: + context: . + args: + ml_base_aurora_branch: ${SOURCE_BRANCH} + command: > + bash -c "pip3 freeze | grep molecule && + pip3 freeze | grep ansible && + pip3 freeze | grep docker" + environment: + - SOURCE_BRANCH diff --git a/docker/molecule/base/jammy/hooks/build b/docker/molecule/base/jammy/hooks/build new file mode 100755 index 000000000..37955d557 --- /dev/null +++ b/docker/molecule/base/jammy/hooks/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +export DOCKERFILE_PATH=${DOCKERFILE_PATH:-Dockerfile} + +echo "Executing build command" +echo "docker build --build-arg ml_base_aurora_branch=${SOURCE_BRANCH} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} ." + +docker build --build-arg ml_base_aurora_branch="${SOURCE_BRANCH}" -f "${DOCKERFILE_PATH}" -t "${IMAGE_NAME}" . diff --git a/docker/molecule/devel/jammy/Dockerfile b/docker/molecule/devel/jammy/Dockerfile new file mode 100644 index 000000000..341b3eccd --- /dev/null +++ b/docker/molecule/devel/jammy/Dockerfile @@ -0,0 +1,37 @@ +FROM public.ecr.aws/shadowrobot/aurora-molecule-docker:jammy + +LABEL Description="Ubuntu Jammy image contains Ansible, Molecule, Docker and EC2 driver and Development tools with GUI" Vendor="Shadow Robot" Version="1.0" + +ENV DEBIAN_FRONTEND noninteractive + +ENV PULSE_SERVER /run/pulse/native + +ARG ml_devel_aurora_branch + +ENV ml_devel_aurora_branch ${ml_devel_aurora_branch:-"master"} + +ENV ml_devel_aurora_script "https://raw.githubusercontent.com/shadow-robot/aurora/$ml_devel_aurora_branch/bin/run-ansible.sh" + +RUN set -x && \ + \ + echo "Downloading one-liner" && \ + wget -O /tmp/oneliner "$( echo "$ml_devel_aurora_script" | sed 's/#/%23/g' )" && \ + chmod 755 /tmp/oneliner && \ + \ + echo "Setting up UI and new Docker user" && \ + /tmp/oneliner configure_software --branch $ml_devel_aurora_branch software=[setup-docker] && \ + \ + echo "Add user to docker group" && \ + usermod -aG docker user && \ + \ + echo "Installing IDEs and AWS CLI" && \ + /tmp/oneliner install_software --branch $ml_devel_aurora_branch software=[pycharm,vscode,aws-cli] && \ + \ + echo "Clean up" && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.ansible /root/.gitconfig /root/.cache + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +VOLUME /var/lib/docker +CMD ["/usr/bin/terminator"] + diff --git a/docker/molecule/devel/jammy/README.md b/docker/molecule/devel/jammy/README.md new file mode 100644 index 000000000..c850c197e --- /dev/null +++ b/docker/molecule/devel/jammy/README.md @@ -0,0 +1,9 @@ +## Launching container with UI + +In order to launch development image please use the following command + +```bash +docker run -it --name sample_dev -e DISPLAY -e QT_X11_NO_MITSHM=1 -e LOCAL_USER_ID=$(id -u) \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /tmp/.X11-unix:/tmp/.X11-unix:rw public.ecr.aws/shadowrobot/aurora-molecule-devel:jammy +``` diff --git a/docker/molecule/devel/jammy/buildspec.yml b/docker/molecule/devel/jammy/buildspec.yml new file mode 100644 index 000000000..fd7c5b353 --- /dev/null +++ b/docker/molecule/devel/jammy/buildspec.yml @@ -0,0 +1,44 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: 0.2 + +env: + shell: bash + variables: + branch: master + image: aurora-molecule-devel + tag: jammy + dockerfile_folder: docker/molecule/devel/jammy/ + exported-variables: + - branch + - image + - tag + - dockerfile_folder +phases: + build: + commands: + - cd .. + - rm -rf aurora + - git clone https://github.com/shadow-robot/aurora.git + - cd aurora + - git checkout $branch + - cd $dockerfile_folder + - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/shadowrobot + - docker build -t $image . + - docker tag $image:latest public.ecr.aws/shadowrobot/$image:$tag + - docker push public.ecr.aws/shadowrobot/$image:$tag + - comm -13 <(aws ecr-public describe-image-tags --repository-name $image --region us-east-1 --output text | awk '{print $3}' | tr " " "\n" | sort -u) <(aws ecr-public describe-images --repository-name $image --region us-east-1 --output text | awk '{print $2}' | tr " " "\n" | sort -u) >> ids_to_delete.txt + - ids_to_delete=$(sed 's/^/imageDigest=/' ids_to_delete.txt) + - if [[ -s ids_to_delete.txt ]]; then aws ecr-public batch-delete-image --repository-name $image --region us-east-1 --image-ids $ids_to_delete --output text; fi diff --git a/docker/molecule/devel/jammy/docker-compose.test.yml b/docker/molecule/devel/jammy/docker-compose.test.yml new file mode 100644 index 000000000..078ef8a03 --- /dev/null +++ b/docker/molecule/devel/jammy/docker-compose.test.yml @@ -0,0 +1,28 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: '3' + +services: + sut: + build: + context: . + args: + ml_devel_aurora_branch: ${SOURCE_BRANCH} + command: > + bash -c "aws --version && + test -f /usr/bin/pycharm && + test -f /usr/bin/code" + environment: + - SOURCE_BRANCH diff --git a/docker/molecule/devel/jammy/hooks/build b/docker/molecule/devel/jammy/hooks/build new file mode 100755 index 000000000..378505089 --- /dev/null +++ b/docker/molecule/devel/jammy/hooks/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +export DOCKERFILE_PATH=${DOCKERFILE_PATH:-Dockerfile} + +echo "Executing build command" +echo "docker build --build-arg ml_devel_aurora_branch=${SOURCE_BRANCH} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} ." + +docker build --build-arg ml_devel_aurora_branch="${SOURCE_BRANCH}" -f "${DOCKERFILE_PATH}" -t "${IMAGE_NAME}" . diff --git a/docker/molecule/docker/jammy/Dockerfile b/docker/molecule/docker/jammy/Dockerfile new file mode 100644 index 000000000..ace6300d7 --- /dev/null +++ b/docker/molecule/docker/jammy/Dockerfile @@ -0,0 +1,28 @@ +FROM public.ecr.aws/shadowrobot/aurora-molecule:jammy + +LABEL Description="Ubuntu Jammy image contains Ansible, Molecule and Docker driver" Vendor="Shadow Robot" Version="1.0" + +ARG ml_docker_aurora_branch + +ENV ml_docker_aurora_branch ${ml_docker_aurora_branch:-"master"} + +ENV ml_docker_aurora_script "https://raw.githubusercontent.com/shadow-robot/aurora/$ml_docker_aurora_branch/bin/run-ansible.sh" + +RUN set -x && \ + \ + echo "Installing Docker" && \ + wget -O /tmp/oneliner "$( echo "$ml_docker_aurora_script" | sed 's/#/%23/g' )" && \ + chmod 755 /tmp/oneliner && \ + /tmp/oneliner install_software --branch $ml_docker_aurora_branch software=[docker] skip_molecule_task=true && \ + \ + echo "Clean up" && \ + apt-get clean && \ + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /root/.ansible \ + /root/.gitconfig \ + /root/.cache + +VOLUME /var/lib/docker diff --git a/docker/molecule/docker/jammy/README.md b/docker/molecule/docker/jammy/README.md new file mode 100644 index 000000000..16625bc39 --- /dev/null +++ b/docker/molecule/docker/jammy/README.md @@ -0,0 +1 @@ +Please read [these instructions](../../../../docs/molecule_dockers.md). diff --git a/docker/molecule/docker/jammy/buildspec.yml b/docker/molecule/docker/jammy/buildspec.yml new file mode 100644 index 000000000..f89d8d6eb --- /dev/null +++ b/docker/molecule/docker/jammy/buildspec.yml @@ -0,0 +1,55 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: 0.2 + +env: + shell: bash + variables: + image: aurora-molecule-docker + tag: jammy + dockerfile_folder: docker/molecule/docker/jammy/ + exported-variables: + - image + - tag + - dockerfile_folder +phases: + build: + commands: + - | + if [[ $CODEBUILD_SOURCE_VERSION == "pr/"* ]]; then + pr_number=${CODEBUILD_SOURCE_VERSION#pr/} + api_response=$(curl -s "https://api.github.com/repos/shadow-robot/aurora/pulls/$pr_number") + if [[ $(echo $api_response | jq -r '.head.ref') == 'null' ]]; then + echo "$api_response" | jq + fi + branch=$(echo $api_response | jq -r '.head.ref') + elif [[ $CODEBUILD_SOURCE_VERSION =~ ^[0-9a-f]{40}$ ]]; then + branch=$(git ls-remote --symref origin | grep -m1 $CODEBUILD_SOURCE_VERSION | awk -F '/' '{print $NF}') + else + branch=$CODEBUILD_SOURCE_VERSION + fi + - cd .. + - rm -rf aurora + - git clone https://github.com/shadow-robot/aurora.git + - cd aurora + - git checkout $branch + - cd $dockerfile_folder + - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/shadowrobot + - docker build --build-arg ml_docker_aurora_branch=$branch -t $image . + - docker tag $image:latest public.ecr.aws/shadowrobot/$image:$tag + - docker push public.ecr.aws/shadowrobot/$image:$tag + - comm -13 <(aws ecr-public describe-image-tags --repository-name $image --region us-east-1 --output text | awk '{print $3}' | tr " " "\n" | sort -u) <(aws ecr-public describe-images --repository-name $image --region us-east-1 --output text | awk '{print $2}' | tr " " "\n" | sort -u) >> ids_to_delete.txt + - ids_to_delete=$(sed 's/^/imageDigest=/' ids_to_delete.txt) + - if [[ -s ids_to_delete.txt ]]; then aws ecr-public batch-delete-image --repository-name $image --region us-east-1 --image-ids $ids_to_delete --output text; fi diff --git a/docker/molecule/docker/jammy/docker-compose.test.yml b/docker/molecule/docker/jammy/docker-compose.test.yml new file mode 100644 index 000000000..0319df1e7 --- /dev/null +++ b/docker/molecule/docker/jammy/docker-compose.test.yml @@ -0,0 +1,25 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: '3' + +services: + sut: + build: + context: . + args: + ml_docker_aurora_branch: ${SOURCE_BRANCH} + command: docker --version + environment: + - SOURCE_BRANCH diff --git a/docker/molecule/docker/jammy/hooks/build b/docker/molecule/docker/jammy/hooks/build new file mode 100755 index 000000000..a56600c93 --- /dev/null +++ b/docker/molecule/docker/jammy/hooks/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +export DOCKERFILE_PATH=${DOCKERFILE_PATH:-Dockerfile} + +echo "Executing build command" +echo "docker build --build-arg ml_docker_aurora_branch=${SOURCE_BRANCH} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} ." + +docker build --build-arg ml_docker_aurora_branch="${SOURCE_BRANCH}" -f "${DOCKERFILE_PATH}" -t "${IMAGE_NAME}" . diff --git a/docker/molecule/ec2/jammy/Dockerfile b/docker/molecule/ec2/jammy/Dockerfile new file mode 100644 index 000000000..fad4c2294 --- /dev/null +++ b/docker/molecule/ec2/jammy/Dockerfile @@ -0,0 +1,32 @@ +FROM public.ecr.aws/shadowrobot/aurora-molecule:jammy + +LABEL Description="Ubuntu Jammy image contains Ansible, Molecule and EC2 driver" Vendor="Shadow Robot" Version="1.0" + +ARG ml_ec2_aurora_branch + +ENV ml_ec2_aurora_branch ${ml_ec2_aurora_branch:-"master"} + +ENV ml_ec2_aurora_script "https://raw.githubusercontent.com/shadow-robot/aurora/$ml_ec2_aurora_branch/bin/run-ansible.sh" + +RUN set -x && \ + \ + echo "Installing AWS CLI" && \ + wget -O /tmp/oneliner "$( echo "$ml_ec2_aurora_script" | sed 's/#/%23/g' )" && \ + chmod 755 /tmp/oneliner && \ + /tmp/oneliner install_software --branch $ml_ec2_aurora_branch software=[aws-cli] && \ + \ + wget https://s3.eu-west-2.amazonaws.com/amazon-ssm-eu-west-2/latest/debian_amd64/amazon-ssm-agent.deb && \ + dpkg -i amazon-ssm-agent.deb && \ + \ + echo "Clean up" && \ + apt-get clean && \ + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /root/.ansible \ + /root/.gitconfig \ + /root/.cache + +VOLUME /var/lib/docker + diff --git a/docker/molecule/ec2/jammy/README.md b/docker/molecule/ec2/jammy/README.md new file mode 100644 index 000000000..16625bc39 --- /dev/null +++ b/docker/molecule/ec2/jammy/README.md @@ -0,0 +1 @@ +Please read [these instructions](../../../../docs/molecule_dockers.md). diff --git a/docker/molecule/ec2/jammy/buildspec.yml b/docker/molecule/ec2/jammy/buildspec.yml new file mode 100644 index 000000000..c73d6c819 --- /dev/null +++ b/docker/molecule/ec2/jammy/buildspec.yml @@ -0,0 +1,44 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: 0.2 + +env: + shell: bash + variables: + branch: master + image: aurora-molecule-ec2 + tag: jammy + dockerfile_folder: docker/molecule/ec2/jammy/ + exported-variables: + - branch + - image + - tag + - dockerfile_folder +phases: + build: + commands: + - cd .. + - rm -rf aurora + - git clone https://github.com/shadow-robot/aurora.git + - cd aurora + - git checkout $branch + - cd $dockerfile_folder + - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/shadowrobot + - docker build -t $image . + - docker tag $image:latest public.ecr.aws/shadowrobot/$image:$tag + - docker push public.ecr.aws/shadowrobot/$image:$tag + - comm -13 <(aws ecr-public describe-image-tags --repository-name $image --region us-east-1 --output text | awk '{print $3}' | tr " " "\n" | sort -u) <(aws ecr-public describe-images --repository-name $image --region us-east-1 --output text | awk '{print $2}' | tr " " "\n" | sort -u) >> ids_to_delete.txt + - ids_to_delete=$(sed 's/^/imageDigest=/' ids_to_delete.txt) + - if [[ -s ids_to_delete.txt ]]; then aws ecr-public batch-delete-image --repository-name $image --region us-east-1 --image-ids $ids_to_delete --output text; fi diff --git a/docker/molecule/ec2/jammy/docker-compose.test.yml b/docker/molecule/ec2/jammy/docker-compose.test.yml new file mode 100644 index 000000000..822c16dd4 --- /dev/null +++ b/docker/molecule/ec2/jammy/docker-compose.test.yml @@ -0,0 +1,25 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: '3' + +services: + sut: + build: + context: . + args: + ml_ec2_aurora_branch: ${SOURCE_BRANCH} + command: aws --version + environment: + - SOURCE_BRANCH diff --git a/docker/molecule/ec2/jammy/hooks/build b/docker/molecule/ec2/jammy/hooks/build new file mode 100755 index 000000000..97a434bf4 --- /dev/null +++ b/docker/molecule/ec2/jammy/hooks/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +export DOCKERFILE_PATH=${DOCKERFILE_PATH:-Dockerfile} + +echo "Executing build command" +echo "docker build --build-arg ml_ec2_aurora_branch=${SOURCE_BRANCH} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} ." + +docker build --build-arg ml_ec2_aurora_branch="${SOURCE_BRANCH}" -f "${DOCKERFILE_PATH}" -t "${IMAGE_NAME}" . diff --git a/docker/test/docker/jammy/Dockerfile b/docker/test/docker/jammy/Dockerfile new file mode 100644 index 000000000..a2a0cdfc1 --- /dev/null +++ b/docker/test/docker/jammy/Dockerfile @@ -0,0 +1,38 @@ +FROM public.ecr.aws/shadowrobot/aurora-test-ubuntu:jammy + +LABEL Description="This image is used for testing Ubuntu Jammy with Docker deployment" Vendor="Shadow Robot" Version="1.0" + +ARG DEBIAN_FRONTEND=noninteractive + +ENV LC_ALL C.UTF-8 + +ENV LANG C.UTF-8 + +ENV USER testuser + +ARG ts_docker_aurora_branch + +ENV ts_docker_aurora_branch ${ts_docker_aurora_branch:-"master"} + +ENV ts_docker_aurora_script "https://raw.githubusercontent.com/shadow-robot/aurora/$ts_docker_aurora_branch/bin/run-ansible.sh" + +RUN set -x && \ + sudo apt-get update && \ + \ + echo "Installing wget" && \ + sudo apt-get install -y --no-install-recommends ca-certificates wget && \ + \ + echo "Installing Docker" && \ + wget -O /tmp/oneliner "$( echo "$ts_docker_aurora_script" | sed 's/#/%23/g' )" && \ + chmod 755 /tmp/oneliner && \ + /tmp/oneliner install_software --branch $ts_docker_aurora_branch software=[docker] skip_molecule_task=true && \ + \ + echo "Clean up" && \ + sudo apt-get clean && \ + sudo rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /root/.ansible \ + /root/.gitconfig \ + /root/.cache diff --git a/docker/test/docker/jammy/buildspec.yml b/docker/test/docker/jammy/buildspec.yml new file mode 100644 index 000000000..3bebbd033 --- /dev/null +++ b/docker/test/docker/jammy/buildspec.yml @@ -0,0 +1,55 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: 0.2 + +env: + shell: bash + variables: + image: aurora-test-ubuntu-docker + tag: jammy + dockerfile_folder: docker/test/docker/jammy/ + exported-variables: + - image + - tag + - dockerfile_folder +phases: + build: + commands: + - | + if [[ $CODEBUILD_SOURCE_VERSION == "pr/"* ]]; then + pr_number=${CODEBUILD_SOURCE_VERSION#pr/} + api_response=$(curl -s "https://api.github.com/repos/shadow-robot/aurora/pulls/$pr_number") + if [[ $(echo $api_response | jq -r '.head.ref') == 'null' ]]; then + echo "$api_response" | jq + fi + branch=$(echo $api_response | jq -r '.head.ref') + elif [[ $CODEBUILD_SOURCE_VERSION =~ ^[0-9a-f]{40}$ ]]; then + branch=$(git ls-remote --symref origin | grep -m1 $CODEBUILD_SOURCE_VERSION | awk -F '/' '{print $NF}') + else + branch=$CODEBUILD_SOURCE_VERSION + fi + - cd .. + - rm -rf aurora + - git clone https://github.com/shadow-robot/aurora.git + - cd aurora + - git checkout $branch + - cd $dockerfile_folder + - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/shadowrobot + - docker build --build-arg ts_docker_aurora_branch=$branch -t $image . + - docker tag $image:latest public.ecr.aws/shadowrobot/$image:$tag + - docker push public.ecr.aws/shadowrobot/$image:$tag + - comm -13 <(aws ecr-public describe-image-tags --repository-name $image --region us-east-1 --output text | awk '{print $3}' | tr " " "\n" | sort -u) <(aws ecr-public describe-images --repository-name $image --region us-east-1 --output text | awk '{print $2}' | tr " " "\n" | sort -u) >> ids_to_delete.txt + - ids_to_delete=$(sed 's/^/imageDigest=/' ids_to_delete.txt) + - if [[ -s ids_to_delete.txt ]]; then aws ecr-public batch-delete-image --repository-name $image --region us-east-1 --image-ids $ids_to_delete --output text; fi diff --git a/docker/test/docker/jammy/docker-compose.test.yml b/docker/test/docker/jammy/docker-compose.test.yml new file mode 100644 index 000000000..67d3d4590 --- /dev/null +++ b/docker/test/docker/jammy/docker-compose.test.yml @@ -0,0 +1,25 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: '3' + +services: + sut: + build: + context: . + args: + ts_docker_aurora_branch: ${SOURCE_BRANCH} + command: docker --version + environment: + - SOURCE_BRANCH diff --git a/docker/test/docker/jammy/hooks/build b/docker/test/docker/jammy/hooks/build new file mode 100755 index 000000000..a132d3e08 --- /dev/null +++ b/docker/test/docker/jammy/hooks/build @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +export DOCKERFILE_PATH=${DOCKERFILE_PATH:-Dockerfile} + +echo "Executing build command" +echo "docker build --build-arg ts_docker_aurora_branch=${SOURCE_BRANCH} -f ${DOCKERFILE_PATH} -t ${IMAGE_NAME} ." + +docker build --build-arg ts_docker_aurora_branch="${SOURCE_BRANCH}" -f "${DOCKERFILE_PATH}" -t "${IMAGE_NAME}" . diff --git a/docker/test/ubuntu/jammy/Dockerfile b/docker/test/ubuntu/jammy/Dockerfile new file mode 100644 index 000000000..c76caa3e2 --- /dev/null +++ b/docker/test/ubuntu/jammy/Dockerfile @@ -0,0 +1,31 @@ +FROM public.ecr.aws/shadowrobot/ubuntu:jammy + +LABEL Description="This image is used for testing empty Ubuntu Jammy deployment" Vendor="Shadow Robot" Version="1.0" + +ENV DEBIAN_FRONTEND noninteractive + +ENV USER testuser + +RUN set -x && \ + apt-get update && \ + \ + echo "Installing sudo" && \ + apt-get install -y sudo && \ + \ + echo "Create testuser with empty password" && \ + useradd -m $USER && \ + passwd -d $USER && \ + adduser $USER sudo && \ + echo "$USER ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers && \ + \ + echo "Clean up" && \ + apt-get clean && \ + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* \ + /root/.ansible \ + /root/.gitconfig \ + /root/.cache + +USER $USER diff --git a/docker/test/ubuntu/jammy/buildspec.yml b/docker/test/ubuntu/jammy/buildspec.yml new file mode 100644 index 000000000..6d450e7f4 --- /dev/null +++ b/docker/test/ubuntu/jammy/buildspec.yml @@ -0,0 +1,55 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: 0.2 + +env: + shell: bash + variables: + branch: master + image: aurora-test-ubuntu + tag: jammy + dockerfile_folder: docker/test/ubuntu/jammy/ + exported-variables: + - branch + - image + - tag + - dockerfile_folder +phases: + build: + commands: + - cd .. + - rm -rf aurora + - git clone https://github.com/shadow-robot/aurora.git + - cd aurora + - git checkout $branch + - cd $dockerfile_folder + - aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/shadowrobot + - docker build -t $image . + - docker tag $image:latest public.ecr.aws/shadowrobot/$image:$tag + - docker push public.ecr.aws/shadowrobot/$image:$tag + - comm -13 <(aws ecr-public describe-image-tags --repository-name $image --region us-east-1 --output text | awk '{print $3}' | tr " " "\n" | sort -u) <(aws ecr-public describe-images --repository-name $image --region us-east-1 --output text | awk '{print $2}' | tr " " "\n" | sort -u) >> ids_to_delete.txt + - ids_to_delete=$(sed 's/^/imageDigest=/' ids_to_delete.txt) + - aws ecr-public describe-image-tags --repository-name $image --region us-east-1 --output text | awk '{print $3}' | tr " " "\n" | sort -u >> t1.txt + - aws ecr-public describe-images --repository-name $image --region us-east-1 --output text | awk '{print $2}' | tr " " "\n" | sort -u >> t2.txt + - echo 't1' + - cat t1.txt + - echo 't2' + - cat t2.txt + - echo 'ids1' + - echo $ids_to_delete + - echo 'ids2txt' + - echo 'img' + - echo $image + - if [[ -s ids_to_delete.txt ]]; then aws ecr-public batch-delete-image --repository-name $image --region us-east-1 --image-ids $ids_to_delete --output text; fi diff --git a/docker/test/ubuntu/jammy/docker-compose.test.yml b/docker/test/ubuntu/jammy/docker-compose.test.yml new file mode 100644 index 000000000..8b0c1ed52 --- /dev/null +++ b/docker/test/ubuntu/jammy/docker-compose.test.yml @@ -0,0 +1,20 @@ +# Copyright 2024 Shadow Robot Company Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +version: '3' + +services: + sut: + build: . + command: id -u testuser