From b9164b5f0dd7f8712fd06e346f0c24b117cbec94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 3 Nov 2022 10:05:36 +0100 Subject: [PATCH] Add gitlab ci --- .gitignore | 2 ++ .gitlab-ci.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 5 ++++- ci/Dockerfile | 18 +++++++++++++++++ ci/Makefile | 29 ++++++++++++++++++++++++++++ ci/entrypoint.sh | 12 ++++++++++++ 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 .gitlab-ci.yml create mode 100644 ci/Dockerfile create mode 100644 ci/Makefile create mode 100644 ci/entrypoint.sh diff --git a/.gitignore b/.gitignore index 96ef6c0..71af5be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target Cargo.lock +tarpaulin-report.html +cobertura.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..34915ac --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,50 @@ +# Copyright (C) 2022 Nitrokey GmbH +# SPDX-License-Identifier: CC0-1.0 + +include: 'https://raw.githubusercontent.com/Nitrokey/common-ci-jobs/master/common_jobs.yml' + +stages: + - pull-github + - build + - deploy + +variables: + GIT_STRATEGY: clone + GIT_DEPTH: 0 + GIT_SUBMODULE_STRATEGY: recursive + REPO_NAME: piv-authenticator + MAIN_BRANCH: main + COMMON_PULL: "true" + COMMON_UPLOAD_NIGHTLY: "false" + COMMON_GITHUB_RELEASE: "false" + COMMON_UPLOAD_FILES: "false" + +build: + image: registry.git.nitrokey.com/nitrokey/piv-authenticator/piv-authenticator-build:latest + rules: + - if: '$CI_PIPELINE_SHOULD_NOT_BUILD == "true"' + when: never + - if: '$CI_PIPELINE_SOURCE == "push"' + - if: '$CI_PIPELINE_SOURCE == "web"' + - if: '$CI_PIPELINE_SOURCE == "schedule"' + tags: + - docker + stage: build + before_script: + - cargo --version + script: + - make ci + after_script: + - cp /app/.cache/scdaemon.log scdaemon.log + - wget $icon_server/checkmark/$CI_COMMIT_REF_NAME/$CI_COMMIT_SHA/$CI_JOB_NAME/$CI_JOB_STATUS/${CI_JOB_URL#*/*/*/} + coverage: '/^\d+.\d+% coverage/' + artifacts: + when: always + paths: + - "scdaemon.log" + - "cobertura.xml" + - "tarpaulin-report.html" + reports: + coverage_report: + coverage_format: cobertura + path: cobertura.xml diff --git a/Makefile b/Makefile index a81e9fe..9b86f58 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,6 @@ test: check: cargo fmt --check cargo check --all-targets --all-features - cargo check --target thumbv7em-none-eabi cargo clippy --all-targets --all-features -- -Dwarnings RUSTDOCFLAGS='-Dwarnings' cargo doc --all-features @@ -25,3 +24,7 @@ tarpaulin: .PHONY: example example: cargo run --example virtual --features virtual + +.PHONY: ci +ci: check tarpaulin + diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000..036b5b6 --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,18 @@ +# Copyright (C) 2022 Nitrokey GmbH +# SPDX-License-Identifier: CC0-1.0 + +FROM docker.io/rust:latest + +RUN apt update && apt install --yes scdaemon libclang-dev llvm python3-pip vsmartcard-vpcd pkg-config nettle-dev libpcsclite-dev + +RUN rustup component add clippy rustfmt && rustup target add thumbv7em-none-eabi +RUN cargo install cargo-tarpaulin --profile release && rm -rf "$CARGO_HOME"/registry +# initialize cargo cache +RUN cargo search + +ENV CARGO_HOME=/app/.cache/cargo + +WORKDIR /app + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/ci/Makefile b/ci/Makefile new file mode 100644 index 0000000..28ae5e9 --- /dev/null +++ b/ci/Makefile @@ -0,0 +1,29 @@ +# Copyright (C) 2022 Nitrokey GmbH +# SPDX-License-Identifier: CC0-1.0 + +-include config.mk + +TAG := registry.git.nitrokey.com/nitrokey/piv-authenticator/piv-authenticator-build +DOCKER ?= docker +FUZZ_JOBS?=$(shell nproc) +FUZZ_DURATION?="0" + +.PHONY: build +build: + $(DOCKER) build . --tag $(TAG) + +.PHONY: push +push: + $(DOCKER) push $(TAG) + +.PHONY: run +run: + $(DOCKER) run --interactive --rm --volume "$(PWD)/..:/app" --env RUST_LOG $(TAG) make ci + +.PHONY: test +test: + $(DOCKER) run --interactive --rm --volume "$(PWD)/..:/app" --env RUST_LOG $(TAG) make test + +.PHONY: fuzz +fuzz: + $(DOCKER) run --interactive --rm --volume "$(PWD)/..:/app" --env RUST_LOG $(TAG) make fuzz FUZZ_JOBS=${FUZZ_JOBS} FUZZ_DURATION=${FUZZ_DURATION} diff --git a/ci/entrypoint.sh b/ci/entrypoint.sh new file mode 100644 index 0000000..4c27a27 --- /dev/null +++ b/ci/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Copyright (C) 2022 Nitrokey GmbH +# SPDX-License-Identifier: CC0-1.0 + +set -e +mkdir -p /app/.cache +if [ ! -e "$CARGO_HOME" ] +then + cp -r /usr/local/cargo $CARGO_HOME +fi +pcscd +exec "$@"