From 911b5983aa74ce106776d136c451724c612ebd14 Mon Sep 17 00:00:00 2001 From: Pando85 Date: Sat, 25 Apr 2020 13:46:05 +0200 Subject: [PATCH] Add github actions: - Add linter with `cargo fmt` - Add tests - Add kanidmd docker build - Add kanidm_rlm_python docker build - Fix kanidm_unix_int format to pass tests --- .github/workflows/kanidmd-docker_image.yml | 75 ++++++++++++++++++++++ .github/workflows/radius-docker_image.yml | 75 ++++++++++++++++++++++ .github/workflows/rust.yml | 43 +++++++++++++ kanidm_unix_int/src/daemon.rs | 12 ++-- 4 files changed, 198 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/kanidmd-docker_image.yml create mode 100644 .github/workflows/radius-docker_image.yml create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/kanidmd-docker_image.yml b/.github/workflows/kanidmd-docker_image.yml new file mode 100644 index 000000000..c51b3af05 --- /dev/null +++ b/.github/workflows/kanidmd-docker_image.yml @@ -0,0 +1,75 @@ +name: Docker + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +env: + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/server + DOCKERFILE_DIR: kanidmd + +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + docker build . --file $DOCKERFILE_DIR/Dockerfile + fi + + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + # Ensure test job passes before pushing image. + needs: test + + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build . --file $DOCKERFILE_DIR/Dockerfile --tag image + + - name: Log into registry + run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + + - name: Push image + run: | + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_NAME | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag image $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + diff --git a/.github/workflows/radius-docker_image.yml b/.github/workflows/radius-docker_image.yml new file mode 100644 index 000000000..bbc265dba --- /dev/null +++ b/.github/workflows/radius-docker_image.yml @@ -0,0 +1,75 @@ +name: Docker + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +env: + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/radius + DOCKERFILE_DIR: kanidm_rlm_python + +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + cd $DOCKERFILE_DIR && docker build . --file Dockerfile + fi + + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + # Ensure test job passes before pushing image. + needs: test + + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: cd $DOCKERFILE_DIR && docker build . --file Dockerfile --tag image + + - name: Log into registry + run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + + - name: Push image + run: | + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_NAME | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag image $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 000000000..71e6498cc --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,43 @@ +name: Rust + +# Trigger the workflow on push or pull request +on: [push, pull_request] + +jobs: + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install rustfmt + run: rustup component add rustfmt + + - name: Run cargo fmt + run: cargo fmt --all -- --check + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install dependencies + run: | + sudo apt install -y \ + libsqlite3-dev \ + libpam0g-dev \ + libssl1.0-dev + + - name: Build + run: cargo build --verbose + + - name: Run tests + run: cargo test --verbose + diff --git a/kanidm_unix_int/src/daemon.rs b/kanidm_unix_int/src/daemon.rs index 493f44cf2..b80d3e570 100644 --- a/kanidm_unix_int/src/daemon.rs +++ b/kanidm_unix_int/src/daemon.rs @@ -241,13 +241,11 @@ async fn main() { match socket_res { Ok(socket) => { let cachelayer_ref = cachelayer.clone(); - tokio::spawn( - async move { - if let Err(e) = handle_client(socket, cachelayer_ref.clone()).await { - error!("an error occured; error = {:?}", e); - } - }, - ); + tokio::spawn(async move { + if let Err(e) = handle_client(socket, cachelayer_ref.clone()).await { + error!("an error occured; error = {:?}", e); + } + }); } Err(err) => { error!("Accept error -> {:?}", err);