From 096e919b3e4aa044254225d33528c35c0d7f3049 Mon Sep 17 00:00:00 2001 From: Gowtham Suresh Kumar Date: Wed, 31 Jan 2024 15:44:03 +0000 Subject: [PATCH] Test: Add basic ci script and test files This patch only adds rudimentary files for the CI and test setup. A comprehensive PR with detailed setup will be added later. Signed-off-by: Gowtham Suresh Kumar --- .github/actions/load_docker/action.yml | 22 ++++++++ .github/workflows/ci.yml | 51 +++++++++++++++++++ .gitignore | 5 ++ ci.sh | 9 ++++ .../parsec-openssl-provider-test.Dockerfile | 30 +++++++++++ 5 files changed, 117 insertions(+) create mode 100644 .github/actions/load_docker/action.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100755 ci.sh create mode 100644 tests/docker_image/parsec-openssl-provider-test.Dockerfile diff --git a/.github/actions/load_docker/action.yml b/.github/actions/load_docker/action.yml new file mode 100644 index 00000000..02819daf --- /dev/null +++ b/.github/actions/load_docker/action.yml @@ -0,0 +1,22 @@ +name: "Load docker image" +description: "Load docker image" +inputs: + image-name: + required: true + description: "Docker image name" + image-path: + required: true + description: "Path to save the docker image" + +runs: + using: "composite" + steps: + - uses: actions/checkout@v3 + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.image-name }} + path: ${{ inputs.image-path }} + - name: Load image + run: docker load --input ${{ inputs.image-path }}/${{ inputs.image-name }}.tar + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c457c16d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: Continuous Integration + +on: + push: + pull_request: + workflow_dispatch: + inputs: + trigger_docker: + description: "'parsec-openssl-provider-test' if docker build should be triggered" + required: false + default: "" + +env: + TEST_DOCKER_IMAGE: ${{ github.event.inputs.trigger_docker || 'ghcr.io/parallaxsecond/parsec-openssl-provider-test' }} + +jobs: + build-and-export-test-docker: + runs-on: ubuntu-latest + # For running this job we need to manually trigger the CI and set the variable + if: ${{ github.event.inputs.trigger_docker == 'parsec-openssl-provider-test' }} + steps: + - uses: actions/checkout@v3 + - name: Build the docker container + run: pushd tests/docker_image && docker build -t parsec-openssl-provider-test -f parsec-openssl-provider-test.Dockerfile . && popd + - name: Export the docker container + run: docker save parsec-openssl-provider-test > /tmp/parsec-openssl-provider-test.tar + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: parsec-openssl-provider-test + path: /tmp/parsec-openssl-provider-test.tar + + build-and-test: + name: Build Parsec OpenSSL Provider and run tests + runs-on: ubuntu-latest + if: ${{ always() }} + needs: [build-and-export-test-docker] + steps: + - uses: actions/checkout@v3 + - name: Load Docker + uses: ./.github/actions/load_docker + if: ${{ env.TEST_DOCKER_IMAGE == 'parsec-openssl-provider-test' }} + with: + image-name: "${{ env.TEST_DOCKER_IMAGE }}" + image-path: "/tmp" + - name: Run the container to execute the test script + run: + pushd parsec-openssl-provider-shared/ && + cargo build && + popd && + ./ci.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..30d8b67d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/target +Cargo.lock +.vscode +*/Cargo.lock +*/target diff --git a/ci.sh b/ci.sh new file mode 100755 index 00000000..c0c5f6e6 --- /dev/null +++ b/ci.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# Copyright 2023 Contributors to the Parsec project. +# SPDX-License-Identifier: Apache-2.0 + +set -ex + +openssl version +openssl list -providers -provider-path ./target/debug/ -provider libparsec_openssl_provider_shared diff --git a/tests/docker_image/parsec-openssl-provider-test.Dockerfile b/tests/docker_image/parsec-openssl-provider-test.Dockerfile new file mode 100644 index 00000000..3e6da33a --- /dev/null +++ b/tests/docker_image/parsec-openssl-provider-test.Dockerfile @@ -0,0 +1,30 @@ +# Copyright 2023 Contributors to the Parsec project. +# SPDX-License-Identifier: Apache-2.0 +FROM ubuntu:22.04 + +RUN apt-get update && apt-get -y upgrade +RUN apt install -y autoconf-archive libcmocka0 libcmocka-dev procps +RUN apt install -y iproute2 build-essential git pkg-config gcc libtool automake libssl-dev uthash-dev doxygen libjson-c-dev +RUN apt install -y --fix-missing wget python3 cmake clang +RUN apt install -y libini-config-dev libcurl4-openssl-dev curl libgcc1 +RUN apt install -y python3-distutils libclang-11-dev protobuf-compiler python3-pip +RUN apt install -y libgcrypt20-dev uuid-dev +RUN apt install -y libssl-dev git gcc openssl + +# Setup git config +RUN git config --global user.email "some@email.com" +RUN git config --global user.name "Parsec Team" + +WORKDIR /tmp + +# Install Rust toolchain for all users +# This way of installing allows all users to call the same binaries, but non-root +# users cannot modify the toolchains or install new ones. +# See: https://github.com/rust-lang/rustup/issues/1085 +ENV RUSTUP_HOME /opt/rust +ENV CARGO_HOME /opt/rust +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path +ENV PATH="/root/.cargo/bin:/opt/rust/bin:${PATH}" + +# For running tests Parsec is configured with the socket in /tmp/ +ENV PARSEC_SERVICE_ENDPOINT="unix:/tmp/parsec.sock"